Support to get highest and lowest values from enums.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
784af6d51a
commit
5710329f39
21
src/Enum.hpp
21
src/Enum.hpp
|
@ -26,6 +26,16 @@
|
||||||
out = name::x; \
|
out = name::x; \
|
||||||
return true;
|
return true;
|
||||||
#
|
#
|
||||||
|
#define ENUM_GET_HIGHEST(x, name) \
|
||||||
|
if ((int64_t)name::x > highest) { \
|
||||||
|
highest = (int64_t)name::x; \
|
||||||
|
}
|
||||||
|
#
|
||||||
|
#define ENUM_GET_LOWEST(x, name) \
|
||||||
|
if ((int64_t)name::x < lowest) { \
|
||||||
|
lowest = (int64_t)name::x; \
|
||||||
|
}
|
||||||
|
#
|
||||||
#define ARRAY_NAME(x, name) name::x,
|
#define ARRAY_NAME(x, name) name::x,
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -68,6 +78,16 @@
|
||||||
static std::vector<name> GetValues() { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \
|
static std::vector<name> GetValues() { return {MACRO_UTILS_FOR_EACH(ARRAY_NAME, name, values)}; } \
|
||||||
constexpr static name Last() { return name::MACRO_UTILS_GET_LAST(values); } \
|
constexpr static name Last() { return name::MACRO_UTILS_GET_LAST(values); } \
|
||||||
constexpr static name First() { return name::MACRO_UTILS_GET_FIRST(values); } \
|
constexpr static name First() { return name::MACRO_UTILS_GET_FIRST(values); } \
|
||||||
|
constexpr static name Highest() { \
|
||||||
|
int64_t highest = -9223372036854775807; \
|
||||||
|
MACRO_UTILS_FOR_EACH(ENUM_GET_HIGHEST, name, values) \
|
||||||
|
return (name)highest; \
|
||||||
|
} \
|
||||||
|
constexpr static name Lowest() { \
|
||||||
|
int64_t lowest = 9223372036854775807; \
|
||||||
|
MACRO_UTILS_FOR_EACH(ENUM_GET_LOWEST, name, values) \
|
||||||
|
return (name)lowest; \
|
||||||
|
} \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
constexpr static name ParseCaseInsensitive(const char* input) { \
|
constexpr static name ParseCaseInsensitive(const char* input) { \
|
||||||
|
@ -79,4 +99,3 @@
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue