osuplusplus/include/config.hpp
jacekpoz f6784c2848
get rid of VAR_BITS
I hate this stupid fucking thing you can't print them normally
2024-04-18 20:16:01 +02:00

152 lines
3.5 KiB
C++

#pragma once
#include <cinttypes>
#include <vector>
#include <SFML/Graphics/Color.hpp>
#include <foreach.hpp>
#define CONFIG(name, ...) \
struct name {\
__VA_ARGS__\
};
#define SECTION(name, ...) \
struct {\
__VA_ARGS__\
} name;
#define VAR_UINT(section, name) uint name;
#define VAR_UINT_D(section, name, default) uint name = default;
#define VAR_INT(section, name) int name;
#define VAR_INT_D(section, name, default) int name = default;
#define VAR_STRING(section, name) std::string name;
#define VAR_STRING_D(section, name, default) std::string name = default;
#define VAR_BOOL(section, name) bool name;
#define VAR_BOOL_D(section, name, default) bool name = default;
#define VAR_FLOAT(section, name) double name;
#define VAR_FLOAT_D(section, name, default) double name = default;
#define VAR_COLOUR(section, name) sf::Color name;
#define VAR_COLOUR_D(section, name, default) sf::Color name = default;
#define VAR_LIST(section, name, type) std::vector<type> name;
#define VAR_LIST_SEP(section, name, type, sep) std::vector<type> name;
#define VAR_LIST_NUMBERED(section, name, type) std::vector<type> name;
#define ENUM(name, ...) \
enum class name {\
__VA_ARGS__\
};\
ENUM_STREAM_OPS(name, __VA_ARGS__)
#define VAR_ENUM(section, name, enum_type) enum_type name;
#define VAR_ENUM_D(section, name, enum_type, default) enum_type name = enum_type::default;
#define STRUCT(name, ...) \
struct name {\
__VA_ARGS__\
};
#define VAR_STRUCT(section, name, struct_type) struct_type name;
#define VAR_STRUCT_D(section, name, struct_type, default) struct_type name = default;
#define ENUM_TO_STRING_CASE(name, e) case name::e: os << #e;
#define ENUM_FROM_STRING(name, e) if (input == #e) en = name::e;
#define ENUM_STREAM_OPS(name, ...) \
inline std::ostream &operator<<(std::ostream &os, const name &en) {\
switch (en) {\
FOR_EACH(ENUM_TO_STRING_CASE, name, __VA_ARGS__)\
}\
return os;\
}\
\
inline std::istream &operator>>(std::istream &is, name &en) {\
std::string input;\
is >> input;\
FOR_EACH(ENUM_FROM_STRING, name, __VA_ARGS__)\
return is;\
}
#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;\
}\
\
inline std::istream &operator>>(std::istream &is, name &str) {\
std::string input;\
std::stringstream ss;\
FOR_EACH(STRUCT_FROM_STRING, name, __VA_ARGS__)\
return is;\
}
#include <config_def.hpp>
#undef FE_0
#undef FE_1
#undef FE_2
#undef FE_3
#undef FE_4
#undef FE_5
#undef GET_MACRO
#undef FOR_EACH
#undef CONFIG
#undef SECTION
#undef UINT
#undef VAR_UINT
#undef VAR_UINT_D
#undef INT
#undef VAR_INT
#undef VAR_INT_D
#undef STRING
#undef VAR_STRING
#undef VAR_STRING_D
#undef BOOL
#undef VAR_BOOL
#undef VAR_BOOL_D
#undef FLOAT
#undef VAR_FLOAT
#undef VAR_FLOAT_D
#undef COLOUR
#undef VAR_COLOUR
#undef VAR_COLOUR_D
#undef ENUM_TO_STRING_CASE
#undef ENUM_FROM_STRING
#undef ENUM
#undef VAR_ENUM
#undef VAR_ENUM_D
#undef STRUCT_FIELD_TO_STRING
#undef STRUCT_FROM_STRING
#undef STRUCT
#undef VAR_STRUCT
#undef VAR_STRUCT_D
#undef VAR_LIST
#undef VAR_LIST_SEP
#undef VAR_LIST_NUMBERED