2024-03-18 11:25:15 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <SFML/Graphics/Color.hpp>
|
|
|
|
|
2024-04-20 13:37:06 +02:00
|
|
|
#include <util_stream_ops.hpp>
|
2024-03-18 11:25:15 +01:00
|
|
|
|
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;
|
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_UINT(section, name) uint name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_UINT_P(section, name, prefix) VAR_UINT(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_UINT_D(section, name, default) uint name = default;
|
2024-03-18 11:25:15 +01:00
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_INT(section, name) int name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_INT_P(section, name, prefix) VAR_INT(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_INT_D(section, name, default) int name = default;
|
2024-03-18 11:25:15 +01:00
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_STRING(section, name) std::string name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_STRING_P(section, name, prefix) VAR_STRING(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_STRING_D(section, name, default) std::string name = default;
|
2024-03-18 11:25:15 +01:00
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_BOOL(section, name) bool name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_BOOL_P(section, name, prefix) VAR_BOOL(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_BOOL_D(section, name, default) bool name = default;
|
2024-03-18 11:25:15 +01:00
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_FLOAT(section, name) double name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_FLOAT_P(section, name, prefix) VAR_FLOAT(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_FLOAT_D(section, name, default) double name = default;
|
|
|
|
|
|
|
|
#define VAR_COLOUR(section, name) sf::Color name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_COLOUR_P(section, name, prefix) VAR_COLOUR(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#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__\
|
|
|
|
};\
|
2024-04-18 20:11:33 +02:00
|
|
|
ENUM_STREAM_OPS(name, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define VAR_ENUM(section, name, enum_type) enum_type name;
|
2024-04-19 10:14:45 +02:00
|
|
|
#define VAR_ENUM_P(section, name, prefix) VAR_ENUM(section, name)
|
2024-04-18 20:11:33 +02:00
|
|
|
#define VAR_ENUM_D(section, name, enum_type, default) enum_type name = enum_type::default;
|
|
|
|
|
2024-04-18 22:32:01 +02:00
|
|
|
#define ENUM_TO_STRING_CASE(name, e) case name::e: os << #e; break;
|
2024-04-18 20:11:33 +02:00
|
|
|
#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;\
|
|
|
|
}
|
|
|
|
|
2024-04-19 10:14:45 +02:00
|
|
|
#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;
|
|
|
|
|
2024-04-20 13:37:06 +02:00
|
|
|
#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) \
|
2024-04-18 20:11:33 +02:00
|
|
|
std::getline(is, input, ',');\
|
|
|
|
ss = std::stringstream(input);\
|
2024-03-18 11:25:15 +01:00
|
|
|
ss >> str.field;
|
|
|
|
|
2024-04-20 13:37:06 +02:00
|
|
|
#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;\
|
2024-04-18 20:11:33 +02:00
|
|
|
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;\
|
|
|
|
}
|
|
|
|
|
2024-04-20 13:37:06 +02:00
|
|
|
#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__)\
|
2024-04-20 13:41:03 +02:00
|
|
|
os << "}";\
|
2024-04-20 13:37:06 +02:00
|
|
|
return os;\
|
2024-04-23 16:42:24 +02:00
|
|
|
}
|
2024-04-20 13:37:06 +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
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_UINT_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_UINT_D
|
|
|
|
|
|
|
|
#undef VAR_INT
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_INT_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_INT_D
|
|
|
|
|
|
|
|
#undef VAR_STRING
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_STRING_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_STRING_D
|
|
|
|
|
|
|
|
#undef VAR_BOOL
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_BOOL_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_BOOL_D
|
|
|
|
|
|
|
|
#undef VAR_FLOAT
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_FLOAT_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_FLOAT_D
|
2024-04-19 10:14:45 +02:00
|
|
|
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_COLOUR
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef VAR_COLOUR_P
|
2024-03-18 11:25:15 +01:00
|
|
|
#undef VAR_COLOUR_D
|
|
|
|
|
2024-04-19 10:14:45 +02:00
|
|
|
#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
|
|
|
|
|
2024-04-19 10:14:45 +02:00
|
|
|
#undef STRUCT
|
|
|
|
#undef VAR_STRUCT
|
|
|
|
#undef VAR_STRUCT_P
|
|
|
|
#undef VAR_STRUCT_D
|
2024-03-18 11:25:15 +01:00
|
|
|
|
2024-04-18 20:11:33 +02:00
|
|
|
#undef STRUCT_FIELD_TO_STRING
|
|
|
|
#undef STRUCT_FROM_STRING
|
|
|
|
|
2024-04-20 13:37:06 +02:00
|
|
|
#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
|