|
25 | 25 | #include "../to_view.hpp" |
26 | 26 | #include "AreReaderAndWriter.hpp" |
27 | 27 | #include "Parent.hpp" |
| 28 | +#include "ParserSharedPtr.hpp" |
| 29 | +#include "Parser_box.hpp" |
| 30 | +#include "Parser_optional.hpp" |
| 31 | +#include "Parser_ref.hpp" |
| 32 | +#include "Parser_reference_wrapper.hpp" |
| 33 | +#include "Parser_unique_ptr.hpp" |
28 | 34 | #include "Parser_base.hpp" |
29 | 35 | #include "call_destructors_where_necessary.hpp" |
30 | 36 | #include "is_tagged_union_wrapper.hpp" |
@@ -52,7 +58,33 @@ struct Parser { |
52 | 58 | * @return A Result containing the parsed value or an error. |
53 | 59 | */ |
54 | 60 | static Result<T> read(const R& _r, const InputVarType& _var) noexcept { |
55 | | - if constexpr (internal::has_read_reflector<T>) { |
| 61 | + if constexpr (is_shared_ptr_v<T>) { |
| 62 | + return ParserSharedPtr<R, W, typename T::element_type, |
| 63 | + ProcessorsType>::read(_r, _var); |
| 64 | + |
| 65 | + } else if constexpr (is_unique_ptr_v<T>) { |
| 66 | + return ParserUniquePtr<R, W, typename T::element_type, |
| 67 | + ProcessorsType>::read(_r, _var); |
| 68 | + |
| 69 | + } else if constexpr (is_optional_v<T>) { |
| 70 | + return ParserOptional<R, W, typename std::remove_cvref_t<T>::value_type, |
| 71 | + ProcessorsType>::read(_r, _var); |
| 72 | + |
| 73 | + } else if constexpr (is_box_v<T>) { |
| 74 | + using IsBox = is_box<std::remove_cvref_t<T>>; |
| 75 | + return ParserBox<R, W, typename IsBox::element_type, IsBox::copyability, |
| 76 | + ProcessorsType>::read(_r, _var); |
| 77 | + |
| 78 | + } else if constexpr (is_ref_v<T>) { |
| 79 | + using IsRef = is_ref<std::remove_cvref_t<T>>; |
| 80 | + return ParserRef<R, W, typename IsRef::element_type, |
| 81 | + ProcessorsType>::read(_r, _var); |
| 82 | + |
| 83 | + } else if constexpr (is_reference_wrapper_v<T>) { |
| 84 | + return ParserReferenceWrapper<R, W, typename std::remove_cvref_t<T>::type, |
| 85 | + ProcessorsType>::read(_r, _var); |
| 86 | + |
| 87 | + } else if constexpr (internal::has_read_reflector<T>) { |
56 | 88 | const auto wrap_in_t = [](auto&& _named_tuple) -> Result<T> { |
57 | 89 | try { |
58 | 90 | using NT = decltype(_named_tuple); |
@@ -106,7 +138,33 @@ struct Parser { |
106 | 138 | */ |
107 | 139 | template <class P> |
108 | 140 | static void write(const W& _w, const T& _var, const P& _parent) { |
109 | | - if constexpr (internal::has_write_reflector<T>) { |
| 141 | + if constexpr (is_shared_ptr_v<T>) { |
| 142 | + ParserSharedPtr<R, W, typename T::element_type, ProcessorsType>::write( |
| 143 | + _w, _var, _parent); |
| 144 | + |
| 145 | + } else if constexpr (is_unique_ptr_v<T>) { |
| 146 | + ParserUniquePtr<R, W, typename T::element_type, ProcessorsType>::write( |
| 147 | + _w, _var, _parent); |
| 148 | + |
| 149 | + } else if constexpr (is_optional_v<T>) { |
| 150 | + ParserOptional<R, W, typename std::remove_cvref_t<T>::value_type, |
| 151 | + ProcessorsType>::write(_w, _var, _parent); |
| 152 | + |
| 153 | + } else if constexpr (is_box_v<T>) { |
| 154 | + using IsBox = is_box<std::remove_cvref_t<T>>; |
| 155 | + ParserBox<R, W, typename IsBox::element_type, IsBox::copyability, |
| 156 | + ProcessorsType>::write(_w, _var, _parent); |
| 157 | + |
| 158 | + } else if constexpr (is_ref_v<T>) { |
| 159 | + using IsRef = is_ref<std::remove_cvref_t<T>>; |
| 160 | + ParserRef<R, W, typename IsRef::element_type, ProcessorsType>::write( |
| 161 | + _w, _var, _parent); |
| 162 | + |
| 163 | + } else if constexpr (is_reference_wrapper_v<T>) { |
| 164 | + ParserReferenceWrapper<R, W, typename std::remove_cvref_t<T>::type, |
| 165 | + ProcessorsType>::write(_w, _var, _parent); |
| 166 | + |
| 167 | + } else if constexpr (internal::has_write_reflector<T>) { |
110 | 168 | Parser<R, W, typename Reflector<T>::ReflType, ProcessorsType>::write( |
111 | 169 | _w, Reflector<T>::from(_var), _parent); |
112 | 170 |
|
@@ -144,7 +202,33 @@ struct Parser { |
144 | 202 | using U = std::remove_cvref_t<T>; |
145 | 203 | using Type = schema::Type; |
146 | 204 |
|
147 | | - if constexpr (rfl::internal::is_description_v<U>) { |
| 205 | + if constexpr (is_shared_ptr_v<U>) { |
| 206 | + return ParserSharedPtr<R, W, typename U::element_type, |
| 207 | + ProcessorsType>::to_schema(_definitions); |
| 208 | + |
| 209 | + } else if constexpr (is_unique_ptr_v<U>) { |
| 210 | + return ParserUniquePtr<R, W, typename U::element_type, |
| 211 | + ProcessorsType>::to_schema(_definitions); |
| 212 | + |
| 213 | + } else if constexpr (is_optional_v<U>) { |
| 214 | + return ParserOptional<R, W, typename U::value_type, |
| 215 | + ProcessorsType>::to_schema(_definitions); |
| 216 | + |
| 217 | + } else if constexpr (is_box_v<U>) { |
| 218 | + using IsBox = is_box<U>; |
| 219 | + return ParserBox<R, W, typename IsBox::element_type, IsBox::copyability, |
| 220 | + ProcessorsType>::to_schema(_definitions); |
| 221 | + |
| 222 | + } else if constexpr (is_ref_v<U>) { |
| 223 | + using IsRef = is_ref<U>; |
| 224 | + return ParserRef<R, W, typename IsRef::element_type, |
| 225 | + ProcessorsType>::to_schema(_definitions); |
| 226 | + |
| 227 | + } else if constexpr (is_reference_wrapper_v<U>) { |
| 228 | + return ParserReferenceWrapper<R, W, typename U::type, |
| 229 | + ProcessorsType>::to_schema(_definitions); |
| 230 | + |
| 231 | + } else if constexpr (rfl::internal::is_description_v<U>) { |
148 | 232 | return make_description<U>(_definitions); |
149 | 233 |
|
150 | 234 | } else if constexpr (rfl::internal::is_deprecated_v<U>) { |
|
0 commit comments