Implements Enum with specific start value.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
e850f728bc
commit
bc64e35c8a
|
@ -5,6 +5,8 @@
|
|||
#include <vector>
|
||||
#include "MacroUtils.hpp"
|
||||
|
||||
#define ENUM_VALUE(x, value) x = value,
|
||||
#
|
||||
#define ENUM_CASE(x, name) \
|
||||
case name::x: \
|
||||
return #x;
|
||||
|
@ -45,8 +47,8 @@
|
|||
static methods for use with the enum.
|
||||
*/
|
||||
|
||||
#define ENUM(name, type, values...) \
|
||||
enum class name : type { values }; \
|
||||
#define ENUM_WITH_START_VALUE(name, type, startValue, values...) \
|
||||
enum class name : type { MACRO_UTILS_FOR_EACH_WITH_VALUE(ENUM_VALUE, ___MACRO_UTILS_NARGS(values) - 1, values) }; \
|
||||
class name##Helper { \
|
||||
inline static uint32_t constexpr ConstHash(char const* input) { \
|
||||
return *input ? static_cast<uint32_t>(*input) + 33 * ConstHash(input + 1) : 5381; \
|
||||
|
@ -104,3 +106,5 @@
|
|||
return false; \
|
||||
} \
|
||||
};
|
||||
|
||||
#define ENUM(name, type, values...) ENUM_WITH_START_VALUE(name, type, 0, values);
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -7,18 +7,38 @@ def generator(num):
|
|||
file.write("#define ___MACRO_UTILS_FE_0(FUNC, arg)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_1(FUNC, arg, X) FUNC(X, arg)\n")
|
||||
for i in range(2, num + 1):
|
||||
file.write("#define ___MACRO_UTILS_FE_" + str(i) + "(FUNC, arg, X, ...) FUNC(X, arg) ___MACRO_UTILS_FE_" + str(i -1) + "(FUNC, arg, __VA_ARGS__)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_" + str(i) + "(FUNC, arg, X, ...) FUNC(X, arg) ___MACRO_UTILS_FE_" +
|
||||
str(i - 1) + "(FUNC, arg, __VA_ARGS__)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_" + str(num + 1) +"(FUNC, arg, X, ...) THE_FOREACH_MACRO_CURRENTLY_ONLY_SUPPORTS_UP_TO_" +
|
||||
str(num) + "_VALUES ___MACRO_UTILS_FE_" + str(num) + "(FUNC, arg, __VA_ARGS__)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_VAL_0(FUNC, arg)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_VAL_1(FUNC, arg, X) FUNC(X, arg)\n")
|
||||
for i in range(2, num + 1):
|
||||
file.write("#define ___MACRO_UTILS_FE_VAL_" + str(i) + "(FUNC, arg, X, ...) FUNC(X, arg -" + str(i - 1) + ") ___MACRO_UTILS_FE_VAL_" +
|
||||
str(i - 1) + "(FUNC, arg , __VA_ARGS__)\n")
|
||||
file.write("#define ___MACRO_UTILS_FE_VAL_" + str(num + 1) +"(FUNC, arg, X, ...) THE_FOREACH_MACRO_CURRENTLY_ONLY_SUPPORTS_UP_TO_" +
|
||||
str(num) + "_VALUES ___MACRO_UTILS_FE_VAL_" + str(num) + "(FUNC, arg, __VA_ARGS__)\n")
|
||||
|
||||
file.write("#define ___MACRO_UTILS_GET_MACRO(")
|
||||
for i in range(0, num + 2):
|
||||
file.write("_" + str(i) + ", ")
|
||||
file.write("NAME, ...) NAME\n")
|
||||
|
||||
file.write("#define MACRO_UTILS_FOR_EACH(action, arg, ...) ___MACRO_UTILS_GET_MACRO(_0, __VA_ARGS__")
|
||||
for i in range(num + 1, 0, -1):
|
||||
file.write(", ___MACRO_UTILS_FE_" + str(i))
|
||||
file.write(") (action, arg, __VA_ARGS__)\n")
|
||||
|
||||
file.write("#define ___MACRO_UTILS_GET_MACRO_WITH_VALUE(")
|
||||
for i in range(0, num + 2):
|
||||
file.write("_" + str(i) + ", ")
|
||||
file.write("NAME, ...) NAME\n")
|
||||
|
||||
file.write("#define MACRO_UTILS_FOR_EACH_WITH_VALUE(action, arg, ...) ___MACRO_UTILS_GET_MACRO_WITH_VALUE(_0, __VA_ARGS__")
|
||||
for i in range(num + 1, 0, -1):
|
||||
file.write(", ___MACRO_UTILS_FE_VAL_" + str(i))
|
||||
file.write(") (action, arg, __VA_ARGS__)\n")
|
||||
|
||||
file.write("// count arguments\n")
|
||||
file.write("#define ___MACRO_UTILS_NARGS(...) ___MACRO_UTILS_NARGS_(__VA_ARGS__")
|
||||
for i in range(num, -1, -1):
|
||||
|
|
Loading…
Reference in New Issue