Template Class PluginClassLoader

Inheritance Relationships

Base Type

  • public pluginlib::ClassLoader< BaseT >

Class Documentation

template<typename BaseT>
class PluginClassLoader : public pluginlib::ClassLoader<BaseT>

Class for loading plugin resources registered according to the conventions defined by the pluginlib package.

For a class to be discoverable, you must call the C++ macro PLUGINLIB_EXPORT_CLASS and provide the arguments according to your definitions. AutoAPMS provides convenient wrappers that encapsulate this macro.

You must also make sure, that you create a plugins.xml file, add the corresponding entries and export it in the CMakeLists.txt of your ROS 2 package. Again, AutoAPMS provides convenient wrapper macros for specific use cases.

If you did all the above and want to instantiate a plugin class, you must call e.g. createSharedInstance and provide a lookup name for the plugin formatted like this:

  • <namespace>::<class_name>

Token Name

Description

<namespace>

Full C++ namespace that the class <class_name> can be found in. It can be flat foo or arbitrarily nested foo::bar (individual levels must be separated by ::).

<class_name>

Name you specified when registering the plugin class using the class keyword in C++. If the class takes template arguments, you must provide it using the MyClass<T> syntax as you would in the source code.

Template Parameters:

BaseT – Base class of the plugin.

Public Functions

inline PluginClassLoader(const std::string &base_package, const std::string &base_class, const std::set<std::string> &exclude_packages = {})

Standard PluginClassLoader constructor.

Alternatively, if you want to verify that only unique class names are loaded, have a look at PluginClassLoader::makeUnambiguousPluginClassLoader.

Parameters:
  • base_package – Name of the package containing the base_class. Will throw an error if it is not installed.

  • base_class – Fully qualified name of the base class that the class loader will use for determining which classes listed in a plugins.xml file are associated with this instance.

  • exclude_packages – Packages to exclude when searching for plugins.

Throws:
  • ament_index_cpp::PackageNotFoundError – if base_package is not installed.

  • auto_apms_util::exceptions::ResourceError – if no plugins of type base_class were found.

inline std::map<std::string, std::string> getClassPackageMap()

Retrieve a map that contains information about which package a plugin class belongs to.

Returns:

Mapping according to {class_name: package_name}.

Public Static Functions

static inline PluginClassLoader makeUnambiguousPluginClassLoader(const std::string &base_package, const std::string &base_class, const std::set<std::string> &exclude_packages = {}, const std::map<std::string, std::string> &reserved_names = {})

Parse all associated plugin manifest files registered with the ament resource index and instantiate a PluginClassLoader.

This factory method additionally performs an ambiguity check. This means that it verifies that only unique class names are being registered by the searched packages. Using the standard constructor, previously registered classes are being overriden if the same class name is being parsed again. Therefore, this method offers the preferred way of instantiating a PluginClassLoader.

Template Parameters:

LoaderT – Type of the plugin class loader.

Parameters:
  • base_package – Name of the package containing the base_class. Will throw an error if it is not installed.

  • base_class – Fully qualified name of the base class that the class loader will use for determining which classes listed in a plugins.xml file are associated with this instance.

  • exclude_packages – Packages to exclude when searching for plugins.

  • reserved_names – Map of reserved class names and the package name that makes the reservation. If any of these class names are found, an error is being raised (Used internally during build time when installed resources aren’t available yet).

Throws:
  • ament_index_cpp::PackageNotFoundError – if base_package is not installed.

  • auto_apms_util::exceptions::ResourceError – if no plugins of type base_class were found.

  • auto_apms_util::exceptions::ResourceError – if multiple packages register a resource using the same class name (or a name in reserved_names is found).