YAML is a horrid format with far too many edge cases. We have switched to TOML. Further, we have completly reworked the framework so that 1. There is no longer any global config state. Config objects now must be passed between scopes by the caller. This will introduce some more friction but whill also make order of initialization clear 2. Config objects are now strongly typed and there is a single sourth of truth for any given config object baked in using the some struct.
46 lines
826 B
C++
46 lines
826 B
C++
#include "fourdst/config/config.h"
|
|
#include "glaze/glaze.hpp"
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using namespace fourdst::config;
|
|
|
|
struct sub {
|
|
double x;
|
|
double y;
|
|
};
|
|
|
|
struct BoundaryConditions {
|
|
double pressure = 1e6;
|
|
sub sub;
|
|
};
|
|
|
|
struct ExampleConfig {
|
|
double parameterA = 1.0;
|
|
int parameterB = 1.0;
|
|
std::string parameterC = "default_value";
|
|
std::vector<double> parameterD = {0.1, 0.2, 0.3};
|
|
BoundaryConditions boundaryConditions;
|
|
};
|
|
|
|
struct Person {
|
|
int age;
|
|
std::string name;
|
|
};
|
|
|
|
struct AppConfig {
|
|
double x;
|
|
double y;
|
|
Person person;
|
|
};
|
|
|
|
int main() {
|
|
const Config<ExampleConfig> cfg;
|
|
cfg.save();
|
|
cfg.save_schema(".");
|
|
|
|
Config<AppConfig> loaded;
|
|
loaded.save_schema(".");
|
|
loaded.load("config_example.toml");
|
|
std::println("{}", loaded);
|
|
} |