salsa 0.7.1
Loading...
Searching...
No Matches
Config.cc
1#include <iostream>
2#include "Config.hh"
3namespace Salsa {
16
17bool Config::load(std::string file)
18{
22
23 mConfig = YAML::LoadFile(file);
24 return true;
25}
26
27void 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
61void Config::print() const
62{
66 std::cout << mConfig << std::endl;
67}
68
69void 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
void filter(std::string const &f)
Definition Config.cc:27
virtual void print() const
Definition Config.cc:61
std::map< std::string, YAML::Node > mFilter
Filter list.
Definition Config.hh:31
void findAndReplaceAll(std::string &data, std::string toSearch, std::string replaceStr)
Definition Config.cc:69
YAML::Node mConfig
YAML Configuration.
Definition Config.hh:30
virtual bool load(std::string file)
Definition Config.cc:17
virtual ~Config()
Definition Config.cc:10
Base Salsa Object class.
Definition Object.hh:15