37 template<
typename ENUM>
40 ss <<
"Options are:\n";
43 for(
auto sit = it->second.begin(); sit != it->second.end(); sit++) {
44 if(sit != it->second.begin()) {
69 template<
typename ENUM>
73 serr << s.str() <<
"\n";
75 throw std::invalid_argument(std::string(
"ERROR: ") + s.str());
82 template<
typename ENUM>
91 template<
typename ENUM>
94 for(
auto sit = it->second.begin(); sit != it->second.end(); sit++) {
101 invalid_enum_string<ENUM>(val, std::cerr);
105 #define ENUM_TRAITS(ENUM) \
107 struct traits<ENUM> { \
109 static const std::string name; \
111 static const std::multimap<ENUM, std::vector<std::string> > strval; \
115 #define ENUM_IO(ENUM) \
116 inline std::ostream &operator<<(std::ostream &sout, const ENUM& val) { \
117 sout << to_string<ENUM>(val); \
121 inline std::istream &operator>>(std::istream &sin, ENUM& val) { \
124 val = from_string<ENUM>(s); \
128 inline jsonParser &to_json(const ENUM &val, jsonParser &json) { \
129 return to_json(to_string<ENUM>(val), json); \
132 inline void from_json(ENUM& val, const jsonParser& json) { \
133 val = from_string<ENUM>(json.get<std::string>()); \
std::string help()
Print help message describing recognized strings for allowed enum values.
ENUM from_string(const std::string &val)
Return enum class object from string representation.
std::string to_string(ENUM val)
Return string representation of enum class.
void invalid_enum_string(std::string val, std::ostream &serr)
Throw invalid_argument error for unrecognized strings.