From f047d2ad23fb64078a803547c565c82da384b897 Mon Sep 17 00:00:00 2001 From: Alejandro Hernandez Cordero Date: Fri, 13 Mar 2026 17:52:29 +0100 Subject: [PATCH] Fix some minor issues Signed-off-by: Alejandro Hernandez Cordero --- pluginlib/include/pluginlib/class_loader.hpp | 3 +- .../include/pluginlib/class_loader_base.hpp | 2 +- .../include/pluginlib/class_loader_imp.hpp | 35 ++++++++----------- pluginlib/src/list_plugins.cpp | 2 +- pluginlib/test/unique_ptr_test.cpp | 2 +- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/pluginlib/include/pluginlib/class_loader.hpp b/pluginlib/include/pluginlib/class_loader.hpp index 2cba481..3b564dc 100644 --- a/pluginlib/include/pluginlib/class_loader.hpp +++ b/pluginlib/include/pluginlib/class_loader.hpp @@ -54,11 +54,10 @@ class ClassLoader : public ClassLoaderBase public: typedef typename std::map::iterator ClassMapIterator; -public: /** * \param package The package containing the base class * \param base_class The type of the base class for classes to be loaded - * \param attrib_name The attribute to search for in manifext.xml files, defaults to "plugin" + * \param attrib_name The attribute to search for in manifest.xml files, defaults to "plugin" * \param plugin_xml_paths The list of paths of plugin.xml files, defaults to be crawled via * ros::package::getPlugins() * \throws pluginlib::ClassLoaderException if package manifest cannot be found diff --git a/pluginlib/include/pluginlib/class_loader_base.hpp b/pluginlib/include/pluginlib/class_loader_base.hpp index 8daa577..21e2f14 100644 --- a/pluginlib/include/pluginlib/class_loader_base.hpp +++ b/pluginlib/include/pluginlib/class_loader_base.hpp @@ -29,8 +29,8 @@ #ifndef PLUGINLIB__CLASS_LOADER_BASE_HPP_ #define PLUGINLIB__CLASS_LOADER_BASE_HPP_ -#include #include +#include namespace pluginlib { diff --git a/pluginlib/include/pluginlib/class_loader_imp.hpp b/pluginlib/include/pluginlib/class_loader_imp.hpp index ff31354..52c579e 100644 --- a/pluginlib/include/pluginlib/class_loader_imp.hpp +++ b/pluginlib/include/pluginlib/class_loader_imp.hpp @@ -42,7 +42,6 @@ #include #include "ament_index_cpp/get_package_prefix.hpp" -#include "ament_index_cpp/get_package_share_directory.hpp" #include "ament_index_cpp/get_resource.hpp" #include "ament_index_cpp/get_resources.hpp" #include "class_loader/interface_traits.hpp" @@ -52,12 +51,6 @@ #include "./class_loader.hpp" -#ifdef _WIN32 -#define CLASS_LOADER_IMPL_OS_PATHSEP ";" -#else -#define CLASS_LOADER_IMPL_OS_PATHSEP ":" -#endif - namespace pluginlib { @@ -93,7 +86,7 @@ ClassLoader::ClassLoader( } classes_available_ = determineAvailableClasses(plugin_xml_paths_); RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", - "Finished constructring ClassLoader, base = %s, address = %p", + "Finished constructing ClassLoader, base = %s, address = %p", base_class.c_str(), static_cast(this)); } @@ -166,7 +159,7 @@ T * ClassLoader::createUnmanagedInstance(const std::string & lookup_name, Arg loadLibraryForClass(lookup_name); } - T * instance = 0; + T * instance = nullptr; try { RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", "Attempting to create instance through low level multi-library class loader."); @@ -269,7 +262,7 @@ std::string ClassLoader::extractPackageNameFromPackageXML(const std::string & tinyxml2::XMLDocument document; document.LoadFile(package_xml_path.c_str()); tinyxml2::XMLElement * doc_root_node = document.FirstChildElement("package"); - if (NULL == doc_root_node) { + if (nullptr == doc_root_node) { RCUTILS_LOG_ERROR_NAMED("pluginlib.ClassLoader", "Could not find a root element for package manifest at %s.", package_xml_path.c_str()); @@ -279,7 +272,7 @@ std::string ClassLoader::extractPackageNameFromPackageXML(const std::string & assert(document.RootElement() == doc_root_node); tinyxml2::XMLElement * package_name_node = doc_root_node->FirstChildElement("name"); - if (NULL == package_name_node) { + if (nullptr == package_name_node) { RCUTILS_LOG_ERROR_NAMED("pluginlib.ClassLoader", "package.xml at %s does not have a tag! Cannot determine package " "which exports plugin.", @@ -288,7 +281,7 @@ std::string ClassLoader::extractPackageNameFromPackageXML(const std::string & } const char * package_name_node_txt = package_name_node->GetText(); - if (NULL == package_name_node_txt) { + if (nullptr == package_name_node_txt) { RCUTILS_LOG_ERROR_NAMED("pluginlib.ClassLoader", "package.xml at %s has an invalid tag! Cannot determine package " "which exports plugin.", @@ -436,13 +429,13 @@ template std::string ClassLoader::getClassLibraryPath(const std::string & lookup_name) /***************************************************************************/ { - if (classes_available_.find(lookup_name) == classes_available_.end()) { + ClassMapIterator it = classes_available_.find(lookup_name); + if (it == classes_available_.end()) { std::ostringstream error_msg; error_msg << "Could not find library corresponding to plugin " << lookup_name << ". Make sure the plugin description XML file has the correct name of the library."; throw pluginlib::LibraryLoadException(error_msg.str()); } - ClassMapIterator it = classes_available_.find(lookup_name); std::string library_name = it->second.library_name_; RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", "Class %s maps to library %s in classes_available_.", @@ -653,14 +646,14 @@ void ClassLoader::processSingleXMLPluginFile( tinyxml2::XMLDocument document; document.LoadFile(xml_file.c_str()); tinyxml2::XMLElement * config = document.RootElement(); - if (NULL == config) { + if (nullptr == config) { throw pluginlib::InvalidXMLException( "XML Document '" + xml_file + "' has no Root Element. This likely means the XML is malformed or missing."); return; } const char * config_value = config->Value(); - if (NULL == config_value) { + if (nullptr == config_value) { throw pluginlib::InvalidXMLException( "XML Document '" + xml_file + "' has an invalid Root Element. This likely means the XML is malformed or missing."); @@ -680,9 +673,9 @@ void ClassLoader::processSingleXMLPluginFile( } tinyxml2::XMLElement * library = config; - while (library != NULL) { + while (library != nullptr) { const char * path = library->Attribute("path"); - if (NULL == path) { + if (nullptr == path) { RCUTILS_LOG_ERROR_NAMED("pluginlib.ClassLoader", "Attribute 'path' in 'library' tag is missing in %s.", xml_file.c_str()); continue; @@ -706,7 +699,7 @@ void ClassLoader::processSingleXMLPluginFile( tinyxml2::XMLElement * class_element = library->FirstChildElement("class"); while (class_element) { std::string derived_class; - if (class_element->Attribute("type") != NULL) { + if (class_element->Attribute("type") != nullptr) { derived_class = std::string(class_element->Attribute("type")); } else { throw pluginlib::ClassLoaderException( @@ -714,7 +707,7 @@ void ClassLoader::processSingleXMLPluginFile( } std::string base_class_type; - if (class_element->Attribute("base_class_type") != NULL) { + if (class_element->Attribute("base_class_type") != nullptr) { base_class_type = std::string(class_element->Attribute("base_class_type")); } else { throw pluginlib::ClassLoaderException( @@ -722,7 +715,7 @@ void ClassLoader::processSingleXMLPluginFile( } std::string lookup_name; - if (class_element->Attribute("name") != NULL) { + if (class_element->Attribute("name") != nullptr) { lookup_name = class_element->Attribute("name"); RCUTILS_LOG_DEBUG_NAMED("pluginlib.ClassLoader", "XML file specifies lookup name (i.e. magic name) = %s.", diff --git a/pluginlib/src/list_plugins.cpp b/pluginlib/src/list_plugins.cpp index 684a405..7e5584b 100644 --- a/pluginlib/src/list_plugins.cpp +++ b/pluginlib/src/list_plugins.cpp @@ -10,7 +10,7 @@ // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // -// * Neither the name of the Willow Garage nor the names of its +// * Neither the name of the Metro Robots nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // diff --git a/pluginlib/test/unique_ptr_test.cpp b/pluginlib/test/unique_ptr_test.cpp index eb8ec4d..81f7eab 100644 --- a/pluginlib/test/unique_ptr_test.cpp +++ b/pluginlib/test/unique_ptr_test.cpp @@ -45,7 +45,7 @@ TEST(PluginlibUniquePtrTest, misspelledPlugin) { "test_pluginlib/foo"), pluginlib::LibraryLoadException); } -TEST(PluginlibTest, brokenPlugin) { +TEST(PluginlibUniquePtrTest, brokenPlugin) { pluginlib::ClassLoader test_loader("test_pluginlib", "test_base::Fubar"); ASSERT_THROW( test_loader.createUniqueInstance("test_pluginlib/none"), pluginlib::PluginlibException);