AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
anch::json::ObjectMapper< T > Class Template Reference

JSON complex object mapper. More...

#include <mapper.hpp>

Inheritance diagram for anch::json::ObjectMapper< T >:
Collaboration diagram for anch::json::ObjectMapper< T >:

Public Member Functions

 ObjectMapper (const ObjectMapper &other)=delete
 ObjectMapper (ObjectMapper &&other)=delete
const anch::json::GenericMapper< ObjectMapper< T >, T > & generic () const
bool serialize (const T &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const T *const value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const std::optional< T > &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const std::vector< T > &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const std::list< T > &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const std::set< T > &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool serialize (const std::map< std::string, T > &value, std::ostream &out, const anch::json::MappingOptions &options, const std::optional< std::string > &field=EMPTY_FIELD)
bool deserialize (T &value, anch::json::ReaderContext &context) const
Public Member Functions inherited from anch::json::GenericMapper< ObjectMapper< T >, T >
bool deserialize (std::optional< T > &value, anch::json::ReaderContext &context) const

Friends

template<typename U>
void anch::json::registerObject (ObjectMapper< U > &)

Additional Inherited Members

Protected Member Functions inherited from anch::json::GenericMapper< ObjectMapper< T >, T >
 GenericMapper ()
virtual ~GenericMapper ()

Detailed Description

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

JSON complex object mapper.

This is a generic template header implementation.
Type has to be a class or a structure. The fields have to be registered through the registerObject function implementation for the specific type.

Template Parameters
Tthe object type
Author
Vincent Lachenal
Since
0.1

Constructor & Destructor Documentation

◆ ObjectMapper() [1/2]

template<typename T>
anch::json::ObjectMapper< T >::ObjectMapper ( const ObjectMapper< T > & other)
delete

Forbids ObjectMapper copy constructor

◆ ObjectMapper() [2/2]

template<typename T>
anch::json::ObjectMapper< T >::ObjectMapper ( ObjectMapper< T > && other)
delete

Forbids ObjectMapper move constructor

Member Function Documentation

◆ deserialize()

template<typename T>
bool anch::json::ObjectMapper< T >::deserialize ( T & value,
anch::json::ReaderContext & context ) const

Deserialize JSON

Parameters
valuethe value to write in
contextthe mapper context
Returns
false when null found, true otherwise

◆ generic()

template<typename T>
const anch::json::GenericMapper< ObjectMapper< T >, T > & anch::json::ObjectMapper< T >::generic ( ) const

Get generic mapper implementation

Returns
*this

◆ serialize() [1/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const std::list< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize array (as std::list ) attribute

Parameters
valuethe array attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true

◆ serialize() [2/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const std::map< std::string, T > & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize array (as std::map ) attribute

Parameters
valuethe array attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true

◆ serialize() [3/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const std::optional< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize optional attribute

Parameters
valuethe optional attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true if attribute is not empty, false otherwise

◆ serialize() [4/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const std::set< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize array (as std::set ) attribute

Parameters
valuethe array attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true

◆ serialize() [5/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const std::vector< T > & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize array (as std::vector ) attribute

Parameters
valuethe array attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true

◆ serialize() [6/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const T & value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize reference attribute

Parameters
valuethe reference attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true

◆ serialize() [7/7]

template<typename T>
bool anch::json::ObjectMapper< T >::serialize ( const T *const value,
std::ostream & out,
const anch::json::MappingOptions & options,
const std::optional< std::string > & field = EMPTY_FIELD )

Serialize pointer attribute

Parameters
valuethe pointer attribute to serialize
outthe output stream to write the attribute
optionsthe options to use
fieldthe attribute's field name
Returns
true if attribute is not NULL, false otherwise

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