extract parsing logic into separate generic macros
This commit is contained in:
parent
46299a089b
commit
9e92f49757
1 changed files with 57 additions and 114 deletions
|
@ -108,157 +108,100 @@ inline std::string checkAndRemove(const std::string &str, const std::string &pre
|
||||||
ret section.name = default;\
|
ret section.name = default;\
|
||||||
__VA_ARGS__)
|
__VA_ARGS__)
|
||||||
|
|
||||||
|
#define UINT_GENERIC uint value = std::stoull(checkAndRemove(line, _prefix));
|
||||||
|
|
||||||
#define VAR_UINT(section, name) \
|
#define VAR_UINT(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, UINT_GENERIC)
|
||||||
uint value = std::stoull(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_UINT_P(section, name, prefix) \
|
#define VAR_UINT_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, UINT_GENERIC)
|
||||||
uint value = std::stoull(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_UINT_D(section, name, default) \
|
#define VAR_UINT_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, UINT_GENERIC)
|
||||||
uint value = std::stoull(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
#define INT_GENERIC int value = std::stoll(checkAndRemove(line, _prefix));
|
||||||
|
|
||||||
#define VAR_INT(section, name) \
|
#define VAR_INT(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, INT_GENERIC)
|
||||||
int value = std::stoll(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_INT_P(section, name, prefix) \
|
#define VAR_INT_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, INT_GENERIC)
|
||||||
int value = std::stoll(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_INT_D(section, name, default) \
|
#define VAR_INT_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, INT_GENERIC)
|
||||||
int value = std::stoll(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
#define STRING_GENERIC std::string value = checkAndRemove(line, _prefix);
|
||||||
|
|
||||||
#define VAR_STRING(section, name) \
|
#define VAR_STRING(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, STRING_GENERIC)
|
||||||
std::string value = checkAndRemove(line, _prefix);\
|
|
||||||
)
|
|
||||||
#define VAR_STRING_P(section, name, prefix) \
|
#define VAR_STRING_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, STRING_GENERIC)
|
||||||
std::string value = checkAndRemove(line, _prefix);\
|
|
||||||
)
|
|
||||||
#define VAR_STRING_D(section, name, default) \
|
#define VAR_STRING_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, STRING_GENERIC)
|
||||||
std::string value = checkAndRemove(line, _prefix);\
|
|
||||||
)
|
#define BOOL_GENERIC bool value = std::stoi(checkAndRemove(line, _prefix));
|
||||||
|
|
||||||
#define VAR_BOOL(section, name) \
|
#define VAR_BOOL(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, BOOL_GENERIC)
|
||||||
bool value = std::stoi(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_BOOL_P(section, name, prefix) \
|
#define VAR_BOOL_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, BOOL_GENERIC)
|
||||||
bool value = std::stoi(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_BOOL_D(section, name, default) \
|
#define VAR_BOOL_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, BOOL_GENERIC)
|
||||||
bool value = std::stoi(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
#define FLOAT_GENERIC double value = std::stof(checkAndRemove(line, _prefix));
|
||||||
|
|
||||||
#define VAR_FLOAT(section, name) \
|
#define VAR_FLOAT(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, FLOAT_GENERIC)
|
||||||
double value = std::stof(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_FLOAT_P(section, name, prefix) \
|
#define VAR_FLOAT_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, FLOAT_GENERIC)
|
||||||
double value = std::stof(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
|
||||||
#define VAR_FLOAT_D(section, name, default) \
|
#define VAR_FLOAT_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, FLOAT_GENERIC)
|
||||||
double value = std::stof(checkAndRemove(line, _prefix));\
|
|
||||||
)
|
#define COLOUR_GENERIC \
|
||||||
|
std::string val = checkAndRemove(line, _prefix);\
|
||||||
|
std::array<sf::Uint8, 3> colours;\
|
||||||
|
std::stringstream ss(val);\
|
||||||
|
std::string colour;\
|
||||||
|
for (size_t i = 0; i < 3; ++i) {\
|
||||||
|
std::getline(ss, colour, ',');\
|
||||||
|
colours[i] = std::stoul(colour);\
|
||||||
|
}\
|
||||||
|
sf::Color value(colours[0], colours[1], colours[2]);
|
||||||
|
|
||||||
#define VAR_COLOUR(section, name) \
|
#define VAR_COLOUR(section, name) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, COLOUR_GENERIC)
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::array<sf::Uint8, 3> colours;\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
std::string colour;\
|
|
||||||
for (size_t i = 0; i < 3; ++i) {\
|
|
||||||
std::getline(ss, colour, ',');\
|
|
||||||
colours[i] = std::stoul(colour);\
|
|
||||||
}\
|
|
||||||
sf::Color value(colours[0], colours[1], colours[2]);\
|
|
||||||
)
|
|
||||||
#define VAR_COLOUR_P(section, name, prefix) \
|
#define VAR_COLOUR_P(section, name, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, COLOUR_GENERIC)
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::array<sf::Uint8, 3> colours;\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
std::string colour;\
|
|
||||||
for (size_t i = 0; i < 3; ++i) {\
|
|
||||||
std::getline(ss, colour, ',');\
|
|
||||||
colours[i] = std::stoul(colour);\
|
|
||||||
}\
|
|
||||||
sf::Color value(colours[0], colours[1], colours[2]);\
|
|
||||||
)
|
|
||||||
#define VAR_COLOUR_D(section, name, default) \
|
#define VAR_COLOUR_D(section, name, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, COLOUR_GENERIC)
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::array<sf::Uint8, 3> colours;\
|
#define ENUM_GENERIC(enum_type) \
|
||||||
std::stringstream ss(val);\
|
std::string val = checkAndRemove(line, _prefix);\
|
||||||
std::string colour;\
|
std::stringstream ss(val);\
|
||||||
for (size_t i = 0; i < 3; ++i) {\
|
enum_type value;\
|
||||||
std::getline(ss, colour, ',');\
|
ss >> value;
|
||||||
colours[i] = std::stoul(colour);\
|
|
||||||
}\
|
|
||||||
sf::Color value(colours[0], colours[1], colours[2]);\
|
|
||||||
)
|
|
||||||
|
|
||||||
#define ENUM(name, ...)
|
#define ENUM(name, ...)
|
||||||
#define VAR_ENUM(section, name, enum_type) \
|
#define VAR_ENUM(section, name, enum_type) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, ENUM_GENERIC(enum_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
enum_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
#define VAR_ENUM_P(section, name, enum_type, prefix) \
|
#define VAR_ENUM_P(section, name, enum_type, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, ENUM_GENERIC(enum_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
enum_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
#define VAR_ENUM_D(section, name, enum_type, default) \
|
#define VAR_ENUM_D(section, name, enum_type, default) \
|
||||||
VAR_GENERIC_D(section, name, enum_type::default,\
|
VAR_GENERIC_D(section, name, enum_type::default, ENUM_GENERIC(enum_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
enum_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
|
|
||||||
#define STRUCT_INPUT_STREAM_OP(name, ...)
|
#define STRUCT_INPUT_STREAM_OP(name, ...)
|
||||||
#define STRUCT_OUTPUT_STREAM_OP(name, ...)
|
#define STRUCT_OUTPUT_STREAM_OP(name, ...)
|
||||||
#define STRUCT_STREAM_OPS(name, ...)
|
#define STRUCT_STREAM_OPS(name, ...)
|
||||||
|
|
||||||
|
#define STRUCT_GENERIC(struct_type) \
|
||||||
|
std::string val = checkAndRemove(line, _prefix);\
|
||||||
|
std::stringstream ss(val);\
|
||||||
|
struct_type value;\
|
||||||
|
ss >> value;
|
||||||
|
|
||||||
#define STRUCT(name, ...)
|
#define STRUCT(name, ...)
|
||||||
#define VAR_STRUCT(section, name, struct_type) \
|
#define VAR_STRUCT(section, name, struct_type) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name, STRUCT_GENERIC(struct_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
struct_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
#define VAR_STRUCT_P(section, name, struct_type, prefix) \
|
#define VAR_STRUCT_P(section, name, struct_type, prefix) \
|
||||||
VAR_GENERIC_P(section, name, prefix,\
|
VAR_GENERIC_P(section, name, prefix, STRUCT_GENERIC(struct_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
struct_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
#define VAR_STRUCT_D(section, name, struct_type, default) \
|
#define VAR_STRUCT_D(section, name, struct_type, default) \
|
||||||
VAR_GENERIC_D(section, name, default,\
|
VAR_GENERIC_D(section, name, default, STRUCT_GENERIC(struct_type))
|
||||||
std::string val = checkAndRemove(line, _prefix);\
|
|
||||||
std::stringstream ss(val);\
|
|
||||||
struct_type value;\
|
|
||||||
ss >> value;\
|
|
||||||
)
|
|
||||||
|
|
||||||
#define VAR_LIST(section, name, type) \
|
#define VAR_LIST(section, name, type) \
|
||||||
VAR_GENERIC(section, name,\
|
VAR_GENERIC(section, name,\
|
||||||
|
|
Loading…
Reference in a new issue