diff --git a/src/osuparser.cpp b/src/osuparser.cpp index 4516fef..237b68d 100644 --- a/src/osuparser.cpp +++ b/src/osuparser.cpp @@ -108,157 +108,100 @@ inline std::string checkAndRemove(const std::string &str, const std::string &pre ret section.name = default;\ __VA_ARGS__) +#define UINT_GENERIC uint value = std::stoull(checkAndRemove(line, _prefix)); + #define VAR_UINT(section, name) \ - VAR_GENERIC(section, name,\ - uint value = std::stoull(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC(section, name, UINT_GENERIC) #define VAR_UINT_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - uint value = std::stoull(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_P(section, name, prefix, UINT_GENERIC) #define VAR_UINT_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - uint value = std::stoull(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_D(section, name, default, UINT_GENERIC) + +#define INT_GENERIC int value = std::stoll(checkAndRemove(line, _prefix)); #define VAR_INT(section, name) \ - VAR_GENERIC(section, name,\ - int value = std::stoll(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC(section, name, INT_GENERIC) #define VAR_INT_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - int value = std::stoll(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_P(section, name, prefix, INT_GENERIC) #define VAR_INT_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - int value = std::stoll(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_D(section, name, default, INT_GENERIC) + +#define STRING_GENERIC std::string value = checkAndRemove(line, _prefix); #define VAR_STRING(section, name) \ - VAR_GENERIC(section, name,\ - std::string value = checkAndRemove(line, _prefix);\ - ) + VAR_GENERIC(section, name, STRING_GENERIC) #define VAR_STRING_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - std::string value = checkAndRemove(line, _prefix);\ - ) + VAR_GENERIC_P(section, name, prefix, STRING_GENERIC) #define VAR_STRING_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - std::string value = checkAndRemove(line, _prefix);\ - ) + VAR_GENERIC_D(section, name, default, STRING_GENERIC) + +#define BOOL_GENERIC bool value = std::stoi(checkAndRemove(line, _prefix)); #define VAR_BOOL(section, name) \ - VAR_GENERIC(section, name,\ - bool value = std::stoi(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC(section, name, BOOL_GENERIC) #define VAR_BOOL_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - bool value = std::stoi(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_P(section, name, prefix, BOOL_GENERIC) #define VAR_BOOL_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - bool value = std::stoi(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_D(section, name, default, BOOL_GENERIC) + +#define FLOAT_GENERIC double value = std::stof(checkAndRemove(line, _prefix)); #define VAR_FLOAT(section, name) \ - VAR_GENERIC(section, name,\ - double value = std::stof(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC(section, name, FLOAT_GENERIC) #define VAR_FLOAT_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - double value = std::stof(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_P(section, name, prefix, FLOAT_GENERIC) #define VAR_FLOAT_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - double value = std::stof(checkAndRemove(line, _prefix));\ - ) + VAR_GENERIC_D(section, name, default, FLOAT_GENERIC) + +#define COLOUR_GENERIC \ + std::string val = checkAndRemove(line, _prefix);\ + std::array 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) \ - VAR_GENERIC(section, name,\ - std::string val = checkAndRemove(line, _prefix);\ - std::array 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]);\ - ) + VAR_GENERIC(section, name, COLOUR_GENERIC) #define VAR_COLOUR_P(section, name, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - std::string val = checkAndRemove(line, _prefix);\ - std::array 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]);\ - ) + VAR_GENERIC_P(section, name, prefix, COLOUR_GENERIC) #define VAR_COLOUR_D(section, name, default) \ - VAR_GENERIC_D(section, name, default,\ - std::string val = checkAndRemove(line, _prefix);\ - std::array 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]);\ - ) + VAR_GENERIC_D(section, name, default, COLOUR_GENERIC) + +#define ENUM_GENERIC(enum_type) \ + std::string val = checkAndRemove(line, _prefix);\ + std::stringstream ss(val);\ + enum_type value;\ + ss >> value; #define ENUM(name, ...) #define VAR_ENUM(section, name, enum_type) \ - VAR_GENERIC(section, name,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - enum_type value;\ - ss >> value;\ - ) + VAR_GENERIC(section, name, ENUM_GENERIC(enum_type)) #define VAR_ENUM_P(section, name, enum_type, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - enum_type value;\ - ss >> value;\ - ) + VAR_GENERIC_P(section, name, prefix, ENUM_GENERIC(enum_type)) #define VAR_ENUM_D(section, name, enum_type, default) \ - VAR_GENERIC_D(section, name, enum_type::default,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - enum_type value;\ - ss >> value;\ - ) + VAR_GENERIC_D(section, name, enum_type::default, ENUM_GENERIC(enum_type)) #define STRUCT_INPUT_STREAM_OP(name, ...) #define STRUCT_OUTPUT_STREAM_OP(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 VAR_STRUCT(section, name, struct_type) \ - VAR_GENERIC(section, name,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - struct_type value;\ - ss >> value;\ - ) + VAR_GENERIC(section, name, STRUCT_GENERIC(struct_type)) #define VAR_STRUCT_P(section, name, struct_type, prefix) \ - VAR_GENERIC_P(section, name, prefix,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - struct_type value;\ - ss >> value;\ - ) + VAR_GENERIC_P(section, name, prefix, STRUCT_GENERIC(struct_type)) #define VAR_STRUCT_D(section, name, struct_type, default) \ - VAR_GENERIC_D(section, name, default,\ - std::string val = checkAndRemove(line, _prefix);\ - std::stringstream ss(val);\ - struct_type value;\ - ss >> value;\ - ) + VAR_GENERIC_D(section, name, default, STRUCT_GENERIC(struct_type)) #define VAR_LIST(section, name, type) \ VAR_GENERIC(section, name,\