Skip to content
Snippets Groups Projects
Commit 13ad32b9 authored by Joaquim Casals Buñuel's avatar Joaquim Casals Buñuel
Browse files

Clean up Parser YAML

parent 6457bfef
No related branches found
No related tags found
No related merge requests found
Pipeline #4685 passed
...@@ -193,7 +193,6 @@ class ParserYAML { ...@@ -193,7 +193,6 @@ class ParserYAML {
std::vector<ParamsInitProcessor> _paramsProc; std::vector<ParamsInitProcessor> _paramsProc;
std::stack<std::string> _parsing_file; std::stack<std::string> _parsing_file;
std::string _file; std::string _file;
bool _relative_path;
std::string _path_root; std::string _path_root;
std::vector<SubscriberManager> _subscriber_managers; std::vector<SubscriberManager> _subscriber_managers;
YAML::Node problem; YAML::Node problem;
...@@ -201,11 +200,7 @@ class ParserYAML { ...@@ -201,11 +200,7 @@ class ParserYAML {
YAML::Node loadYAML(std::string); YAML::Node loadYAML(std::string);
void insert_register(std::string, std::string); void insert_register(std::string, std::string);
public: public:
ParserYAML(bool freely_parse = false): ParserYAML("", "", freely_parse){ ParserYAML(std::string file, std::string path_root = "",
}
ParserYAML(std::string file, bool freely_parse = false)
: ParserYAML(file, "", freely_parse) {}
ParserYAML(std::string file, std::string path_root,
bool freely_parse = false) { bool freely_parse = false) {
_params = std::map<std::string, std::string>(); _params = std::map<std::string, std::string>();
_active_name = ""; _active_name = "";
...@@ -215,19 +210,17 @@ public: ...@@ -215,19 +210,17 @@ public:
_parsing_file = std::stack<std::string>(); _parsing_file = std::stack<std::string>();
_file = file; _file = file;
if (path_root != "") { if (path_root != "") {
std::regex r("/$"); std::regex r(".*/ *$");
if (not std::regex_match(path_root, r)) if (not std::regex_match(path_root, r))
_path_root = path_root + "/"; _path_root = path_root + "/";
else else
_path_root = path_root; _path_root = path_root;
_relative_path = true;
} else {
_relative_path = false;
} }
if(not freely_parse) this->parse(); if(not freely_parse) this->parse();
else this->parse_freely(); else this->parse_freely();
} }
~ParserYAML(){ ~ParserYAML()
{
// //
} }
void parse_freely(); void parse_freely();
...@@ -243,12 +236,12 @@ public: ...@@ -243,12 +236,12 @@ public:
std::string tagsToString(std::vector<std::string>& tags); std::string tagsToString(std::vector<std::string>& tags);
void parse(); void parse();
}; };
std::string ParserYAML::generatePath(std::string path){ std::string ParserYAML::generatePath(std::string file){
std::regex r("^/.*"); std::regex r("^/.*");
if(std::regex_match(path, r)){ if(std::regex_match(file, r)){
return path; return file;
}else{ }else{
return _path_root + path; return _path_root + file;
} }
} }
YAML::Node ParserYAML::loadYAML(std::string file){ YAML::Node ParserYAML::loadYAML(std::string file){
...@@ -472,11 +465,10 @@ void ParserYAML::parse(){ ...@@ -472,11 +465,10 @@ void ParserYAML::parse(){
if (n.Type() == YAML::NodeType::Map) if (n.Type() == YAML::NodeType::Map)
{ {
WOLF_INFO("HELLO");
for (auto it : n) for (auto it : n)
{ {
auto node = it.second; auto node = it.second;
WOLF_INFO("WUT ", it.first); // WOLF_INFO("WUT ", it.first);
std::vector<std::string> tags = std::vector<std::string>(); std::vector<std::string> tags = std::vector<std::string>();
if(it.first.as<std::string>() != "config") if(it.first.as<std::string>() != "config")
this->walkTreeR(node, tags, it.first.as<std::string>()); this->walkTreeR(node, tags, it.first.as<std::string>());
...@@ -485,7 +477,7 @@ void ParserYAML::parse(){ ...@@ -485,7 +477,7 @@ void ParserYAML::parse(){
for (auto itt : node) for (auto itt : node)
{ {
std::string node_key = itt.first.as<std::string>(); std::string node_key = itt.first.as<std::string>();
WOLF_INFO("node_key ", node_key); // WOLF_INFO("node_key ", node_key);
if (node_key != "problem" and node_key != "sensors" and node_key != "processors" and if (node_key != "problem" and node_key != "sensors" and node_key != "processors" and
node_key != "ROS subscriber managers") node_key != "ROS subscriber managers")
{ {
...@@ -496,7 +488,6 @@ void ParserYAML::parse(){ ...@@ -496,7 +488,6 @@ void ParserYAML::parse(){
} }
}else }else
{ {
WOLF_INFO("GETTING HERE?");
std::vector<std::string> tags = std::vector<std::string>(); std::vector<std::string> tags = std::vector<std::string>();
this->walkTreeR(n, tags, ""); this->walkTreeR(n, tags, "");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment