ndm  0.1.2
Config.cc
1 #include "Config.hh"
2 #include "Space.hh"
3 #include <iostream>
4 namespace NDM {
6 {
10 }
12 {
16 }
17 
18 bool 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["info"]) a.info(ax["info"].as<std::string>());
67  mSpace->add(a);
68  mLevels.push_back(ax["level"].as<int>());
69  }
70 
71  return true;
72 }
73 
74 void Config::print() const
75 {
79  std::cout << mConfig << std::endl;
80 }
81 
82 } // namespace NDM
void add(NDM::Axis a)
Definition: Space.cc:31
void info(std::string i)
Sets info string.
Definition: Axis.hh:48
std::vector< std::string > mEnvs
List of env variables.
Definition: Config.hh:38
Space * mSpace
Space object.
Definition: Config.hh:36
Axis object in n-dimensional space.
Definition: Axis.hh:12
virtual ~Config()
Definition: Config.cc:11
Config()
Definition: Config.cc:5
YAML::Node mConfig
YAML Configuration.
Definition: Config.hh:35
Space object in n-dimensional space.
Definition: Space.hh:17
virtual bool load(std::string file)
Definition: Config.cc:18
std::vector< int > mLevels
Levels for each axis.
Definition: Config.hh:37
virtual void print() const
Definition: Config.cc:74