Skip to content
Snippets Groups Projects

WIP: Resolve "Processor constructors and creators requiring a sensor pointer?"

2 files
+ 28
10
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -186,6 +186,7 @@ class ParserYAML {
std::vector<std::array<std::string, 3>> _callbacks;
YAML::Node problem;
std::string generatePath(std::string);
YAML::Node loadYAML(std::string);
public:
ParserYAML(){
_params = std::map<std::string, std::string>();
@@ -252,6 +253,13 @@ std::string ParserYAML::generatePath(std::string path){
return _path_root + path;
}
}
YAML::Node ParserYAML::loadYAML(std::string file){
try{
return YAML::LoadFile(generatePath(file));
}catch (YAML::BadFile& e){
throw std::runtime_error("Couldn't load file " + generatePath(file));
}
}
std::string ParserYAML::tagsToString(std::vector<std::string> &tags){
std::string hdr = "";
for(auto it : tags){
@@ -262,20 +270,20 @@ std::string ParserYAML::tagsToString(std::vector<std::string> &tags){
void ParserYAML::walkTree(std::string file){
YAML::Node n;
std::cout << "Parsing " << generatePath(file) << std::endl;
n = YAML::LoadFile(generatePath(file));
n = loadYAML(generatePath(file));
std::vector<std::string> hdrs = std::vector<std::string>();
walkTreeR(n, hdrs, "");
}
void ParserYAML::walkTree(std::string file, std::vector<std::string>& tags){
YAML::Node n;
std::cout << "Parsing " << generatePath(file) << std::endl;
n = YAML::LoadFile(generatePath(file));
n = loadYAML(generatePath(file));
walkTreeR(n, tags, "");
}
void ParserYAML::walkTree(std::string file, std::vector<std::string>& tags, std::string hdr){
YAML::Node n;
std::cout << "Parsing " << generatePath(file) << std::endl;
n = YAML::LoadFile(generatePath(file));
n = loadYAML(generatePath(file));
walkTreeR(n, tags, hdr);
}
/** @Brief Recursively walks the YAML tree while filling a map with the values parsed from the file
@@ -365,18 +373,28 @@ void ParserYAML::updateActiveName(std::string tag){
void ParserYAML::parseFirstLevel(std::string file){
YAML::Node n;
std::cout << "Parsing " << generatePath(file) << std::endl;
n = YAML::LoadFile(generatePath(file));
n = loadYAML(generatePath(file));
YAML::Node n_config = n["config"];
assert(n_config.Type() == YAML::NodeType::Map && "trying to parse config node but found a non-Map node");
// assert(n_config.Type() == YAML::NodeType::Map && "trying to parse config node but found a non-Map node");
if(n_config.Type() != YAML::NodeType::Map) throw std::runtime_error("Could not find config node. Please make sure that your YAML file " + generatePath(file) + " starts with 'config:'");
if(n_config["problem"].Type() != YAML::NodeType::Map) throw std::runtime_error("Could not find problem node. Please make sure that the 'config' node in YAML file " + generatePath(file) + " has a 'problem' entry");
this->problem = n_config["problem"];
for(const auto& kv : n_config["sensors"]){
try{
for(const auto& kv : n_config["sensors"]){
ParamsInitSensor pSensor = {kv["type"].Scalar(), kv["name"].Scalar(), kv};
_paramsSens.push_back(pSensor);
}
} catch(YAML::InvalidNode& e){
throw std::runtime_error("Error parsing sensors. Please make sure that each sensor entry has 'type' and 'name' entries.");
}
for(const auto& kv : n_config["processors"]){
try{
for(const auto& kv : n_config["processors"]){
ParamsInitProcessor pProc = {kv["type"].Scalar(), kv["name"].Scalar(), kv["sensor_name"].Scalar(), kv};
_paramsProc.push_back(pProc);
}
} catch(YAML::InvalidNode& e){
throw std::runtime_error("Error parsing processors. Please make sure that each processor has 'type', 'name' and 'sensor_name' entries.");
}
for(const auto& kv : n_config["callbacks"]){
_callbacks.push_back({{kv[0].as<std::string>(), kv[1].as<std::string>(), kv[2].as<std::string>()}});
Loading