ndm 0.2.8
Loading...
Searching...
No Matches
Config.cc
1#include "Config.hh"
2#include "Space.hh"
3#include <iostream>
4namespace NDM {
17
18bool Config::load(std::string file)
19{
23
24 struct stat buffer;
25 bool rc = (stat(file.c_str(), &buffer) == 0);
26 if (!rc) {
27 spdlog::error("File '{}' doesn't exists !!! ", file);
28 return false;
29 }
30
31 mConfig = YAML::LoadFile(file);
32
33 // Clearing previous state
34 if (mSpace != nullptr) delete mSpace;
35 mLevels.clear();
36
37 mEnvs.clear();
38
39 YAML::Node envsType = mConfig["envs"];
40 for (std::size_t i = 0; i < envsType.size(); i++) {
41 mEnvs.push_back(
42 fmt::format("{}={}", envsType[i]["name"].as<std::string>(), envsType[i]["value"].as<std::string>()));
43 }
44
45 mSpace = new Space();
46
47 YAML::Node axes = mConfig["space"]["axes"];
48 for (auto ax : axes) {
49 if (!ax["name"]) {
50 spdlog::warn("Name of axis was not found !!! Skipping axis ...");
51 continue;
52 }
53 if (!ax["min"]) {
54 spdlog::warn("Min value in axis was not found !!! Skipping axis [{}] ...", ax["name"].as<std::string>());
55 continue;
56 }
57 if (!ax["max"]) {
58 spdlog::warn("Max value in axis was not found !!! Skipping axis [{}] ...", ax["name"].as<std::string>());
59 continue;
60 }
61 if (!ax["level"]) {
62 spdlog::warn("Level value in axis was not found !!! Skipping axis [{}] ...", ax["name"].as<std::string>());
63 continue;
64 }
65 NDM::Axis a(ax["min"].as<double>(), ax["max"].as<double>());
66 if (ax["isbin"]) a.is_bin(ax["isbin"].as<bool>());
67 if (ax["info"]) a.info(ax["info"].as<std::string>());
68 mSpace->add(a);
69 mLevels.push_back(ax["level"].as<int>());
70 }
71
72 return true;
73}
74
75void Config::print() const
76{
80 std::cout << mConfig << std::endl;
81}
82
83} // namespace NDM
Axis object in n-dimensional space.
Definition Axis.hh:12
void is_bin(bool b)
Sets user defined maximum.
Definition Axis.hh:34
void info(std::string i)
Sets info string.
Definition Axis.hh:52
std::vector< int > mLevels
Levels for each axis.
Definition Config.hh:37
std::vector< std::string > mEnvs
List of env variables.
Definition Config.hh:38
virtual ~Config()
Definition Config.cc:11
YAML::Node mConfig
YAML Configuration.
Definition Config.hh:35
virtual bool load(std::string file)
Definition Config.cc:18
virtual void print() const
Definition Config.cc:75
Space * mSpace
Space object.
Definition Config.hh:36
Space object in n-dimensional space.
Definition Space.hh:17
void add(NDM::Axis a)
Definition Space.cc:31