salsa  0.4.0
 All Classes Functions Variables Typedefs Enumerations Pages
Config.cc
1 #include <iostream>
2 #include "Config.hh"
3 namespace Salsa {
5 {
9 }
11 {
15 }
16 
17 bool Config::load(std::string file)
18 {
22 
23  mConfig = YAML::LoadFile(file);
24  return true;
25 }
26 
27 void Config::filter(std::string const & filter)
28 {
32  std::stringstream filterSS{filter};
33  std::string netName;
34 
35  while (std::getline(filterSS, netName, '+')) {
36  if (!netName.empty()) {
37 
38  size_t pos = netName.find('{'); // Find semicolon, if any
39  std::string name = netName.substr(0, pos); // Substring name
40  std::string opt;
41  if (pos != std::string::npos) {
42  opt = netName.substr(pos, netName.size()); // Substring opt
43 
44  // replase ":" with ": "
45  findAndReplaceAll(opt, ":", ": ");
46  }
47 
48  if (opt.empty()) {
49  YAML::Node n;
50  mFilter.insert(std::pair<std::string, YAML::Node>(std::move(name), n));
51  }
52  else {
53  mFilter.insert(std::pair<std::string, YAML::Node>(std::move(name), YAML::Load(opt)));
54  }
55 
56  // mFilter.push_back(std::move(s));
57  }
58  }
59 }
60 
61 void Config::print() const
62 {
66  std::cout << mConfig << std::endl;
67 }
68 
69 void Config::findAndReplaceAll(std::string & data, std::string toSearch, std::string replaceStr)
70 {
74 
75  // Get the first occurrence
76  size_t pos = data.find(toSearch);
77 
78  // Repeat till end is reached
79  while (pos != std::string::npos) {
80  // Replace this occurrence of Sub String
81  data.replace(pos, toSearch.size(), replaceStr);
82  // Get the next occurrence from the current position
83  pos = data.find(toSearch, pos + replaceStr.size());
84  }
85 }
86 
87 } // namespace Salsa
std::map< std::string, YAML::Node > mFilter
Filter list.
Definition: Config.hh:31
virtual bool load(std::string file)
Definition: Config.cc:17
void filter(std::string const &f)
Definition: Config.cc:27
virtual void print() const
Definition: Config.cc:61
Base Salsa Object class.
Definition: Object.hh:15
YAML::Node mConfig
YAML Configuration.
Definition: Config.hh:30
void findAndReplaceAll(std::string &data, std::string toSearch, std::string replaceStr)
Definition: Config.cc:69
virtual ~Config()
Definition: Config.cc:10