Prefix macro utils macros that are not intended for external use.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
e0f9629946
commit
623dd9cb20
17
src/Enum.hpp
17
src/Enum.hpp
|
@ -50,32 +50,33 @@
|
||||||
\
|
\
|
||||||
public: \
|
public: \
|
||||||
constexpr static const char* ToString(name value) { \
|
constexpr static const char* ToString(name value) { \
|
||||||
switch (value) { FOR_EACH(ENUM_CASE, name, values) } \
|
switch (value) { MACRO_UTILS_FOR_EACH(ENUM_CASE, name, values) } \
|
||||||
throw std::logic_error("Not reachable"); \
|
throw std::logic_error("Not reachable"); \
|
||||||
} \
|
} \
|
||||||
constexpr static name Parse(const char* input, bool caseInsensitive = false) { \
|
constexpr static name Parse(const char* input, bool caseInsensitive = false) { \
|
||||||
if (caseInsensitive) \
|
if (caseInsensitive) \
|
||||||
return ParseCaseInsensitive(input); \
|
return ParseCaseInsensitive(input); \
|
||||||
switch (ConstHash(input)) { FOR_EACH(ENUM_PARSE_CASE, name, values) } \
|
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE, name, values) } \
|
||||||
throw std::runtime_error("Invalid " #name " string."); \
|
throw std::runtime_error("Invalid " #name " string."); \
|
||||||
} \
|
} \
|
||||||
constexpr static bool TryParse(const char* input, name& out, bool caseInsensitive = false) { \
|
constexpr static bool TryParse(const char* input, name& out, bool caseInsensitive = false) { \
|
||||||
if (caseInsensitive) \
|
if (caseInsensitive) \
|
||||||
return TryParseCaseInsensitive(input, out); \
|
return TryParseCaseInsensitive(input, out); \
|
||||||
switch (ConstHash(input)) { FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \
|
switch (ConstHash(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE, name, values) } \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
static std::vector<name> GetValues() { return {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::GET_LAST(values); } \
|
constexpr static name Last() { return name::MACRO_UTILS_GET_LAST(values); } \
|
||||||
constexpr static name First() { return name::GET_FIRST(values); } \
|
constexpr static name First() { return name::MACRO_UTILS_GET_FIRST(values); } \
|
||||||
\
|
\
|
||||||
private: \
|
private: \
|
||||||
constexpr static name ParseCaseInsensitive(const char* input) { \
|
constexpr static name ParseCaseInsensitive(const char* input) { \
|
||||||
switch (ConstHashCI(input)) { FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \
|
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_PARSE_CASE_INSENSITIVE, name, values) } \
|
||||||
throw std::runtime_error("Invalid " #name " string."); \
|
throw std::runtime_error("Invalid " #name " string."); \
|
||||||
} \
|
} \
|
||||||
constexpr static bool TryParseCaseInsensitive(const char* input, name& out) { \
|
constexpr static bool TryParseCaseInsensitive(const char* input, name& out) { \
|
||||||
switch (ConstHashCI(input)) { FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \
|
switch (ConstHashCI(input)) { MACRO_UTILS_FOR_EACH(ENUM_TRY_PARSE_CASE_INSENSITIVE, name, values) } \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
1048
src/MacroUtils.hpp
1048
src/MacroUtils.hpp
File diff suppressed because one or more lines are too long
|
@ -4,47 +4,47 @@ def generator(num):
|
||||||
file.write("//\n//\n// THIS FILE IS AUTOGENERATED, DO NOT EDIT!\n//\n//\n")
|
file.write("//\n//\n// THIS FILE IS AUTOGENERATED, DO NOT EDIT!\n//\n//\n")
|
||||||
|
|
||||||
file.write("// Defines a for each macro utility, with up to " + str(num) + " elements.\n")
|
file.write("// Defines a for each macro utility, with up to " + str(num) + " elements.\n")
|
||||||
file.write("#define FE_0(FUNC, arg)\n")
|
file.write("#define ___MACRO_UTILS_FE_0(FUNC, arg)\n")
|
||||||
file.write("#define FE_1(FUNC, arg, X) FUNC(X, arg)\n")
|
file.write("#define ___MACRO_UTILS_FE_1(FUNC, arg, X) FUNC(X, arg)\n")
|
||||||
for i in range(2, num + 1):
|
for i in range(2, num + 1):
|
||||||
file.write("#define FE_" + str(i) + "(FUNC, arg, X, ...) FUNC(X, arg) 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 FE_" + str(num + 1) +"(FUNC, arg, X, ...) THE_FOREACH_MACRO_CURRENTLY_ONLY_SUPPORTS_UP_TO_" +
|
file.write("#define ___MACRO_UTILS_FE_" + str(num + 1) +"(FUNC, arg, X, ...) THE_FOREACH_MACRO_CURRENTLY_ONLY_SUPPORTS_UP_TO_" +
|
||||||
str(num) + "_VALUES FE_" + str(num) + "(FUNC, arg, __VA_ARGS__)\n")
|
str(num) + "_VALUES ___MACRO_UTILS_FE_" + str(num) + "(FUNC, arg, __VA_ARGS__)\n")
|
||||||
file.write("#define GET_MACRO(")
|
file.write("#define ___MACRO_UTILS_GET_MACRO(")
|
||||||
for i in range(0, num + 2):
|
for i in range(0, num + 2):
|
||||||
file.write("_" + str(i) + ", ")
|
file.write("_" + str(i) + ", ")
|
||||||
file.write("NAME, ...) NAME\n")
|
file.write("NAME, ...) NAME\n")
|
||||||
file.write("#define FOR_EACH(action, arg, ...) GET_MACRO(_0, __VA_ARGS__")
|
file.write("#define MACRO_UTILS_FOR_EACH(action, arg, ...) ___MACRO_UTILS_GET_MACRO(_0, __VA_ARGS__")
|
||||||
for i in range(num + 1, 0, -1):
|
for i in range(num + 1, 0, -1):
|
||||||
file.write(", FE_" + str(i))
|
file.write(", ___MACRO_UTILS_FE_" + str(i))
|
||||||
file.write(") (action, arg, __VA_ARGS__)\n")
|
file.write(") (action, arg, __VA_ARGS__)\n")
|
||||||
|
|
||||||
file.write("// count arguments\n")
|
file.write("// count arguments\n")
|
||||||
file.write("#define NARGS(...) NARGS_(__VA_ARGS__")
|
file.write("#define ___MACRO_UTILS_NARGS(...) ___MACRO_UTILS_NARGS_(__VA_ARGS__")
|
||||||
for i in range(num, -1, -1):
|
for i in range(num, -1, -1):
|
||||||
file.write(", " + str(i))
|
file.write(", " + str(i))
|
||||||
file.write(")\n")
|
file.write(")\n")
|
||||||
|
|
||||||
file.write("#define NARGS_(")
|
file.write("#define ___MACRO_UTILS_NARGS_(")
|
||||||
for i in range(num, 0, -1):
|
for i in range(num, 0, -1):
|
||||||
file.write("_" + str(i) + ", ")
|
file.write("_" + str(i) + ", ")
|
||||||
file.write("N, ...) N\n")
|
file.write("N, ...) N\n")
|
||||||
file.write("// utility (concatenation)\n")
|
file.write("// utility (concatenation)\n")
|
||||||
file.write("#define CONC(A, B) CONC_(A, B)\n")
|
file.write("#define ___MACRO_UTILS_CONC(A, B) ___MACRO_UTILS_CONC_(A, B)\n")
|
||||||
file.write("#define CONC_(A, B) A##B\n\n")
|
file.write("#define ___MACRO_UTILS_CONC_(A, B) A##B\n\n")
|
||||||
file.write("#define GET_ELEM(N, ...) CONC(GET_ELEM_, N)(__VA_ARGS__)\n")
|
file.write("#define ___MACRO_UTILS_GET_ELEM(N, ...) ___MACRO_UTILS_CONC( ___MACRO_UTILS_GET_ELEM_, N)(__VA_ARGS__)\n")
|
||||||
|
|
||||||
for i in range(0, num + 1):
|
for i in range(0, num + 1):
|
||||||
file.write("#define GET_ELEM_" + str(i) +"(")
|
file.write("#define ___MACRO_UTILS_GET_ELEM_" + str(i) +"(")
|
||||||
for j in range(0, i + 1):
|
for j in range(0, i + 1):
|
||||||
file.write("_" + str(j) + ", ")
|
file.write("_" + str(j) + ", ")
|
||||||
file.write("...) _" + str(i) + "\n")
|
file.write("...) _" + str(i) + "\n")
|
||||||
|
|
||||||
file.write("#define GET_LAST(...) GET_ELEM(NARGS(__VA_ARGS__), _, __VA_ARGS__ ,")
|
file.write("#define MACRO_UTILS_GET_LAST(...) ___MACRO_UTILS_GET_ELEM( ___MACRO_UTILS_NARGS(__VA_ARGS__), _, __VA_ARGS__ ,")
|
||||||
for i in range(0, num):
|
for i in range(0, num):
|
||||||
file.write(",")
|
file.write(",")
|
||||||
file.write(")\n")
|
file.write(")\n")
|
||||||
file.write("#define GET_FIRST(...) GET_ELEM_0(__VA_ARGS__)\n")
|
file.write("#define MACRO_UTILS_GET_FIRST(...) ___MACRO_UTILS_GET_ELEM_0(__VA_ARGS__)\n")
|
||||||
|
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue