1 #ifndef CASM_support_enum_io_traits
2 #define CASM_support_enum_io_traits
30 template <
typename ENUM>
46 template <
typename ENUM>
49 ss <<
"Options are:\n";
53 for (
auto sit = it->second.begin(); sit != it->second.end(); sit++) {
54 if (sit != it->second.begin()) {
82 template <
typename StringContainer>
84 std::string _default =
"") {
86 ss <<
"Options are: {";
87 for (
auto it = options.begin(); it != options.end(); ++it) {
88 if (it != options.begin()) {
91 ss <<
"'" << *it <<
"'";
92 if (*it == _default) {
114 template <
typename ENUM>
116 std::string other =
"") {
117 std::vector<std::string> options;
118 if (!other.empty()) {
119 options.push_back(std::string(
"<") + other +
">");
138 template <
typename ENUM>
140 return standard_singleline_enum_help<ENUM>(
157 template <
typename ENUM>
161 << singleline_help<ENUM>();
164 throw std::invalid_argument(std::string(
"ERROR: ") +
s.str());
171 template <
typename ENUM>
183 template <
typename ENUM>
184 std::set<ENUM>
matches(
const std::string &val) {
188 for (
auto sit = it->second.begin(); sit != it->second.end(); sit++) {
189 if (sit->substr(0, val.size()) == val) {
190 res.insert(it->first);
201 template <
typename ENUM>
203 std::set<ENUM> _matches = matches<ENUM>(val);
205 if (_matches.size() == 1) {
206 return *_matches.begin();
209 invalid_enum_string<ENUM>(val);
213 #define ENUM_TRAITS(ENUM) \
215 struct traits<ENUM> { \
216 static const std::string name; \
218 static const std::multimap<ENUM, std::vector<std::string> > strval; \
221 inline std::string singleline_help<ENUM>() { \
222 return singleline_enum_help<ENUM>(); \
225 inline std::string multiline_help<ENUM>() { \
226 return multiline_enum_help<ENUM>(); \
std::set< std::string > & s
std::string singleline_enum_help()
Print short help message describing recognized strings for allowed enum values.
void invalid_enum_string(std::string val)
Throw invalid_argument error for unrecognized strings.
ENUM from_string(const std::string &val)
Return enum class object from string representation.
std::set< ENUM > matches(const std::string &val)
Return all matching enum class members from string representation.
std::string to_string(ENUM val)
Return string representation of enum class.
std::string standard_singleline_enum_help(std::string _default="", std::string other="")
Print short help message describing recognized strings for allowed enum values.
std::string multiline_enum_help()
Print help message describing recognized strings for allowed enum values.
std::string standard_singleline_help(StringContainer options, std::string _default="")
Print short help message describing recognized strings for allowed enum values.