JSON Voorhees
Killer JSON for C++
jsonv::enum_adapter< TEnum, FEnumComp, FValueComp > Class Template Reference

An adapter for enumeration types. More...

#include <jsonv/serialization_util.hpp>

+ Inheritance diagram for jsonv::enum_adapter< TEnum, FEnumComp, FValueComp >:

Public Member Functions

template<typename TForwardIterator >
 enum_adapter (std::string enum_name, TForwardIterator first, TForwardIterator last)
 Create an adapter with mapping values from the range [first, last). More...
 
 enum_adapter (std::string enum_name, std::initializer_list< std::pair< TEnum, value >> mapping)
 
- Public Member Functions inherited from jsonv::adapter_for< TEnum >
virtual const std::type_info & get_type () const override
 Get the run-time type this extractor knows how to extract. More...
 
virtual void extract (const extraction_context &context, const value &from, void *into) const override
 Extract a the type from a value into a region of memory. More...
 
virtual value to_json (const serialization_context &context, const void *from) const override
 Create a value from the value in the given region of memory. More...
 

Protected Member Functions

virtual TEnum create (const extraction_context &context, const value &from) const override
 
virtual value to_json (const serialization_context &, const TEnum &from) const override
 

Detailed Description

template<typename TEnum, typename FEnumComp = std::less<TEnum>, typename FValueComp = std::less<value>>
class jsonv::enum_adapter< TEnum, FEnumComp, FValueComp >

An adapter for enumeration types.

The most common use of this is to map enum values in C++ to string values in a JSON representation (and vice versa).

Template Parameters
TEnumThe type to map. This is not restricted to C++ enumerations (types defined with the enum keyword), but any type you wish to restrict to a subset of values.
FEnumCompbool (*)(TEnum, TEnum) – a strict ordering for TEnum values.
FValueCompbool (*)(value, value) – a strict ordering for value objects. By default, this is a case-sensitive comparison, but this can be replaced with anything you desire (for example, use value_less_icase to ignore case in extracting from JSON).
See also
enum_adapter_icase

Definition at line 437 of file serialization_util.hpp.

Constructor & Destructor Documentation

template<typename TEnum , typename FEnumComp = std::less<TEnum>, typename FValueComp = std::less<value>>
template<typename TForwardIterator >
jsonv::enum_adapter< TEnum, FEnumComp, FValueComp >::enum_adapter ( std::string  enum_name,
TForwardIterator  first,
TForwardIterator  last 
)
inlineexplicit

Create an adapter with mapping values from the range [first, last).

Template Parameters
TForwardIteratorAn iterator yielding the type std::pair<jsonv::value, TEnum>>

Definition at line 446 of file serialization_util.hpp.


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