diff --git a/src/libYARP_robotinterface/src/yarp/robotinterface/impl/XMLReaderFileV3.cpp b/src/libYARP_robotinterface/src/yarp/robotinterface/impl/XMLReaderFileV3.cpp index bc140781484..6938f326338 100644 --- a/src/libYARP_robotinterface/src/yarp/robotinterface/impl/XMLReaderFileV3.cpp +++ b/src/libYARP_robotinterface/src/yarp/robotinterface/impl/XMLReaderFileV3.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #define SYNTAX_ERROR(line) yError() << "Syntax error while loading" << curr_filename << "at line" << line << "." #define SYNTAX_WARNING(line) yWarning() << "Invalid syntax while loading" << curr_filename << "at line" << line << "." @@ -56,7 +57,7 @@ class yarp::robotinterface::impl::XMLReaderFileV3::Private yarp::robotinterface::Action readActionTag(TiXmlElement* actionElem, yarp::robotinterface::XMLReaderResult& result); yarp::robotinterface::ActionList readActionsTag(TiXmlElement* actionsElem, yarp::robotinterface::XMLReaderResult& result); - bool Check_include_section_is_enabled(const std::string& href_enable_tags, const std::string& href_disable_tags); + bool CheckIfIncludeSectionIsEnabled(const std::string& href_enable_tags, const std::string& href_disable_tags); bool PerformInclusions(TiXmlNode* pParent, const std::string& parent_fileName, const std::string& current_path); void ReplaceAllStrings(std::string& str, const std::string& from, const std::string& to); XMLReaderFileV3* const parent; @@ -70,8 +71,10 @@ class yarp::robotinterface::impl::XMLReaderFileV3::Private std::string curr_filename; unsigned int minorVersion; unsigned int majorVersion; - yarp::os::Bottle b_enabled_options; - yarp::os::Bottle b_disabled_options; + std::set m_enabled_options_from_command_line; + std::set m_disabled_options_from_command_line; + std::set m_enable_set_found_in_all_xml; + std::set m_disable_set_found_in_all_xml; }; @@ -132,15 +135,51 @@ yarp::robotinterface::XMLReaderResult yarp::robotinterface::impl::XMLReaderFileV log_filename = current_filename.substr(0, current_filename.find(".xml")); log_filename += "_preprocessor_log.xml"; - yarp::os::Bottle* enable_tags = config.find("enable_tags").asList(); - yarp::os::Bottle* disable_tags = config.find("disable_tags").asList(); - if (enable_tags) b_enabled_options = *enable_tags; - if (disable_tags) b_disabled_options = *disable_tags; + std::string enable_tags_string; + yarp::os::Bottle* be = config.find("enable_tags").asList(); + if (be) { enable_tags_string = be->toString();} + + std::string disable_tags_string; + yarp::os::Bottle* bd = config.find("disable_tags").asList(); + if (bd) { disable_tags_string = bd->toString();} + + { + char* all_string = strdup(enable_tags_string.c_str()); + char* token = strtok(all_string, " "); + while (token) { + m_enabled_options_from_command_line.insert(token); + token = strtok(NULL, " "); + } + } + { + char* all_string = strdup(disable_tags_string.c_str()); + char* token = strtok(all_string, " "); + while (token) { + m_disabled_options_from_command_line.insert(token); + token = strtok(NULL, " "); + } + } + yInfo() << "Yarprobotinterface was started using the following enable_tags:"<< enable_tags_string; + yInfo() << "Yarprobotinterface was started using the following disable_tags:" << disable_tags_string; double start_time = yarp::os::Time::now(); PerformInclusions(doc->RootElement(), current_filename, current_path); double end_time = yarp::os::Time::now(); + std::string all_enable_att_string = "List of all enable attributes found in the include tags: "; + for (auto it = m_enable_set_found_in_all_xml.begin(); it != m_enable_set_found_in_all_xml.end(); it++) + { + all_enable_att_string += (" " + *it); + } + yDebug() << all_enable_att_string; + + std::string all_disable_att_string = "List of all disable attributes found in the include tags: "; + for (auto it = m_disable_set_found_in_all_xml.begin(); it != m_disable_set_found_in_all_xml.end(); it++) + { + all_disable_att_string += (" " + *it); + } + yDebug() << all_disable_att_string; + std::string full_log_withpath = current_path + std::string("\\") + log_filename; std::replace(full_log_withpath.begin(), full_log_withpath.end(), '\\', '/'); yDebug() << "Preprocessor complete in: " << end_time - start_time << "s"; @@ -178,26 +217,29 @@ yarp::robotinterface::XMLReaderResult yarp::robotinterface::impl::XMLReaderFileV return result; } -bool yarp::robotinterface::impl::XMLReaderFileV3::Private::Check_include_section_is_enabled(const std::string& href_enable_tags, const std::string& href_disable_tags) +bool yarp::robotinterface::impl::XMLReaderFileV3::Private::CheckIfIncludeSectionIsEnabled(const std::string& hrefxml_enable_tags_s, const std::string& hrefxml_disable_tags_s) { - yarp::os::Bottle b_included_enable_options; - b_included_enable_options.fromString(href_enable_tags); - yarp::os::Bottle b_included_disable_options; - b_included_disable_options.fromString(href_disable_tags); + yarp::os::Bottle hrefxml_enable_tags_b; + hrefxml_enable_tags_b.fromString(hrefxml_enable_tags_s); + yarp::os::Bottle hrefxml_disable_tags_b; + hrefxml_disable_tags_b.fromString(hrefxml_disable_tags_s); //yDebug() << "included enable tag size:" << b_included_enable_options.size() << " contents:" << b_included_enable_options.toString(); //yDebug() << "included disable tag size:" << b_included_disable_options.size() << " contents:" << b_included_disable_options.toString(); //if no `enabled_by` attribute are found in the xi::include line, then the include is enabled by default. bool enabled = true; - if (b_included_enable_options.size() != 0) + size_t hrefxml_enable_tags_b_size = hrefxml_enable_tags_b.size(); + if (hrefxml_enable_tags_b_size != 0) { //.otherwise, if a `enabled_by` attribute is found, then the include line is not enabled by default and it // is enabled only if yarprobotinterface has been executed with the specific option --enable_tags enabled = false; - for (size_t i = 0; i < b_included_enable_options.size(); i++) + for (size_t i = 0; i < hrefxml_enable_tags_b_size; i++) { - std::string s = b_included_enable_options.get(i).asString(); - if (b_enabled_options.check(s) || b_enabled_options.check("enable_all")) + std::string s = hrefxml_enable_tags_b.get(i).asString(); + m_enable_set_found_in_all_xml.insert(s); + if (m_enabled_options_from_command_line.find(s) != m_enabled_options_from_command_line.end() || + m_enabled_options_from_command_line.find("enable_all") != m_enabled_options_from_command_line.end()) { enabled = true; } @@ -205,14 +247,17 @@ bool yarp::robotinterface::impl::XMLReaderFileV3::Private::Check_include_section } // if a `disabled_by` attribute is found, then the include line (either enabled by default or by an `enable_by` tag ) can // be disabled if yarprobotinterface has been executed with the specific option --disable_tags - for (size_t i = 0; i < b_included_disable_options.size(); i++) + size_t hrefxml_disable_tags_b_size = hrefxml_disable_tags_b.size(); + for (size_t i = 0; i < hrefxml_disable_tags_b_size; i++) { - std::string s = b_included_disable_options.get(i).asString(); - if (b_disabled_options.check(s)) + std::string s = hrefxml_disable_tags_b.get(i).asString(); + m_disable_set_found_in_all_xml.insert(s); + if (m_disabled_options_from_command_line.find(s) != m_disabled_options_from_command_line.end()) { enabled = false; } } + return enabled; } @@ -240,7 +285,7 @@ bool yarp::robotinterface::impl::XMLReaderFileV3::Private::PerformInclusions(TiX std::string href_enable_tags, href_disable_tags; childElem->QueryStringAttribute("enabled_by", &href_enable_tags); childElem->QueryStringAttribute("disabled_by", &href_disable_tags); - if (Check_include_section_is_enabled(href_enable_tags, href_disable_tags)) + if (CheckIfIncludeSectionIsEnabled(href_enable_tags, href_disable_tags)) { std::string included_path = std::string(current_path).append("\\").append(href_filename.substr(0, href_filename.find_last_of("\\/"))); std::string included_filename = href_filename.substr(href_filename.find_last_of("\\/") + 1);