A class to help manage and load classes. More...
#include <class_loader.h>
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 >()) | |||
Constructor for a ClassLoader. | |||
T * | createUnmanagedInstance (const std::string &lookup_name) | ||
Creates an instance of a desired class (which implicitly calls loadLibraryForClass() to increment the library counter). | |||
virtual std::string | getBaseClassType () const | ||
Given the lookup name of a class, returns the type of the associated base class. | |||
virtual std::string | getClassDescription (const std::string &lookup_name) | ||
Given the lookup name of a class, returns its description. | |||
virtual std::string | getClassLibraryPath (const std::string &lookup_name) | ||
Given the name of a class, returns the path to its associated library. | |||
virtual std::string | getClassPackage (const std::string &lookup_name) | ||
Given the name of a class, returns name of the containing package. | |||
virtual std::string | getClassType (const std::string &lookup_name) | ||
Given the lookup name of a class, returns the type of the derived class associated with it. | |||
std::vector< std::string > | getDeclaredClasses () | ||
Returns a list of all available classes for this ClassLoader's base class type. | |||
virtual std::string | getName (const std::string &lookup_name) | ||
Strips the package name off of a lookup name. | |||
virtual std::string | getPluginManifestPath (const std::string &lookup_name) | ||
Given the name of a class, returns the path of the associated plugin manifest. | |||
std::vector< std::string > | getPluginXmlPaths () | ||
Returns a list of all available plugin manifest paths for this ClassLoader's base class type. | |||
virtual std::vector< std::string > | getRegisteredLibraries () | ||
Returns the libraries that are registered and can be loaded. | |||
virtual bool | isClassAvailable (const std::string &lookup_name) | ||
Checks if the class associated with a plugin name is available to be loaded. | |||
bool | isClassLoaded (const std::string &lookup_name) | ||
Checks if the library for a given class is currently loaded. | |||
virtual void | loadLibraryForClass (const std::string &lookup_name) | ||
Attempts to load the library containing a class with a given name and increments a counter for the library. | |||
virtual void | refreshDeclaredClasses () | ||
Refreshs the list of all available classes for this ClassLoader's base class type
| |||
virtual int | unloadLibraryForClass (const std::string &lookup_name) | ||
Decrements the counter for the library containing a class with a given name and attempts to unload it if the counter reaches zero. | |||
~ClassLoader () | |||
Destructor for ClassLoader. | |||
Private Member Functions | |||
std::string | callCommandLine (const char *cmd) | ||
std::map< std::string, ClassDesc > | determineAvailableClasses (const std::vector< std::string > &plugin_xml_paths) | ||
Returns the available classes. | |||
std::string | extractPackageNameFromPackageXML (const std::string &package_xml_path) | ||
std::vector< std::string > | getAllLibraryPathsToTry (const std::string &library_name, const std::string &exporting_package_name) | ||
std::vector< std::string > | getCatkinLibraryPaths () | ||
std::string | getErrorStringForUnknownClass (const std::string &lookup_name) | ||
Returns an error message for an unknown class. | |||
std::string | getPackageFromPluginXMLFilePath (const std::string &path) | ||
std::string | getPathSeparator () | ||
std::vector< std::string > | getPluginXmlPaths (const std::string &package, const std::string &attrib_name) | ||
std::string | getROSBuildLibraryPath (const std::string &exporting_package_name) | ||
std::string | joinPaths (const std::string &path1, const std::string &path2) | ||
std::vector< std::string > | parseToStringVector (std::string newline_delimited_str) | ||
void | processSingleXMLPluginFile (const std::string &xml_file, std::map< std::string, ClassDesc > &class_available) | ||
std::string | stripAllButFileFromPath (const std::string &path) | ||
int | unloadClassLibraryInternal (const std::string &library_path) | ||
Helper function for unloading a shared library. | |||
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 53 of file class_loader.h.
typedef std::map<std::string, ClassDesc>::iterator pluginlib::ClassLoader< T >::ClassMapIterator |
Definition at line 56 of file class_loader.h.
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>() |
||
) |
Constructor for a ClassLoader.
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::LibraryLoadException | Thrown if package manifest cannot be found |
Definition at line 53 of file class_loader_imp.h.
pluginlib::ClassLoader< T >::~ClassLoader | ( | ) |
Destructor for ClassLoader.
Definition at line 71 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::callCommandLine | ( | const char * | cmd | ) | [private] |
Calls a program from command line and returns output to stdout as a string
Definition at line 78 of file class_loader_imp.h.
T * pluginlib::ClassLoader< T >::createUnmanagedInstance | ( | const std::string & | lookup_name | ) |
Creates an instance of a desired class (which implicitly calls loadLibraryForClass() to increment the library counter).
lookup_name | The name of the class to load |
pluginlib::LibraryLoadException | Thrown when the library associated with the class cannot be loaded |
pluginlib::CreateClassException | Thrown when the class cannot be instantiated |
Definition at line 151 of file class_loader_imp.h.
std::map< std::string, ClassDesc > pluginlib::ClassLoader< T >::determineAvailableClasses | ( | const std::vector< std::string > & | plugin_xml_paths | ) | [private] |
Returns the available classes.
plugin_xml_paths | The vector of paths of plugin.xml files |
pluginlib::LibraryLoadException | Thrown if package manifest cannot be found |
Definition at line 187 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::extractPackageNameFromPackageXML | ( | const std::string & | package_xml_path | ) | [private] |
Opens a package.xml file and extracts the package name (i.e. contents of <name> tag)
Definition at line 206 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getAllLibraryPathsToTry | ( | const std::string & | library_name, |
const std::string & | exporting_package_name | ||
) | [private] |
Gets 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 239 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getBaseClassType | ( | ) | const [virtual] |
Given the lookup name of a class, returns the type of the associated base class.
Implements pluginlib::ClassLoaderBase.
Definition at line 271 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getCatkinLibraryPaths | ( | ) | [private] |
Returns the paths where libraries are installed according to the Catkin build system.
Definition at line 231 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getClassDescription | ( | const std::string & | lookup_name | ) | [virtual] |
Given the lookup name of a class, returns its description.
lookup_name | The lookup name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 278 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getClassLibraryPath | ( | const std::string & | lookup_name | ) | [virtual] |
Given the name of a class, returns the path to its associated library.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 298 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getClassPackage | ( | const std::string & | lookup_name | ) | [virtual] |
Given the name of a class, returns name of the containing package.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 326 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getClassType | ( | const std::string & | lookup_name | ) | [virtual] |
Given the lookup name of a class, returns the type of the derived class associated with it.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 288 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getDeclaredClasses | ( | ) | [virtual] |
Returns a list of all available classes for this ClassLoader's base class type.
Implements pluginlib::ClassLoaderBase.
Definition at line 343 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getErrorStringForUnknownClass | ( | const std::string & | lookup_name | ) | [private] |
Returns an error message for an unknown class.
lookup_name | The name of the class |
Definition at line 354 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getName | ( | const std::string & | lookup_name | ) | [virtual] |
Strips the package name off of a lookup name.
lookup_name | The name of the plugin |
Implements pluginlib::ClassLoaderBase.
Definition at line 368 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getPackageFromPluginXMLFilePath | ( | const std::string & | path | ) | [private] |
Gets the package name from a path to a plugin XML file
Definition at line 378 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getPathSeparator | ( | ) | [private] |
Gets the standard path separator for the native OS (e.g. "/" on *nix, "\" on windows)
Definition at line 435 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getPluginManifestPath | ( | const std::string & | lookup_name | ) | [virtual] |
Given the name of a class, returns the path of the associated plugin manifest.
lookup_name | The name of the class |
Implements pluginlib::ClassLoaderBase.
Definition at line 447 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getPluginXmlPaths | ( | ) | [virtual] |
Returns a list of all available plugin manifest paths for this ClassLoader's base class type.
Implements pluginlib::ClassLoaderBase.
Definition at line 336 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getPluginXmlPaths | ( | const std::string & | package, |
const std::string & | attrib_name | ||
) | [private] |
Returns the paths to plugin.xml files.
pluginlib::LibraryLoadException | Thrown if package manifest cannot be found |
Definition at line 177 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::getRegisteredLibraries | ( | ) | [virtual] |
Returns the libraries that are registered and can be loaded.
Implements pluginlib::ClassLoaderBase.
Definition at line 458 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::getROSBuildLibraryPath | ( | const std::string & | exporting_package_name | ) | [private] |
Gets the path where rosbuild build system thinks plugins are installed
Definition at line 465 of file class_loader_imp.h.
bool pluginlib::ClassLoader< T >::isClassAvailable | ( | const std::string & | lookup_name | ) | [virtual] |
Checks 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 472 of file class_loader_imp.h.
bool pluginlib::ClassLoader< T >::isClassLoaded | ( | const std::string & | lookup_name | ) | [virtual] |
Checks 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 264 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::joinPaths | ( | const std::string & | path1, |
const std::string & | path2 | ||
) | [private] |
Joins two filesystem paths together utilzing appropriate path separator
Definition at line 479 of file class_loader_imp.h.
void pluginlib::ClassLoader< T >::loadLibraryForClass | ( | const std::string & | lookup_name | ) | [virtual] |
Attempts to load the library containing a class with a given name and increments a counter for the library.
lookup_name | The lookup name of the class to load |
pluginlib::LibraryLoadException | Thrown if the library for the class cannot be loaded |
Implements pluginlib::ClassLoaderBase.
Definition at line 487 of file class_loader_imp.h.
std::vector< std::string > pluginlib::ClassLoader< T >::parseToStringVector | ( | std::string | newline_delimited_str | ) | [private] |
Parses a string delimited by newlines into a vector of strings
Definition at line 519 of file class_loader_imp.h.
void pluginlib::ClassLoader< T >::processSingleXMLPluginFile | ( | const std::string & | xml_file, |
std::map< std::string, ClassDesc > & | class_available | ||
) | [private] |
Parses a plugin XML file and inserts the appropriate ClassDesc entries into the passes classes_available map
Definition at line 540 of file class_loader_imp.h.
void pluginlib::ClassLoader< T >::refreshDeclaredClasses | ( | ) | [virtual] |
Refreshs the list of all available classes for this ClassLoader's base class type
pluginlib::LibraryLoadException | Thrown if package manifest cannot be found. |
Implements pluginlib::ClassLoaderBase.
Definition at line 619 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::stripAllButFileFromPath | ( | const std::string & | path | ) | [private] |
Strips all but the filename from an explicit file path.
Definition at line 651 of file class_loader_imp.h.
int pluginlib::ClassLoader< T >::unloadClassLibraryInternal | ( | const std::string & | library_path | ) | [private] |
Helper function for unloading a shared library.
library_path | The exact path to the library to unload |
Definition at line 680 of file class_loader_imp.h.
int pluginlib::ClassLoader< T >::unloadLibraryForClass | ( | const std::string & | lookup_name | ) | [virtual] |
Decrements the counter for the library containing a class with a given name and attempts to unload it if the counter reaches zero.
lookup_name | The lookup name of the class to unload |
pluginlib::LibraryUnloadException | Thrown if the library for the class cannot be unloaded |
Implements pluginlib::ClassLoaderBase.
Definition at line 663 of file class_loader_imp.h.
std::string pluginlib::ClassLoader< T >::attrib_name_ [private] |
Definition at line 296 of file class_loader.h.
std::string pluginlib::ClassLoader< T >::base_class_ [private] |
Definition at line 295 of file class_loader.h.
std::map<std::string, ClassDesc> pluginlib::ClassLoader< T >::classes_available_ [private] |
Definition at line 293 of file class_loader.h.
class_loader::MultiLibraryClassLoader pluginlib::ClassLoader< T >::lowlevel_class_loader_ [private] |
Definition at line 297 of file class_loader.h.
std::string pluginlib::ClassLoader< T >::package_ [private] |
Definition at line 294 of file class_loader.h.
std::vector<std::string> pluginlib::ClassLoader< T >::plugin_xml_paths_ [private] |
Definition at line 292 of file class_loader.h.