31#include "json/constraints.hpp"
33#include "json/genericMapper.hpp"
34#include "json/mappingOptions.hpp"
49namespace anch::json::detail {
62 using V = std::remove_cvref_t<P>;
64 return valueTypeOf<anch::val::detail::Unwrap<V>>();
65 }
else if constexpr (anch::val::MapLike<V>) {
66 return std::type_identity<std::remove_cvref_t<typename V::mapped_type>>{};
67 }
else if constexpr (anch::val::Collection<V>) {
68 return std::type_identity<std::remove_cvref_t<std::ranges::range_value_t<V>>>{};
70 return std::type_identity<V>{};
81 using MapperType =
typename decltype(anch::json::detail::valueTypeOf<P>())::type;
122 static constexpr std::size_t NOT_REQUIRED = std::numeric_limits<std::size_t>::max();
130 std::size_t required = NOT_REQUIRED;
133 bool rejectNull =
false;
149 std::vector<FieldWriter> _writers;
161 [[gnu::always_inline]]
bool operator()(
const std::string& a,
const std::string& b)
const noexcept {
162 int res = std::char_traits<char>::compare(a.data(), b.data(), std::min(a.size(), b.size()));
163 return res < 0 || (res == 0 && a.size() < b.size());
168 std::map<std::string, FieldReader, FieldLess> _readers;
171 std::vector<std::string> _required;
259 template<
typename G,
typename W,
typename... C>
260 void addWriter(
const std::string& key, G get, W write,
const C&... constraints);
285 template<
typename R,
typename P,
typename... C>
302 template<
typename MT,
typename P,
typename... C>
303 ObjectMapper<T>& registerMapped(
const std::string& key, P T::* value, C&&... constraints);
320 template<
typename P,
typename... C>
336 template<
typename P,
typename... C>
352 template<
typename P,
typename... C>
369 template<
typename P,
typename... C>
371 ObjectMapper<T>&
registerField(
const std::string& key, std::function<P(
const T&)> getter, std::function<
void(T&,
const P&)> setter, C&&... constraints);
380#include "json/impl/mapper.hpp"
JSON mapper factory.
Definition factory.hpp:54
Generic mapper.
Definition genericMapper.hpp:49
JSON complex object mapper.
Definition mapper.hpp:116
ObjectMapper< T > & registerField(const std::string &key, std::function< void(T &, const P &)> setter, C &&... constraints)
ObjectMapper< T > & registerField(const std::string &key, std::function< P(const T &)> getter, std::function< void(T &, const P &)> setter, C &&... constraints)
ObjectMapper< T > & registerField(const std::string &key, std::function< P(const T &)> getter, const C &... constraints)
ObjectMapper< T > & registerField(const std::string &key, P T::*value, C &&... constraints)
ObjectMapper(ObjectMapper &&other)=delete
void serializeValue(const T &value, anch::json::WriterContext &context) const
bool deserializeValue(T &value, anch::json::ReaderContext &context) const
ObjectMapper(const ObjectMapper &other)=delete
JSON reader context.
Definition readerContext.hpp:44
JSON writer context.
Definition writerContext.hpp:45
Mapper of a format on which anch::Mapping registers the fields of T.
Definition mapping.hpp:88
Definition constraints.hpp:1164
JSON namespace.
Definition constants.hpp:27
std::function< bool(T &, anch::json::ReaderContext &)> DeserializeFn
Definition mapper.hpp:93
std::function< void(const T &, std::ostream &, const anch::json::MappingOptions &)> SerializeFn
Definition mapper.hpp:89
constexpr bool isNullable()
Definition constraints.hpp:1205
JSON mapping options.
Definition mappingOptions.hpp:38