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

Mapper which validates the fields of a described type ( anch::Mapping ). More...

#include <validation.hpp>

Collaboration diagram for anch::val::ValidationMapper< T >:

Public Member Functions

 ValidationMapper ()
void validate (const T &value, anch::val::ValidationContext &context) const
template<typename P, typename... C>
ValidationMapper< T > & registerField (const std::string &name, P T::*member, C &&... constraints)
template<typename P, typename... C>
ValidationMapper< T > & registerField (const std::string &name, std::function< P(const T &)> getter, C &&... constraints)
template<typename P, typename... C>
ValidationMapper< T > & registerField (const std::string &name, std::function< void(T &, const P &)> setter, C &&... constraints)
template<typename P, typename... C>
ValidationMapper< 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 ValidationMapper< T > & instance ()

Detailed Description

template<typename T>
class anch::val::ValidationMapper< T >

Mapper which validates the fields of a described type ( anch::Mapping ).

It satisfies the anch::ObjectMapper concept: the description registers its fields and their constraints. Fields with a value (member pointer or getter) are validated: their value constraints and their nested values (described objects, std::optional and pointers values, collections items, maps values). Fields registered with a setter only are not checked, and anch::val::required is not checked (an object always has its fields).

Template Parameters
Tthe described type
Author
Vincent Lachenal
Since
0.3

Constructor & Destructor Documentation

◆ ValidationMapper()

template<typename T>
anch::val::ValidationMapper< T >::ValidationMapper ( )

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

Member Function Documentation

◆ instance()

template<typename T>
const ValidationMapper< T > & anch::val::ValidationMapper< T >::instance ( )
static

Get the mapper of T (built on first use)

Returns
the mapper
Here is the call graph for this function:

◆ registerField() [1/4]

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

Register field with its member

Parameters
namethe field 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>
ValidationMapper< T > & anch::val::ValidationMapper< T >::registerField ( const std::string & name,
std::function< P(const T &)> getter,
C &&... constraints )

Register field with its getter

Parameters
namethe field 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>
ValidationMapper< T > & anch::val::ValidationMapper< 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: the getter value is validated

Parameters
namethe field 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>
ValidationMapper< T > & anch::val::ValidationMapper< T >::registerField ( const std::string & name,
std::function< void(T &, const P &)> setter,
C &&... constraints )

Register field with its setter: it is not validated (no value)

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

◆ validate()

template<typename T>
void anch::val::ValidationMapper< T >::validate ( const T & value,
anch::val::ValidationContext & context ) const

Validate object fields

Parameters
valuethe object
contextthe validation context

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