AnCH Framework 0.2
Another C++ Hack: C++23 utility libraries
Loading...
Searching...
No Matches
anch::csv::ObjectMapper< T > Class Template Reference

CSV mapper of a described type ( anch::Mapping , anch-utils): fields are columns. More...

#include <mapper.hpp>

Collaboration diagram for anch::csv::ObjectMapper< T >:

Classes

struct  Field
 Field mapping. More...

Public Member Functions

 ObjectMapper ()
const std::vector< Field > & fields () const noexcept
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & registerField (const std::string &name, P T::*member, C &&... constraints)
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & registerField (const std::string &name, std::function< P(const T &)> getter, C &&... constraints)
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & registerField (const std::string &name, std::function< void(T &, const P &)> setter, C &&... constraints)
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & registerField (const std::string &name, std::function< P(const T &)> getter, std::function< void(T &, const P &)> setter, C &&... constraints)

Static Public Member Functions

static const ObjectMapper< T > & instance ()

Detailed Description

template<typename T>
class anch::csv::ObjectMapper< T >

CSV mapper of a described type ( anch::Mapping , anch-utils): fields are columns.

It satisfies the anch::ObjectMapper concept. Fields are scalars or optionalscalars ; fields registered with a member or a getter are written, fields registered with a member or a setter are read. Constraints are anch-val ones: anch::val::required makes the column required, value constraints are checked according to Options::readCheckConstraints and Options::writeCheckConstraints .

Template Parameters
Tthe described type
Author
Vincent Lachenal
Since
0.3

Constructor & Destructor Documentation

◆ ObjectMapper()

template<typename T>
anch::csv::ObjectMapper< T >::ObjectMapper ( )

ObjectMapper constructor: fields are registered by anch::Mapping<T>

Member Function Documentation

◆ fields()

template<typename T>
const std::vector< Field > & anch::csv::ObjectMapper< T >::fields ( ) const
noexcept

Fields getter

Returns
the fields, in registration order

◆ instance()

template<typename T>
const ObjectMapper< T > & anch::csv::ObjectMapper< T >::instance ( )
static

Get the mapper of T (built on first use)

Returns
the mapper

◆ registerField() [1/4]

template<typename T>
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & anch::csv::ObjectMapper< T >::registerField ( const std::string & name,
P T::* member,
C &&... constraints )

Register field with its member (read and written)

Parameters
namethe column name
memberthe member
constraintsthe constraints
Returns
this
Here is the call graph for this function:

◆ registerField() [2/4]

template<typename T>
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & anch::csv::ObjectMapper< T >::registerField ( const std::string & name,
std::function< P(const T &)> getter,
C &&... constraints )

Register field with its getter (written only)

Parameters
namethe column name
getterthe getter
constraintsthe constraints
Returns
this
Here is the call graph for this function:

◆ registerField() [3/4]

template<typename T>
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & anch::csv::ObjectMapper< T >::registerField ( const std::string & name,
std::function< P(const T &)> getter,
std::function< void(T &, const P &)> setter,
C &&... constraints )

Register field with its getter and its setter

Parameters
namethe column name
getterthe getter
setterthe setter
constraintsthe constraints
Returns
this
Here is the call graph for this function:

◆ registerField() [4/4]

template<typename T>
template<typename P, typename... C>
requires (anch::val::FieldConstraint<C, P> && ...)
ObjectMapper< T > & anch::csv::ObjectMapper< T >::registerField ( const std::string & name,
std::function< void(T &, const P &)> setter,
C &&... constraints )

Register field with its setter (read only)

Parameters
namethe column name
setterthe setter
constraintsthe constraints
Returns
this
Here is the call graph for this function:

The documentation for this class was generated from the following file: