Skip to content
Snippets Groups Projects
Commit ba56bc9c authored by Oliver Charles Schubert's avatar Oliver Charles Schubert
Browse files

Adds extractNodesFromPtree() to search a ptree for specific nodes.

parent 77169dd4
Branches
No related tags found
No related merge requests found
......@@ -3,9 +3,9 @@
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
void printNodeNames(const boost::property_tree::ptree& tree, const std::string& indent = "") {
void printNodeNames(const boost::property_tree::ptree& myPtree, const std::string& indent = "") {
// Iterate through each child node of the given tree
for (const auto& node : tree) {
for (const auto& node : myPtree) {
// Print the node's name
std::cout << indent << node.first;
......@@ -23,14 +23,28 @@ void printNodeNames(const boost::property_tree::ptree& tree, const std::string&
}
}
int containsSymbol(const std::string& myString, const std::string& mySymbol) {
if (myString.find(mySymbol) != std::string::npos) {
int containsSymbol(const std::string& my_string, const std::string& my_symbol) {
if (my_string.find(my_symbol) != std::string::npos) {
return 1;
} else {
return 0;
}
}
boost::property_tree::ptree extractNodesFromPtree(const boost::property_tree::ptree& ptree, const std::string& target_node) {
boost::property_tree::ptree reduced_ptree{};
for (const auto& parent_node : ptree) {
if (parent_node.first == target_node) {
reduced_ptree.add_child(parent_node.first, parent_node.second);
}
boost::property_tree::ptree myPtree{};
myPtree = extractNodesFromPtree(parent_node.second, target_node);
}
return reduced_ptree;
}
enum State {
DefiningFilePaths,
LoadingXMLsIntoTrees,
......@@ -119,16 +133,17 @@ int main () {
std::cout << "Current State: " << state << std::endl;
// Iterate through the children of <ConfigFile.ProgramSettings.Parameters>
for (const boost::property_tree::ptree::value_type& parent_nodes : config_tree.get_child("ConfigFile.ProgramSettings.Parameters")) {
boost::property_tree::ptree temporary_tree{};
// Iterate through the children of parent_node
for (const auto &child_nodes : parent_nodes.second) {
if (child_nodes.first == "SubPath") {
temporary_tree.add_child(child_nodes.first, child_nodes.second);
}
}
reduced_config_tree.add_child(parent_nodes.first, temporary_tree);
}
// for (const boost::property_tree::ptree::value_type& parent_nodes : config_tree.get_child("ConfigFile.ProgramSettings.Parameters")) {
// boost::property_tree::ptree temporary_tree{};
// // Iterate through the children of parent_node
// for (const auto &child_nodes : parent_nodes.second) {
// if (child_nodes.first == "SubPath") {
// temporary_tree.add_child(child_nodes.first, child_nodes.second);
// }
// }
// reduced_config_tree.add_child(parent_nodes.first, temporary_tree);
// }
reduced_config_tree = extractNodesFromPtree(config_tree, "SubPath");
// printNodeNames(reduced_config_tree);
state = State::SubstractingNodeValues;
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment