handle parsing ints to enums

This commit is contained in:
jacekpoz 2024-04-25 22:35:14 +02:00
parent ad03011871
commit 725cae21eb
Signed by: poz
SSH key fingerprint: SHA256:JyLeVWE4bF3tDnFeUpUaJsPsNlJyBldDGV/dIKSLyN8

View file

@ -8,6 +8,7 @@
#endif #endif
#include <util_stream_ops.hpp> #include <util_stream_ops.hpp>
#include <string_util.hpp>
#include <foreach.hpp> #include <foreach.hpp>
@ -74,6 +75,11 @@
inline std::istream &operator>>(std::istream &is, name &en) {\ inline std::istream &operator>>(std::istream &is, name &en) {\
std::string input;\ std::string input;\
is >> input;\ is >> input;\
if (isInt(input)) {\
en = static_cast<name>(std::stoul(input));\
return is;\
}\
toUpper(input);\
FOR_EACH(ENUM_FROM_STRING, name, __VA_ARGS__)\ FOR_EACH(ENUM_FROM_STRING, name, __VA_ARGS__)\
return is;\ return is;\
} }