osuplusplus/include/config.hpp

174 lines
4.7 KiB
C++
Raw Normal View History

2024-03-18 11:25:15 +01:00
#pragma once
#include <cinttypes>
#include <vector>
#include <SFML/Graphics/Color.hpp>
#include <util_stream_ops.hpp>
2024-03-18 11:25:15 +01:00
awk marker comments to save necessary macros I restructured the beginnings of the preprocessed files for debugging to make the awks in the makefile not eat headers which are needed for debugging (e.g. the FOR_EACH macro) it's done by putting awk marker comments: // awk stop marker (check make pp) after the macros to be eaten by awk and before the ones we wanna keep I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this I hate this
2024-04-24 23:36:25 +02:00
// awk stop marker (check make pp)
// <util_stream_ops.hpp> only brings in operator<< definitions
// for sf::Color and std::vector<T>
// doesn't change output, we only need the FOR_EACH macro
#include <foreach.hpp>
2024-03-18 11:25:15 +01:00
#define CONFIG(name, ...) \
struct name {\
__VA_ARGS__\
};
#define SECTION(name, ...) \
struct {\
__VA_ARGS__\
} name;
#define VAR_UINT(section, name) uint name;
#define VAR_UINT_P(section, name, prefix) VAR_UINT(section, name)
#define VAR_UINT_D(section, name, default) uint name = default;
2024-03-18 11:25:15 +01:00
#define VAR_INT(section, name) int name;
#define VAR_INT_P(section, name, prefix) VAR_INT(section, name)
#define VAR_INT_D(section, name, default) int name = default;
2024-03-18 11:25:15 +01:00
#define VAR_STRING(section, name) std::string name;
#define VAR_STRING_P(section, name, prefix) VAR_STRING(section, name)
#define VAR_STRING_D(section, name, default) std::string name = default;
2024-03-18 11:25:15 +01:00
#define VAR_BOOL(section, name) bool name;
#define VAR_BOOL_P(section, name, prefix) VAR_BOOL(section, name)
#define VAR_BOOL_D(section, name, default) bool name = default;
2024-03-18 11:25:15 +01:00
#define VAR_FLOAT(section, name) double name;
#define VAR_FLOAT_P(section, name, prefix) VAR_FLOAT(section, name)
#define VAR_FLOAT_D(section, name, default) double name = default;
#define VAR_COLOUR(section, name) sf::Color name;
#define VAR_COLOUR_P(section, name, prefix) VAR_COLOUR(section, name)
#define VAR_COLOUR_D(section, name, default) sf::Color name = default;
2024-03-18 11:25:15 +01:00
2024-03-19 19:47:06 +01:00
#define VAR_LIST(section, name, type) std::vector<type> name;
#define VAR_LIST_SEP(section, name, type, sep) std::vector<type> name;
2024-04-21 10:40:43 +02:00
#define VAR_LIST_SEP_P(section, name, type, sep, prefix) std::vector<type> name;
2024-03-19 19:47:06 +01:00
#define VAR_LIST_NUMBERED(section, name, type) std::vector<type> name;
2024-03-18 11:25:15 +01:00
#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_P(section, name, prefix) VAR_ENUM(section, name)
#define VAR_ENUM_D(section, name, enum_type, default) enum_type name = enum_type::default;
#define ENUM_TO_STRING_CASE(name, e) case name::e: os << #e; break;
#define ENUM_FROM_STRING(name, e) if (input == #e) en = name::e;
#define ENUM_STREAM_OPS(name, ...) \
2024-03-18 11:25:15 +01:00
inline std::ostream &operator<<(std::ostream &os, const name &en) {\
switch (en) {\
FOR_EACH(ENUM_TO_STRING_CASE, name, __VA_ARGS__)\
}\
return os;\
}\
2024-04-21 13:34:18 +02:00
\
2024-03-18 11:25:15 +01:00
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(name, ...) \
struct name {\
__VA_ARGS__\
};
#define VAR_STRUCT(section, name, struct_type) struct_type name;
#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";
2024-03-18 11:25:15 +01:00
#define STRUCT_FROM_STRING(name, field) \
std::getline(is, input, ',');\
ss = std::stringstream(input);\
2024-03-18 11:25:15 +01:00
ss >> str.field;
#define STRUCT_INPUT_STREAM_OP(name, ...) \
2024-03-18 11:25:15 +01:00
inline std::istream &operator>>(std::istream &is, name &str) {\
std::string input;\
std::stringstream ss;\
2024-03-19 14:24:47 +01:00
FOR_EACH(STRUCT_FROM_STRING, name, __VA_ARGS__)\
2024-03-18 11:25:15 +01:00
return is;\
}
#define STRUCT_OUTPUT_STREAM_OP(name, ...) \
inline std::ostream &operator<<(std::ostream &os, const name &str) {\
os << #name << " {\n";\
2024-04-23 16:23:29 +02:00
FOR_EACH(STRUCT_FIELD_TO_STRING, name, __VA_ARGS__)\
os << "}";\
return os;\
2024-04-23 16:42:24 +02:00
}
#define STRUCT_STREAM_OPS(name, ...) \
STRUCT_INPUT_STREAM_OP(name, __VA_ARGS__) \
STRUCT_OUTPUT_STREAM_OP(name, __VA_ARGS__)
2024-03-18 11:25:15 +01:00
#include <config_def.hpp>
#undef CONFIG
#undef SECTION
#undef VAR_UINT
#undef VAR_UINT_P
2024-03-18 11:25:15 +01:00
#undef VAR_UINT_D
#undef VAR_INT
#undef VAR_INT_P
2024-03-18 11:25:15 +01:00
#undef VAR_INT_D
#undef VAR_STRING
#undef VAR_STRING_P
2024-03-18 11:25:15 +01:00
#undef VAR_STRING_D
#undef VAR_BOOL
#undef VAR_BOOL_P
2024-03-18 11:25:15 +01:00
#undef VAR_BOOL_D
#undef VAR_FLOAT
#undef VAR_FLOAT_P
2024-03-18 11:25:15 +01:00
#undef VAR_FLOAT_D
2024-03-18 11:25:15 +01:00
#undef VAR_COLOUR
#undef VAR_COLOUR_P
2024-03-18 11:25:15 +01:00
#undef VAR_COLOUR_D
#undef ENUM
#undef VAR_ENUM
#undef VAR_ENUM_P
#undef VAR_ENUM_D
2024-03-18 11:25:15 +01:00
#undef ENUM_TO_STRING_CASE
#undef ENUM_FROM_STRING
2024-04-18 20:41:40 +02:00
#undef ENUM_STREAM_OPS
#undef STRUCT
#undef VAR_STRUCT
#undef VAR_STRUCT_P
#undef VAR_STRUCT_D
2024-03-18 11:25:15 +01:00
#undef STRUCT_FIELD_TO_STRING
#undef STRUCT_FROM_STRING
#undef STRUCT_INPUT_STREAM_OP
#undef STRUCT_OUTPUT_STREAM_OP
2024-04-18 20:41:40 +02:00
#undef STRUCT_STREAM_OPS
2024-03-18 11:25:15 +01:00
#undef VAR_LIST
#undef VAR_LIST_SEP
2024-04-21 10:40:43 +02:00
#undef VAR_LIST_SEP_P
2024-03-18 11:25:15 +01:00
#undef VAR_LIST_NUMBERED