From c5491dbc9f239addf2caee93eea480f6a4d45330 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Sat, 20 Apr 2024 13:37:06 +0200 Subject: [PATCH] refactor a huge part of the code this allows for creating only input and output streams and allows me to finally print out the generated config struct --- include/config.hpp | 26 ++++++++++++------- include/config_def.hpp | 49 +++++++++++++++++++++++++++++++++++ include/foreach.hpp | 46 ++++++++++++++++++++++++++++++--- include/osuparser.hpp | 4 +++ include/util_stream_ops.hpp | 4 +-- src/HitObjectDrawable.cpp | 2 ++ src/main.cpp | 51 +------------------------------------ src/osuparser.cpp | 2 ++ 8 files changed, 120 insertions(+), 64 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index 50ff37a..a1218da 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -6,6 +6,7 @@ #include #include +#include #define CONFIG(name, ...) \ struct name {\ @@ -82,20 +83,13 @@ #define VAR_STRUCT_P(section, name, prefix) VAR_STRUCT(section, name) #define VAR_STRUCT_D(section, name, struct_type, default) struct_type name = default; -#define STRUCT_FIELD_TO_STRING(name, field) os << #field << ": " << str.field << "\n"; +#define STRUCT_FIELD_TO_STRING(name, field) os << " " << #field << ": " << str.field << "\n"; #define STRUCT_FROM_STRING(name, field) \ std::getline(is, input, ',');\ ss = std::stringstream(input);\ ss >> str.field; -#define STRUCT_STREAM_OPS(name, ...) \ - inline std::ostream &operator<<(std::ostream &os, const name &str) {\ - os << #name << " {\n";\ - FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\ - os << "}\n";\ - return os;\ - }\ -\ +#define STRUCT_INPUT_STREAM_OP(name, ...) \ inline std::istream &operator>>(std::istream &is, name &str) {\ std::string input;\ std::stringstream ss;\ @@ -103,6 +97,18 @@ return is;\ } +#define STRUCT_OUTPUT_STREAM_OP(name, ...) \ + inline std::ostream &operator<<(std::ostream &os, const name &str) {\ + os << #name << " {\n";\ + FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\ + os << "}\n";\ + return os;\ + }\ + +#define STRUCT_STREAM_OPS(name, ...) \ + STRUCT_INPUT_STREAM_OP(name, __VA_ARGS__) \ + STRUCT_OUTPUT_STREAM_OP(name, __VA_ARGS__) + #include #undef CONFIG @@ -150,6 +156,8 @@ #undef STRUCT_FIELD_TO_STRING #undef STRUCT_FROM_STRING +#undef STRUCT_INPUT_STREAM_OP +#undef STRUCT_OUTPUT_STREAM_OP #undef STRUCT_STREAM_OPS #undef VAR_LIST diff --git a/include/config_def.hpp b/include/config_def.hpp index 78adf59..5ceaf0b 100644 --- a/include/config_def.hpp +++ b/include/config_def.hpp @@ -38,6 +38,8 @@ #define VAR_STRUCT_P(section, name, prefix) #define VAR_STRUCT_D(section, name, struct_type, default) +#define STRUCT_INPUT_STREAM_OP(name, ...) +#define STRUCT_OUTPUT_STREAM_OP(name, ...) #define STRUCT_STREAM_OPS(name, ...) #define VAR_LIST(section, name, type) @@ -169,6 +171,51 @@ CONFIG(Difficulty, VAR_LIST(, hitObjects, HitObject) ) +STRUCT_OUTPUT_STREAM_OP(Difficulty, + formatVersion, + general.audioFilename, + general.audioLeadIn, + general.previewTime, + general.countdown, + general.sampleSet, + general.stackLeniency, + general.mode, + general.letterboxInBreaks, + general.useSkinSprites, + general.overlayPosition, + general.skinPreference, + general.epilepsyWarning, + general.countdownOffset, + general.specialStyle, + general.widescreenStoryboard, + general.sampleMatchPlaybackRate, + editor.bookmarks, + editor.distanceSpacing, + editor.beatDivisor, + editor.gridSize, + editor.timelineZoom, + metadata.title, + metadata.titleUnicode, + metadata.artist, + metadata.artistUnicode, + metadata.creator, + metadata.version, + metadata.source, + metadata.tags, + metadata.beatmapID, + metadata.beatmapSetID, + difficulty.hpDrainRate, + difficulty.circleSize, + difficulty.overallDifficulty, + difficulty.approachRate, + difficulty.sliderMultiplier, + difficulty.sliderTickRate, + timingPoints, + colours.combo, + colours.sliderTrackOverride, + colours.sliderBorder, + hitObjects +) #ifdef CONFIG_DEFINED #undef CONFIG @@ -208,6 +255,8 @@ CONFIG(Difficulty, #undef VAR_STRUCT_P #undef VAR_STRUCT_D +#undef STRUCT_INPUT_STREAM_OP +#undef STRUCT_OUTPUT_STREAM_OP #undef STRUCT_STREAM_OPS #undef VAR_LIST diff --git a/include/foreach.hpp b/include/foreach.hpp index 67968dc..c854ff1 100644 --- a/include/foreach.hpp +++ b/include/foreach.hpp @@ -11,7 +11,47 @@ #define FE_7(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_6(WHAT, extra_arg, __VA_ARGS__) #define FE_8(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_7(WHAT, extra_arg, __VA_ARGS__) #define FE_9(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_8(WHAT, extra_arg, __VA_ARGS__) +#define FE_10(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_9(WHAT, extra_arg, __VA_ARGS__) +#define FE_11(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_10(WHAT, extra_arg, __VA_ARGS__) +#define FE_12(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_11(WHAT, extra_arg, __VA_ARGS__) +#define FE_13(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_12(WHAT, extra_arg, __VA_ARGS__) +#define FE_14(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_13(WHAT, extra_arg, __VA_ARGS__) +#define FE_15(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_14(WHAT, extra_arg, __VA_ARGS__) +#define FE_16(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_15(WHAT, extra_arg, __VA_ARGS__) +#define FE_17(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_16(WHAT, extra_arg, __VA_ARGS__) +#define FE_18(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_17(WHAT, extra_arg, __VA_ARGS__) +#define FE_19(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_18(WHAT, extra_arg, __VA_ARGS__) +#define FE_20(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_19(WHAT, extra_arg, __VA_ARGS__) +#define FE_21(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_20(WHAT, extra_arg, __VA_ARGS__) +#define FE_22(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_21(WHAT, extra_arg, __VA_ARGS__) +#define FE_23(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_22(WHAT, extra_arg, __VA_ARGS__) +#define FE_24(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_23(WHAT, extra_arg, __VA_ARGS__) +#define FE_25(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_24(WHAT, extra_arg, __VA_ARGS__) +#define FE_26(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_25(WHAT, extra_arg, __VA_ARGS__) +#define FE_27(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_26(WHAT, extra_arg, __VA_ARGS__) +#define FE_28(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_27(WHAT, extra_arg, __VA_ARGS__) +#define FE_29(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_28(WHAT, extra_arg, __VA_ARGS__) +#define FE_30(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_29(WHAT, extra_arg, __VA_ARGS__) +#define FE_31(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_30(WHAT, extra_arg, __VA_ARGS__) +#define FE_32(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_31(WHAT, extra_arg, __VA_ARGS__) +#define FE_33(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_32(WHAT, extra_arg, __VA_ARGS__) +#define FE_34(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_33(WHAT, extra_arg, __VA_ARGS__) +#define FE_35(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_34(WHAT, extra_arg, __VA_ARGS__) +#define FE_36(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_35(WHAT, extra_arg, __VA_ARGS__) +#define FE_37(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_36(WHAT, extra_arg, __VA_ARGS__) +#define FE_38(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_37(WHAT, extra_arg, __VA_ARGS__) +#define FE_39(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_38(WHAT, extra_arg, __VA_ARGS__) +#define FE_40(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_39(WHAT, extra_arg, __VA_ARGS__) +#define FE_41(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_40(WHAT, extra_arg, __VA_ARGS__) +#define FE_42(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_41(WHAT, extra_arg, __VA_ARGS__) +#define FE_43(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_42(WHAT, extra_arg, __VA_ARGS__) +#define FE_44(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_43(WHAT, extra_arg, __VA_ARGS__) +#define FE_45(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_44(WHAT, extra_arg, __VA_ARGS__) +#define FE_46(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_45(WHAT, extra_arg, __VA_ARGS__) +#define FE_47(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_46(WHAT, extra_arg, __VA_ARGS__) +#define FE_48(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_47(WHAT, extra_arg, __VA_ARGS__) +#define FE_49(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_48(WHAT, extra_arg, __VA_ARGS__) +#define FE_50(WHAT, extra_arg, X, ...) WHAT(extra_arg, X)FE_49(WHAT, extra_arg, __VA_ARGS__) -#define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,NAME,...) NAME -#define FOR_EACH(action,extra_arg,...) \ - GET_MACRO(_0,__VA_ARGS__,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)(action,extra_arg,__VA_ARGS__) +#define GET_MACRO(_0,_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26,_27,_28,_29,_30,_31,_32,_33,_34,_35,_36,_37,_38,_39,_40,_41,_42,_43,_44,_45,_46,_47,_48,_49,_50,NAME,...) NAME +#define FOR_EACH(action,extra_arg,...) GET_MACRO(_0,__VA_ARGS__,FE_50,FE_49,FE_48,FE_47,FE_46,FE_45,FE_44,FE_43,FE_42,FE_41,FE_40,FE_39,FE_38,FE_37,FE_36,FE_35,FE_34,FE_33,FE_32,FE_31,FE_30,FE_29,FE_28,FE_27,FE_26,FE_25,FE_24,FE_23,FE_22,FE_21,FE_20,FE_19,FE_18,FE_17,FE_16,FE_15,FE_14,FE_13,FE_12,FE_11,FE_10,FE_9,FE_8,FE_7,FE_6,FE_5,FE_4,FE_3,FE_2,FE_1,FE_0)(action,extra_arg,__VA_ARGS__) diff --git a/include/osuparser.hpp b/include/osuparser.hpp index 86add2a..c89ff16 100644 --- a/include/osuparser.hpp +++ b/include/osuparser.hpp @@ -31,6 +31,8 @@ namespace fs = std::filesystem; #define VAR_ENUM(section, name, enum_type) #define VAR_ENUM_D(section, name, enum_type, default) +#define STRUCT_INPUT_STREAM_OP(name, ...) +#define STRUCT_OUTPUT_STREAM_OP(name, ...) #define STRUCT_STREAM_OPS(name, ...) #define STRUCT(name, ...) @@ -68,6 +70,8 @@ namespace fs = std::filesystem; #undef VAR_ENUM #undef VAR_ENUM_D +#undef STRUCT_INPUT_STREAM_OP +#undef STRUCT_OUTPUT_STREAM_OP #undef STRUCT_STREAM_OPS #undef STRUCT diff --git a/include/util_stream_ops.hpp b/include/util_stream_ops.hpp index 22e19ce..ee66b59 100644 --- a/include/util_stream_ops.hpp +++ b/include/util_stream_ops.hpp @@ -6,13 +6,13 @@ #include -std::ostream &operator<<(std::ostream &stream, const sf::Color &color) { +inline std::ostream &operator<<(std::ostream &stream, const sf::Color &color) { stream << "Color(" << color.r << ", " << color.g << ", " << color.b << ", " << color.a << ")"; return stream; } template -std::ostream &operator<<(std::ostream &stream, const std::vector &vec) { +inline std::ostream &operator<<(std::ostream &stream, const std::vector &vec) { stream << "["; for (size_t i = 0; i < vec.size(); ++i) { stream << vec.at(i); diff --git a/src/HitObjectDrawable.cpp b/src/HitObjectDrawable.cpp index 803f5c0..467e9be 100644 --- a/src/HitObjectDrawable.cpp +++ b/src/HitObjectDrawable.cpp @@ -1,5 +1,7 @@ #include +#include + #include HitObjectDrawable::HitObjectDrawable(TextureManager &tman, const HitObject &hitObject, const DifficultySettings &diff, const uint comboCount) diff --git a/src/main.cpp b/src/main.cpp index a9e940a..75a86c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,56 +63,7 @@ int main(int argc, char *argv[]) { i += 1; Difficulty diff = parseDifficulty(argv[i]); - std::cout << "osu format version: " << diff.formatVersion << "\n"; - - std::cout << "general.audioFilename: " << diff.general.audioFilename << "\n"; - std::cout << "general.audioLeadIn: " << diff.general.audioLeadIn << "\n"; - std::cout << "general.previewTime: " << diff.general.previewTime << "\n"; - std::cout << "general.countdown: " << diff.general.countdown << "\n"; - std::cout << "general.sampleSet: " << diff.general.sampleSet << "\n"; - std::cout << "general.stackLeniency: " << diff.general.stackLeniency << "\n"; - std::cout << "general.mode: " << diff.general.mode << "\n"; - std::cout << "general.letterboxInBreaks: " << diff.general.letterboxInBreaks << "\n"; - std::cout << "general.useSkinSprites: " << diff.general.useSkinSprites << "\n"; - std::cout << "general.overlayPosition: " << diff.general.overlayPosition << "\n"; - std::cout << "general.skinPreference: " << diff.general.skinPreference << "\n"; - std::cout << "general.epilepsyWarning: " << diff.general.epilepsyWarning << "\n"; - std::cout << "general.countdownOffset: " << diff.general.countdownOffset << "\n"; - std::cout << "general.specialStyle: " << diff.general.specialStyle << "\n"; - std::cout << "general.widescreenStoryboard: " << diff.general.widescreenStoryboard << "\n"; - std::cout << "general.sampleMatchPlaybackRate: " << diff.general.sampleMatchPlaybackRate << "\n"; - - std::cout << "editor.bookmarks: " << diff.editor.bookmarks << "\n"; - std::cout << "editor.distanceSpacing: " << diff.editor.distanceSpacing << "\n"; - std::cout << "editor.beatDivisor: " << diff.editor.beatDivisor << "\n"; - std::cout << "editor.gridSize: " << diff.editor.gridSize << "\n"; - std::cout << "editor.timelineZoom: " << diff.editor.timelineZoom << "\n"; - - std::cout << "metadata.title: " << diff.metadata.title << "\n"; - std::cout << "metadata.titleUnicode: " << diff.metadata.titleUnicode << "\n"; - std::cout << "metadata.artist: " << diff.metadata.artist << "\n"; - std::cout << "metadata.artistUnicode: " << diff.metadata.artistUnicode << "\n"; - std::cout << "metadata.creator: " << diff.metadata.creator << "\n"; - std::cout << "metadata.version: " << diff.metadata.version << "\n"; - std::cout << "metadata.source: " << diff.metadata.source << "\n"; - std::cout << "metadata.tags: " << diff.metadata.tags << "\n"; - std::cout << "metadata.beatmapID: " << diff.metadata.beatmapID << "\n"; - std::cout << "metadata.beatmapSetID: " << diff.metadata.beatmapSetID << "\n"; - - std::cout << "difficulty.hpDrainRate: " << diff.difficulty.hpDrainRate << "\n"; - std::cout << "difficulty.circleSize: " << diff.difficulty.circleSize << "\n"; - std::cout << "difficulty.overallDifficulty: " << diff.difficulty.overallDifficulty << "\n"; - std::cout << "difficulty.approachRate: " << diff.difficulty.approachRate << "\n"; - std::cout << "difficulty.sliderMultiplier: " << diff.difficulty.sliderMultiplier << "\n"; - std::cout << "difficulty.sliderTickRate: " << diff.difficulty.sliderTickRate << "\n"; - - std::cout << "timingPoints: " << diff.timingPoints << "\n"; - - std::cout << "colours.combo: " << diff.colours.combo << "\n"; - std::cout << "colours.sliderTrackOverride: " << diff.colours.sliderTrackOverride << "\n"; - std::cout << "colours.sliderBorder: " << diff.colours.sliderBorder << "\n"; - - std::cout << "hitObjects: " << diff.hitObjects << "\n"; + std::cout << diff << "\n"; std::exit(EXIT_SUCCESS); } diff --git a/src/osuparser.cpp b/src/osuparser.cpp index 62be21a..564523a 100644 --- a/src/osuparser.cpp +++ b/src/osuparser.cpp @@ -216,6 +216,8 @@ inline void toLower(std::string &str) { ss >> value;\ ) +#define STRUCT_INPUT_STREAM_OP(name, ...) +#define STRUCT_OUTPUT_STREAM_OP(name, ...) #define STRUCT_STREAM_OPS(name, ...) #define STRUCT(name, ...)