Template Class ClassLoader
Defined in File class_loader.hpp
Inheritance Relationships
Base Type
public pluginlib::ClassLoaderBase
(Class ClassLoaderBase)
Class Documentation
-
template<class T>
class pluginlib::ClassLoader : public pluginlib::ClassLoaderBase A class to help manage and load classes.
Public Functions
-
ClassLoader(std::string package, std::string base_class, std::string attrib_name = std::string("plugin"), std::vector<std::string> plugin_xml_paths = std::vector<std::string>())
- Parameters
package – The package containing the base class
base_class – The type of the base class for classes to be loaded
attrib_name – The attribute to search for in manifext.xml files, defaults to “plugin”
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
-
~ClassLoader()
-
T *createClassInstance(const std::string &lookup_name, bool auto_load = true)
Create an instance of a desired class, optionally loading the associated library too.
- Deprecated:
use either createInstance() or createUnmanagedInstance()
- Parameters
lookup_name – The name of the class to load
auto_load – Specifies whether or not to automatically load the library containing the class, set to true by default.
- Throws
pluginlib::LibraryLoadException – when the library associated with the class cannot be loaded
pluginlib::CreateClassException – when the class cannot be instantiated
- Returns
An instance of the class
Create an instance of a desired class.
Implicitly calls loadLibraryForClass() to increment the library counter.
Deleting the instance and calling unloadLibraryForClass() is automatically handled by the shared pointer.
- Parameters
lookup_name – The name of the class to load
- Throws
pluginlib::LibraryLoadException – when the library associated with the class cannot be loaded
pluginlib::CreateClassException – when the class cannot be instantiated
- Returns
An instance of the class
-
UniquePtr<T> createUniqueInstance(const std::string &lookup_name)
Create an instance of a desired class.
Implicitly calls loadLibraryForClass() to increment the library counter.
Deleting the instance and calling unloadLibraryForClass() is automatically handled by the unique pointer.
If you release the wrapped pointer you must manually call the original deleter when you want to destroy the released pointer.
- Parameters
lookup_name – The name of the class to load.
- Throws
pluginlib::LibraryLoadException – when the library associated with the class cannot be loaded.
pluginlib::CreateClassException – when the class cannot be instantiated
- Returns
An instance of the class
-
T *createUnmanagedInstance(const std::string &lookup_name)
Create an instance of a desired class.
Implicitly calls loadLibraryForClass() to increment the library counter.
- Attention
The ownership is transfered to the caller, which is responsible for deleting the instance and calling unloadLibraryForClass() (in order to decrement the associated library counter and unloading it if it is no more used).
- Parameters
lookup_name – The name of the class to load
- Throws
pluginlib::LibraryLoadException – when the library associated with the class cannot be loaded
pluginlib::CreateClassException – when the class cannot be instantiated
- Returns
An instance of the class
-
virtual std::vector<std::string> getPluginXmlPaths()
Return a list of all available plugin manifest paths for this ClassLoader’s base class type.
- Returns
A vector of strings corresponding to the paths of all available plugin manifests
-
virtual std::vector<std::string> getDeclaredClasses()
Return a list of all available classes for this ClassLoader’s base class type.
- Returns
A vector of strings corresponding to the names of all available classes
-
virtual std::string getName(const std::string &lookup_name)
Strip the package name off of a lookup name.
- Parameters
lookup_name – The name of the plugin
- Returns
The name of the plugin stripped of the package name
-
virtual std::string getBaseClassType() const
Given the lookup name of a class, return the type of the associated base class.
- Returns
The type of the associated base class
-
virtual std::string getClassType(const std::string &lookup_name)
Given the lookup name of a class, return the type of the derived class associated with it.
- Parameters
lookup_name – The name of the class
- Returns
The name of the associated derived class
-
virtual std::string getClassDescription(const std::string &lookup_name)
Given the lookup name of a class, return its description.
- Parameters
lookup_name – The lookup name of the class
- Returns
The description of the class
-
virtual std::string getClassLibraryPath(const std::string &lookup_name)
Given the name of a class, return the path to its associated library.
- Parameters
lookup_name – The name of the class
- Returns
The path to the associated library
-
virtual std::string getClassPackage(const std::string &lookup_name)
Given the name of a class, return name of the containing package.
- Parameters
lookup_name – The name of the class
- Returns
The name of the containing package
-
virtual std::string getPluginManifestPath(const std::string &lookup_name)
Given the name of a class, return the path of the associated plugin manifest.
- Parameters
lookup_name – The name of the class
- Returns
The path of the associated plugin manifest
-
virtual std::vector<std::string> getRegisteredLibraries()
Return the libraries that are registered and can be loaded.
- Returns
A vector of strings corresponding to the names of registered libraries
-
virtual bool isClassLoaded(const std::string &lookup_name)
Check if the library for a given class is currently loaded.
- Parameters
lookup_name – The lookup name of the class to query
- Returns
True if the class is loaded, false otherwise
-
virtual bool isClassAvailable(const std::string &lookup_name)
Check if the class associated with a plugin name is available to be loaded.
- Parameters
lookup_name – The name of the plugin
- Returns
true if the plugin is available, false otherwise
-
virtual void loadLibraryForClass(const std::string &lookup_name)
Attempt to load the library containing a class with a given name.
The counter for the library uses (refcount) is also incremented.
- Parameters
lookup_name – The lookup name of the class to load
- Throws
pluginlib::LibraryLoadException – if the library for the class cannot be loaded
-
virtual void refreshDeclaredClasses()
Refresh the list of all available classes for this ClassLoader’s base class type.
- Throws
pluginlib::LibraryLoadException – if package manifest cannot be found
-
virtual int unloadLibraryForClass(const std::string &lookup_name)
Decrement the counter for the library containing a class with a given name.
Also try to unload the library, If the counter reaches zero.
- Parameters
lookup_name – The lookup name of the class to unload
- Throws
pluginlib::LibraryUnloadException – if the library for the class cannot be unloaded
- Returns
The number of pending unloads until the library is removed from memory
-
ClassLoader(std::string package, std::string base_class, std::string attrib_name = std::string("plugin"), std::vector<std::string> plugin_xml_paths = std::vector<std::string>())