#ifndef RFL_PARSING_PARSER_SHARED_PTR_HPP_ #define RFL_PARSING_PARSER_SHARED_PTR_HPP_ #include #include #include #include "../Ref.hpp" #include "../Result.hpp" #include "../always_false.hpp" #include "Parent.hpp" #include "Parser_base.hpp" #include "schema/Type.hpp" namespace rfl::parsing { template requires AreReaderAndWriter> struct Parser, ProcessorsType> { using InputVarType = typename R::InputVarType; using OutputVarType = typename W::OutputVarType; using ParentType = Parent; 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, ProcessorsType>::read(_r, _var) .transform(to_ptr); } template static void write(const W& _w, const std::shared_ptr& _s, const P& _parent) noexcept { if (!_s) { ParentType::add_null(_w, _parent); return; } Parser, ProcessorsType>::write(_w, *_s, _parent); } static schema::Type to_schema( std::map* _definitions) { using U = std::remove_cvref_t; return schema::Type {schema::Type::Optional {Ref::make( Parser::to_schema(_definitions))}}; } }; } // namespace rfl::parsing #endif