47 #ifndef _MIRA_HUMANREADABLEENUM_H_ 48 #define _MIRA_HUMANREADABLEENUM_H_ 50 #include <boost/preprocessor/tuple/to_seq.hpp> 51 #include <boost/preprocessor/seq/for_each.hpp> 54 #include <boost/bimap.hpp> 55 #include <boost/assign.hpp> 86 #define MIRA_HUMANREADABLE_ENUM_VALUE_EXPAND(VALUE) #VALUE 88 #define MIRA_HUMANREADABLE_ENUM_MAP_ITEM(R, NAME, VALUE) \ 89 (NAME::VALUE, MIRA_HUMANREADABLE_ENUM_VALUE_EXPAND(VALUE)) 91 #define MIRA_HUMANREADABLE_ENUM_DECLARE(NAME, VALUES...) \ 92 enum class NAME { VALUES }; \ 93 std::string toString(const NAME& v); \ 94 NAME to##NAME(const std::string& v); 96 #define MIRA_HUMANREADABLE_ENUM_DEFINE(NAME, VALUES...) \ 97 const boost::bimap<NAME, std::string> NAME##Map \ 98 = boost::assign::list_of<boost::bimap<NAME, std::string>::relation> \ 99 BOOST_PP_SEQ_FOR_EACH( \ 100 MIRA_HUMANREADABLE_ENUM_MAP_ITEM, \ 102 BOOST_PP_TUPLE_TO_SEQ(MIRA_VARIADIC_SIZE(VALUES), (VALUES))); \ 103 std::string toString(const NAME& v) { \ 104 auto it = NAME##Map.left.find(v); \ 105 if ( it == NAME##Map.left.end() ) \ 106 MIRA_THROW(mira::XInvalidParameter, mira::toString(int(v)) + \ 107 " is not a valid value for enumeration "#NAME) \ 110 NAME to##NAME(const std::string& v) { \ 111 auto it = NAME##Map.right.find(v); \ 112 if ( it == NAME##Map.right.end() ) \ 113 MIRA_THROW(mira::XInvalidParameter, v + \ 114 " is not a valid value for enumeration "#NAME) \ Tools for handling variadic macros.
Contains toString and fromString functions for converting data types to strings and the other way rou...