#ifndef RFL_PARSING_PARSER_SHARED_PTR_HPP_ #define RFL_PARSING_PARSER_SHARED_PTR_HPP_ #include #include #include "../Result.hpp" #include "../always_false.hpp" #include "Parser_base.hpp" namespace rfl { namespace parsing { 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 { if (_r.is_empty(*_var)) { return std::shared_ptr(); } const auto to_ptr = [](auto&& _t) { return std::make_shared(std::move(_t)); }; return Parser>::read(_r, _var).transform( to_ptr); } /// Expresses the variable a a JSON. static OutputVarType write(const W& _w, const std::shared_ptr& _s) noexcept { if (!_s) { return _w.empty_var(); } return Parser>::write(_w, *_s); } }; } // namespace parsing } // namespace rfl #endif