A class to help manage and load classes. More...
#include <class_loader.hpp>
Public Types | |
typedef std::map< std::string, ClassDesc >::iterator | ClassMapIterator |
Public Member 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 >()) | |
T * | createClassInstance (const std::string &lookup_name, bool auto_load=true) |
Create an instance of a desired class, optionally loading the associated library too. More... | |
boost::shared_ptr< T > | createInstance (const std::string &lookup_name) |
Create an instance of a desired class. More... | |
T * | createUnmanagedInstance (const std::string &lookup_name) |
Create an instance of a desired class. More... | |
virtual std::string | getBaseClassType () const |
Given the lookup name of a class, return the type of the associated base class. More... | |
virtual std::string | getClassDescription (const std::string &lookup_name) |
Given the lookup name of a class, return its description. More... | |
virtual std::string | getClassLibraryPath (const std::string &lookup_name) |
Given the name of a class, return the path to its associated library. More... | |
virtual std::string | getClassPackage (const std::string &lookup_name) |
Given the name of a class, return name of the containing package. More... | |
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. More... | |
std::vector< std::string > | getDeclaredClasses () |
Return a list of all available classes for this ClassLoader's base class type. More... | |
virtual std::string | getName (const std::string &lookup_name) |
Strip the package name off of a lookup name. More... | |
virtual std::string | getPluginManifestPath (const std::string &lookup_name) |
Given the name of a class, return the path of the associated plugin manifest. More... | |
std::vector< std::string > | getPluginXmlPaths () |
Return a list of all available plugin manifest paths for this ClassLoader's base class type. More... | |
virtual std::vector< std::string > | getRegisteredLibraries () |
Return the libraries that are registered and can be loaded. More... | |
virtual bool | isClassAvailable (const std::string &lookup_name) |
Check if the class associated with a plugin name is available to be loaded. More... | |
bool | isClassLoaded (const std::string &lookup_name) |
Check if the library for a given class is currently loaded. More... | |
virtual void | loadLibraryForClass (const std::string &lookup_name) |
Attempt to load the library containing a class with a given name. More... | |
virtual void | refreshDeclaredClasses () |
Refresh the list of all available classes for this ClassLoader's base class type. More... | |
virtual int | unloadLibraryForClass (const std::string &lookup_name) |
Decrement the counter for the library containing a class with a given name. More... | |
~ClassLoader () override | |
The destructor attempts to unload all libraries which are still loaded. More... | |
Public Member Functions inherited from pluginlib::ClassLoaderBase | |
virtual | ~ClassLoaderBase () |
Empty virtual destructor. More... | |
Private Member Functions | |
std::map< std::string, ClassDesc > | determineAvailableClasses (const std::vector< std::string > &plugin_xml_paths) |
Return the available classes. More... | |
std::string | extractPackageNameFromPackageXML (const std::string &package_xml_path) |
Open a package.xml file and extract the package name (i.e. contents of <name> tag). More... | |
std::vector< std::string > | getAllLibraryPathsToTry (const std::string &library_name, const std::string &exporting_package_name) |
Get a list of paths to try to find a library. More... | |
std::vector< std::string > | getCatkinLibraryPaths () |
Return the paths where libraries are installed according to the Catkin build system. More... | |
std::string | getErrorStringForUnknownClass (const std::string &lookup_name) |
Return an error message for an unknown class. More... | |
std::string | getPackageFromPluginXMLFilePath (const std::string &path) |
Get the package name from a path to a plugin XML file. More... | |
std::string | getPathSeparator () |
Get the standard path separator for the native OS (e.g. "/" on *nix, "\" on Windows). More... | |
std::vector< std::string > | getPluginXmlPaths (const std::string &package, const std::string &attrib_name, bool force_recrawl=false) |
Return the paths to plugin.xml files. More... | |
std::string | getROSBuildLibraryPath (const std::string &exporting_package_name) |
Given a package name, return the path where rosbuild thinks plugins are installed. More... | |
std::string | joinPaths (const std::string &path1, const std::string &path2) |
Join two filesystem paths together utilzing appropriate path separator. More... | |
void | processSingleXMLPluginFile (const std::string &xml_file, std::map< std::string, ClassDesc > &class_available) |
Parse a plugin XML file. More... | |
std::string | stripAllButFileFromPath (const std::string &path) |
Strip all but the filename from an explicit file path. More... | |
int | unloadClassLibraryInternal (const std::string &library_path) |
Helper function for unloading a shared library. More... | |
Private Attributes | |
std::string | attrib_name_ |
std::string | base_class_ |
std::map< std::string, ClassDesc > | classes_available_ |
class_loader::MultiLibraryClassLoader | lowlevel_class_loader_ |
std::string | package_ |
std::vector< std::string > | plugin_xml_paths_ |
A class to help manage and load classes.
Definition at line 61 of file class_loader.hpp.
typedef std::map<std::string, ClassDesc>::iterator pluginlib::ClassLoader< T >::ClassMapIterator |
Definition at line 64 of file class_loader.hpp.
pluginlib::ClassLoader< T >::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>() |
||
) |
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() |
pluginlib::ClassLoaderException | if package manifest cannot be found |
Definition at line 68 of file class_loader_imp.hpp.
|
override |
The destructor attempts to unload all libraries which are still loaded.
class_loader::LibraryUnloadException | if unloading a library fails |
Definition at line 98 of file class_loader_imp.hpp.
T * pluginlib::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.
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. |
pluginlib::LibraryLoadException | when the library associated with the class cannot be loaded |
pluginlib::CreateClassException | when the class cannot be instantiated |
Definition at line 107 of file class_loader_imp.hpp.
boost::shared_ptr< T > pluginlib::ClassLoader< T >::createInstance | ( | 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 shared pointer.
lookup_name | The name of the class to load |
pluginlib::LibraryLoadException | when the library associated with the class cannot be loaded |
pluginlib::CreateClassException | when the class cannot be instantiated |
Definition at line 136 of file class_loader_imp.hpp.
T * pluginlib::ClassLoader< T >::createUnmanagedInstance | ( | const std::string & | lookup_name | ) |
Create an instance of a desired class.
Implicitly calls loadLibraryForClass() to increment the library counter.
lookup_name | The name of the class to load |
pluginlib::LibraryLoadException | when the library associated with the class cannot be loaded |
pluginlib::CreateClassException | when the class cannot be instantiated |
Definition at line 200 of file class_loader_imp.hpp.
|
private |
Return the available classes.
plugin_xml_paths | The vector of paths of plugin.xml files |
pluginlib::LibraryLoadException | if package manifest cannot be found |
Definition at line 243 of file class_loader_imp.hpp.
|
private |
Open a package.xml file and extract the package name (i.e. contents of <name> tag).
package_xml_path | The path to the package.xml file |
Definition at line 273 of file class_loader_imp.hpp.
|
private |
Get a list of paths to try to find a library.
As we transition from rosbuild to Catkin build systems, plugins can be found in the old rosbuild place (pkg_name/lib usually) or somewhere in the Catkin build space.
Definition at line 333 of file class_loader_imp.hpp.
|
virtual |
Given the lookup name of a class, return the type of the associated base class.
Implements pluginlib::ClassLoaderBase.
Definition at line 386 of file class_loader_imp.hpp.
|
private |
Return the paths where libraries are installed according to the Catkin build system.
Definition at line 310 of file class_loader_imp.hpp.
|
virtual |
Given the lookup name of a class, return its description.
lookup_name | The lookup name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 393 of file class_loader_imp.hpp.
|
virtual |
Given the name of a class, return the path to its associated library.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 415 of file class_loader_imp.hpp.
|
virtual |
Given the name of a class, return name of the containing package.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 451 of file class_loader_imp.hpp.
|
virtual |
Given the lookup name of a class, return the type of the derived class associated with it.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 404 of file class_loader_imp.hpp.
|
virtual |
Return a list of all available classes for this ClassLoader's base class type.
Implements pluginlib::ClassLoaderBase.
Definition at line 469 of file class_loader_imp.hpp.
|
private |
Return an error message for an unknown class.
lookup_name | The name of the class |
Definition at line 481 of file class_loader_imp.hpp.
|
virtual |
Strip the package name off of a lookup name.
lookup_name | The name of the plugin |
Implements pluginlib::ClassLoaderBase.
Definition at line 495 of file class_loader_imp.hpp.
|
private |
Get the package name from a path to a plugin XML file.
Definition at line 506 of file class_loader_imp.hpp.
|
private |
Get the standard path separator for the native OS (e.g. "/" on *nix, "\" on Windows).
Definition at line 561 of file class_loader_imp.hpp.
|
virtual |
Given the name of a class, return the path of the associated plugin manifest.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 577 of file class_loader_imp.hpp.
|
virtual |
Return a list of all available plugin manifest paths for this ClassLoader's base class type.
Implements pluginlib::ClassLoaderBase.
Definition at line 462 of file class_loader_imp.hpp.
|
private |
Return the paths to plugin.xml files.
pluginlib::LibraryLoadException | if package manifest cannot be found |
Definition at line 230 of file class_loader_imp.hpp.
|
virtual |
Return the libraries that are registered and can be loaded.
Implements pluginlib::ClassLoaderBase.
Definition at line 589 of file class_loader_imp.hpp.
|
private |
Given a package name, return the path where rosbuild thinks plugins are installed.
Definition at line 596 of file class_loader_imp.hpp.
|
virtual |
Check if the class associated with a plugin name is available to be loaded.
lookup_name | The name of the plugin |
Implements pluginlib::ClassLoaderBase.
Definition at line 603 of file class_loader_imp.hpp.
|
virtual |
Check if the library for a given class is currently loaded.
lookup_name | The lookup name of the class to query |
Implements pluginlib::ClassLoaderBase.
Definition at line 379 of file class_loader_imp.hpp.
|
private |
Join two filesystem paths together utilzing appropriate path separator.
Definition at line 610 of file class_loader_imp.hpp.
|
virtual |
Attempt to load the library containing a class with a given name.
The counter for the library uses (refcount) is also incremented.
lookup_name | The lookup name of the class to load |
pluginlib::LibraryLoadException | if the library for the class cannot be loaded |
Implements pluginlib::ClassLoaderBase.
Definition at line 618 of file class_loader_imp.hpp.
|
private |
Parse a plugin XML file.
Also insert the appropriate ClassDesc entries into the passes classes_available map.
Definition at line 653 of file class_loader_imp.hpp.
|
virtual |
Refresh the list of all available classes for this ClassLoader's base class type.
pluginlib::LibraryLoadException | if package manifest cannot be found |
Implements pluginlib::ClassLoaderBase.
Definition at line 768 of file class_loader_imp.hpp.
|
private |
Strip all but the filename from an explicit file path.
path | The path to strip |
Definition at line 802 of file class_loader_imp.hpp.
|
private |
Helper function for unloading a shared library.
library_path | The exact path to the library to unload |
Definition at line 830 of file class_loader_imp.hpp.
|
virtual |
Decrement the counter for the library containing a class with a given name.
Also try to unload the library, If the counter reaches zero.
lookup_name | The lookup name of the class to unload |
pluginlib::LibraryUnloadException | if the library for the class cannot be unloaded |
Implements pluginlib::ClassLoaderBase.
Definition at line 815 of file class_loader_imp.hpp.
|
private |
Definition at line 347 of file class_loader.hpp.
|
private |
Definition at line 346 of file class_loader.hpp.
|
private |
Definition at line 344 of file class_loader.hpp.
|
private |
Definition at line 348 of file class_loader.hpp.
|
private |
Definition at line 345 of file class_loader.hpp.
|
private |
Definition at line 342 of file class_loader.hpp.