16#include "adapter_for.hpp"
35template <
typename TEnum,
36 typename FEnumComp = std::less<TEnum>,
37 typename FValueComp = std::less<value>
46 template <
typename TForwardIterator>
52 _val_to_cpp.insert({
iter->second,
iter->first });
53 _cpp_to_val.insert(*
iter);
84 virtual TEnum create(
const extraction_context& context,
const value& from)
const override
88 auto iter = _val_to_cpp.find(from);
89 if (iter != end(_val_to_cpp))
92 throw extraction_error(context.path(),
93 std::string(
"Invalid value for ") + _enum_name +
": " + to_string(from)
97 virtual value to_json(
const serialization_context&,
const TEnum& from)
const override
101 auto iter = _cpp_to_val.find(from);
102 if (iter != end(_cpp_to_val))
109 std::string _enum_name;
110 std::map<value, TEnum, FValueComp> _val_to_cpp;
111 std::map<TEnum, value, FEnumComp> _cpp_to_val;
117template <
typename TEnum,
typename FEnumComp = std::less<TEnum>>
An adapter for the type T.
An adapter for enumeration types.
enum_adapter(std::string enum_name, TForwardIterator first, TForwardIterator last)
Create an adapter with mapping values from the range [first, last).
Copyright (c) 2014-2020 by Travis Gockel.
A collection of function objects a la <functional>.
JSONV_PUBLIC const value null
An instance with kind::null.
Conversion between C++ types and JSON values.