AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::ObjectMapper Concept Reference

Mapper of a format on which anch::Mapping registers the fields of T. More...

#include <mapping.hpp>

Concept definition

template<typename M, typename T>
concept ObjectMapper = std::is_class_v<T>
&& requires(M& mapper, const std::string& name, int T::* member, std::function<int(const T&)> getter,
std::function<void(T&, const int&)> setter) {
{ mapper.registerField(name, member) } -> std::same_as<M&>;
{ mapper.registerField(name, getter) } -> std::same_as<M&>;
{ mapper.registerField(name, setter) } -> std::same_as<M&>;
{ mapper.registerField(name, getter, setter) } -> std::same_as<M&>;
}
Mapper of a format on which anch::Mapping registers the fields of T.
Definition mapping.hpp:88

Detailed Description

Mapper of a format on which anch::Mapping registers the fields of T.

A mapper registers fields with their name and:

  • a member pointer: registerField(name, &T::member, constraints...) ;
  • a getter: registerField(name, std::function<P(const T&)>, constraints...) (written only) ;
  • a setter: registerField(name, std::function<void(T&, const P&)>, constraints...) (read only) ;
  • a getter and a setter.

Each function returns the mapper (fluent registration). Descriptions only use these forms, common to formats: a format deduces how it maps a field from its type (anch-json maps fields of std::optional , pointers, collections and maps with the mapper of their value type). Constraints are anch-val ones ; a format which does not support one of them refuses it at compile time.

Template Parameters
Mthe mapper type
Tthe object type
Since
0.3