Template Struct value_serializer< T >

Struct Documentation

template<typename T>
struct value_serializer<T>

value_serializer for enum values

This class is used to (de-)serialize enum values. To map enum values to a string you should use the singleton instance accessible through instance() and then call the operator() members assinging each of the enum values with their respective string.

A recent addition is the init() call to initialize the instance

Public Types

using value_map_type = std::map<T, std::string>
using value_map_value_type = typename value_map_type::value_type

Public Functions

inline value_serializer &operator()(T v, std::string_view name)
inline value_serializer &operator()(std::string name, T v)

Public Members

std::string m_type_name
value_map_type m_value_map

Public Static Functions

static inline void init(std::string_view name, std::initializer_list<value_map_value_type> values)

Initialize a new instance of value_serializer for this enum, with name and a set of name/value pairs.

static inline void init(std::initializer_list<value_map_value_type> values)

Initialize a new anonymous instance of value_serializer for this enum with a set of name/value pairs.

static inline value_serializer &instance(std::string name = {})
static inline std::string type_name()
static inline std::string to_string(T value)
static inline T from_string(std::string_view value)
static inline bool empty()