push entire parse function into CONFIG macro
This commit is contained in:
parent
0e05eee14a
commit
f4490f2c6c
1 changed files with 36 additions and 37 deletions
|
@ -28,26 +28,43 @@ inline void toLower(std::string &str) {
|
|||
}
|
||||
|
||||
#define CONFIG(name, ...) \
|
||||
name parse##name(fs::path configPath) {\
|
||||
if (!fs::exists(configPath)) {\
|
||||
std::cerr << #name << " file not found: " << configPath << "\n";\
|
||||
std::exit(EXIT_FAILURE);\
|
||||
}\
|
||||
\
|
||||
if (!fs::is_regular_file(configPath)) {\
|
||||
std::cerr << #name << " file isn't a regular file: " << configPath << "\n";\
|
||||
std::exit(EXIT_FAILURE);\
|
||||
}\
|
||||
\
|
||||
std::ifstream configFile(configPath);\
|
||||
if (!configFile.is_open()) {\
|
||||
std::cerr << "can't open " << #name << " file: " << configPath << "\n";\
|
||||
std::exit(EXIT_FAILURE);\
|
||||
}\
|
||||
std::string line;\
|
||||
\
|
||||
\
|
||||
name ret;\
|
||||
std::string currentSection;\
|
||||
std::string namePascalCased;\
|
||||
\
|
||||
while (std::getline(diffFile, line)) {\
|
||||
\
|
||||
while (std::getline(configFile, line)) {\
|
||||
/* remove \n*/\
|
||||
line.pop_back();\
|
||||
\
|
||||
\
|
||||
if (line.starts_with('[') && line.ends_with(']')) {\
|
||||
currentSection = line.substr(1, line.length() - 2);\
|
||||
toLower(currentSection);\
|
||||
continue;\
|
||||
}\
|
||||
\
|
||||
\
|
||||
__VA_ARGS__\
|
||||
}\
|
||||
\
|
||||
return ret;
|
||||
\
|
||||
return ret;\
|
||||
}
|
||||
|
||||
#define SECTION(name, ...) \
|
||||
if (currentSection == #name) {\
|
||||
|
@ -189,22 +206,4 @@ inline void toLower(std::string &str) {
|
|||
std::vector<type> value;\
|
||||
)
|
||||
|
||||
Difficulty parseDifficulty(fs::path difficultyPath) {
|
||||
if (!fs::exists(difficultyPath)) {
|
||||
std::cerr << "difficulty file not found: " << difficultyPath << "\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!fs::is_regular_file(difficultyPath)) {
|
||||
std::cerr << "difficulty file isn't a regular file: " << difficultyPath << "\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
std::ifstream diffFile(difficultyPath);
|
||||
if (!diffFile.is_open()) {
|
||||
std::cerr << "can't open difficulty file: " << difficultyPath << "\n";
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#include <config_def.hpp>
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue