diff --git a/include/rfl/Literal.hpp b/include/rfl/Literal.hpp index 9661f3f5..fc173a5b 100644 --- a/include/rfl/Literal.hpp +++ b/include/rfl/Literal.hpp @@ -33,12 +33,16 @@ class Literal { /// can assume. static constexpr ValueType num_fields_ = sizeof...(fields_); + using ReflectionType = std::string; + /// Constructs a Literal from another literal. Literal(const Literal& _other) = default; /// Constructs a Literal from another literal. Literal(Literal&& _other) noexcept = default; + Literal(const std::string& _str) : value_(find_value(_str).value()) {} + /// A single-field literal is special because it /// can also have a default constructor. template > { // ---------------------------------------------------------------------------- -template -requires AreReaderAndWriter> -struct Parser> { - using InputVarType = typename R::InputVarType; - using OutputVarType = typename W::OutputVarType; - - /// Expresses the variables as type T. - static Result> read(const R& _r, - const InputVarType& _var) noexcept { - const auto to_type = [](const auto& _str) { - return Literal<_fields...>::from_string(_str); - }; - - const auto embellish_error = [](const Error& _e) { - return Error(std::string("Failed to parse Literal: ") + _e.what()); - }; - - return _r.template to_basic_type(_var) - .and_then(to_type) - .or_else(embellish_error); - } - - /// Expresses the variable a a JSON. - static OutputVarType write(const W& _w, - const Literal<_fields...>& _literal) noexcept { - return _w.from_basic_type(_literal.name()); - } -}; - -// ---------------------------------------------------------------------------- - /// Used for maps for which the key type is std::string. These are /// represented as objects. template