diff --git a/DesignEvaluator/src/main.cpp b/DesignEvaluator/src/main.cpp index ff8410f9b5e7ff656b8caa75807bf96182492407..d0b6edf0d17c9b75844b5730bbb36ebe1492f93e 100644 --- a/DesignEvaluator/src/main.cpp +++ b/DesignEvaluator/src/main.cpp @@ -48,6 +48,41 @@ boost::property_tree::ptree extractNodesFromPtree(const boost::property_tree::pt return reduced_ptree; } +boost::property_tree::ptree GetSubtreeByAttributevalue(const boost::property_tree::ptree& ptree, + const std::string& node_path, + const std::string& attribute_for_which_to_filter, + const std::string& attribute_value) { + boost::property_tree::ptree subtree{}; + boost::property_tree::ptree temp_tree{}; + std::string parent_path{node_path.substr(0, node_path.find_last_of('/'))}; + std::string child_name{node_path.substr(node_path.find_last_of('/')+1, node_path.length())}; + + try + { + temp_tree = ptree.get_child(boost::property_tree::ptree::path_type(parent_path, '/')); + } + catch(const std::exception& e) + { + std::cerr << "Error occured at: " << __FILE__ << ", "; + std::cerr << "in function: " << __func__ << "(), "; + std::cerr << "in line: " << __LINE__ << std::endl; + std::cerr << "Error creating xml tree: " << e.what() << std::endl; + std::cerr << "Aborting Programm!" << std::endl; + std::exit(1); + } + + for (const auto& node : temp_tree) { + bool bool1{node.first == child_name}; + bool bool2{node.second.get_optional<std::string>("<xmlattr>." + attribute_for_which_to_filter) == attribute_value}; + + if (bool1 && bool2) { + subtree = node.second; + } + } + + return subtree; +} + enum State { DefiningFilePaths, LoadingXMLsIntoTrees, @@ -136,7 +171,6 @@ int main () { std::cout << "Current State: " << state << std::endl; reduced_config_tree = extractNodesFromPtree(config_tree, "SubPath"); - printNodeNames(reduced_config_tree); state = State::SubstractingNodeValues; break; @@ -145,23 +179,31 @@ int main () { try { - // iterate over the parent nodes - for (const auto& parent_node : reduced_config_tree) { - // iterate over child nodes - for (const auto& child_node : parent_node.second) { - std::string xml_path{"AcftExchangeFile/" + parent_node.first + "/" + child_node.second.data()}; - double upstream_value{NAN}; - double local_value{NAN}; - if (containsSymbol(xml_path, "@")) - { - std::cout << "xml with '@' skipped." << std::endl; - } else { - upstream_value = upstream_tree.get<double>(boost::property_tree::ptree::path_type(xml_path, '/')); - local_value = local_tree.get<double>(boost::property_tree::ptree::path_type(xml_path, '/')); - } - result_tree.put(child_node.second.get<std::string>("<xmlattr>.Name"), upstream_value - local_value); - // std::cout << child_node.second.get<std::string>("<xmlattr>.Name") << ": " << upstream_value - local_value << std::endl; + for (const auto& node : reduced_config_tree) { + std::string node_path{"AcftExchangeFile/" + node.second.data()}; + double upstream_value{NAN}; + double local_value{NAN}; + + if (containsSymbol(node_path, "@")) + { + // "MassesAndLoadings/MassBreakdown/PowerUnit/Engine@1/EngineDry/Mass" + std::string pre{node_path.substr(0, node_path.find_first_of('@'))}; + std::string temp_string{node_path.substr(node_path.find_first_of('@'))}; + std::string attribute_value{temp_string.substr(temp_string.find_first_of('@')+1, temp_string.find_first_of('/')-1)}; + std::string post{temp_string.substr(temp_string.find_first_of('/')+1)}; + // TODO(Oli): try to fit this into own function, with multiple '@' seperations + + boost::property_tree::ptree temp_upstream_tree{GetSubtreeByAttributevalue(upstream_tree, pre, "ID", attribute_value)}; + boost::property_tree::ptree temp_local_tree{GetSubtreeByAttributevalue(local_tree, pre, "ID", attribute_value)}; + + upstream_value = temp_upstream_tree.get<double>(boost::property_tree::ptree::path_type(post, '/')); + local_value = temp_local_tree.get<double>(boost::property_tree::ptree::path_type(post, '/')); + + } else { + upstream_value = upstream_tree.get<double>(boost::property_tree::ptree::path_type(node_path, '/')); + local_value = local_tree.get<double>(boost::property_tree::ptree::path_type(node_path, '/')); } + result_tree.put(node.second.get<std::string>("<xmlattr>.Name"), upstream_value - local_value); } } catch(const std::exception& e)