Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
pluginlib::ClassLoader< T > Class Template Reference

A class to help manage and load classes. More...

#include <class_loader.h>

Inheritance diagram for pluginlib::ClassLoader< T >:
Inheritance graph
[legend]

List of all members.

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"))
 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).
std::string getBaseClassType () const
 Given the lookup name of a class, returns the type of the associated base class.
std::string getClassDescription (const std::string &lookup_name)
 Given the lookup name of a class, returns its description.
std::string getClassLibraryPath (const std::string &lookup_name)
 Given the name of a class, returns the path to its associated library.
std::string getClassPackage (const std::string &lookup_name)
 Given the name of a class, returns name of the containing package.
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.
std::string getName (const std::string &lookup_name)
 Strips the package name off of a lookup name.
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 > getRegisteredLibraries ()
 Returns the libraries that are registered and can be loaded.
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 a given class is currently loaded.
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.
void refreshDeclaredClasses ()
 Refreshs the list of all available classes for this ClassLoader's base class type

Exceptions:
pluginlib::LibraryLoadExceptionThrown if package manifest cannot be found.

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 Types

typedef std::map< std::string,
unsigned int > 
LibraryCountMap

Private Member Functions

std::map< std::string, ClassDescdetermineAvailableClasses ()
 Returns the available classes

Exceptions:
pluginlib::LibraryLoadExceptionThrown if package manifest cannot be found.

void garbageInstance (T *p, const std::string &lookup_name)
std::vector< std::string > getClassesInLibrary (const std::string &library_path)
 Returns the names of the classes that are available in a given library.
std::string getErrorStringForUnknownClass (const std::string &lookup_name)
 Returns an error message for an unknown class.
std::vector< std::string > getLoadedLibraries ()
 Returns the libraries that are currently loaded.
bool loadClassLibrary (const std::string &library_path)
 Dynamicaly loads a library.
void loadClassLibraryInternal (const std::string &library_path, const std::string &list_name_arg=std::string(""))
 Helper function for loading a shared library.
bool unloadClassLibrary (const std::string &library_path)
 Unloads a previously dynamically loaded lobrary.
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, ClassDescclasses_available_
LibraryCountMap loaded_libraries_
std::string package_
Poco::ClassLoader< T > poco_class_loader_

Detailed Description

template<class T>
class pluginlib::ClassLoader< T >

A class to help manage and load classes.

Definition at line 204 of file class_loader.h.


Member Typedef Documentation

template<class T>
typedef std::map<std::string, ClassDesc>::iterator pluginlib::ClassLoader< T >::ClassMapIterator

Definition at line 210 of file class_loader.h.

template<class T>
typedef std::map<std::string, unsigned int> pluginlib::ClassLoader< T >::LibraryCountMap [private]

Definition at line 207 of file class_loader.h.


Constructor & Destructor Documentation

template<class T >
pluginlib::ClassLoader< T >::ClassLoader ( std::string  package,
std::string  base_class,
std::string  attrib_name = std::string("plugin") 
)

Constructor for a ClassLoader.

Parameters:
packageThe package containing the base class
base_classThe type of the base class for classes to be loaded
attrib_nameThe attribute to search for in manifext.xml files, defaults to "plugin"
Exceptions:
pluginlib::LibraryLoadExceptionThrown if package manifest cannot be found

Definition at line 49 of file class_loader_imp.h.

template<class T >
pluginlib::ClassLoader< T >::~ClassLoader ( )

Destructor for ClassLoader.

Definition at line 104 of file class_loader_imp.h.


Member Function Documentation

template<class T >
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).

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_nameThe name of the class to load
Exceptions:
pluginlib::LibraryLoadExceptionThrown when the library associated with the class cannot be loaded
pluginlib::CreateClassExceptionThrown when the class cannot be instantiated
Returns:
An instance of the class

Definition at line 258 of file class_loader_imp.h.

template<class T >
std::map< std::string, ClassDesc > pluginlib::ClassLoader< T >::determineAvailableClasses ( ) [private]

Returns the available classes

Exceptions:
pluginlib::LibraryLoadExceptionThrown if package manifest cannot be found.

Returns:
A map of class names and the corresponding descriptions

Definition at line 409 of file class_loader_imp.h.

template<class T >
void pluginlib::ClassLoader< T >::garbageInstance ( T *  p,
const std::string &  lookup_name 
) [private]

Deleter for boost shared pointer.

Parameters:
pThe instance
lookup_nameThe name of the class

Definition at line 276 of file class_loader_imp.h.

template<class T >
std::string pluginlib::ClassLoader< T >::getBaseClassType ( ) const [virtual]

Given the lookup name of a class, returns the type of the associated base class.

Returns:
The type of the associated base class

Implements pluginlib::ClassLoaderBase.

Definition at line 203 of file class_loader_imp.h.

template<class T >
std::string pluginlib::ClassLoader< T >::getClassDescription ( const std::string &  lookup_name) [virtual]

Given the lookup name of a class, returns its description.

Parameters:
lookup_nameThe lookup name of the class
Returns:
The description of the class

Implements pluginlib::ClassLoaderBase.

Definition at line 194 of file class_loader_imp.h.

template<class T >
std::vector< std::string > pluginlib::ClassLoader< T >::getClassesInLibrary ( const std::string &  library_path) [private]

Returns the names of the classes that are available in a given library.

Parameters:
library_pathThe path to the library
Returns:
A vector of strings corresponding to the names of the classes in the library

Definition at line 352 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe name of the class
Returns:
The path to the associated library

Implements pluginlib::ClassLoaderBase.

Definition at line 209 of file class_loader_imp.h.

template<class T >
std::string pluginlib::ClassLoader< T >::getClassPackage ( const std::string &  lookup_name) [virtual]

Given the name of a class, returns name of the containing package.

Parameters:
lookup_nameThe name of the class
Returns:
The name of the containing package

Implements pluginlib::ClassLoaderBase.

Definition at line 218 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe name of the class
Returns:
The name of the associated derived class

Implements pluginlib::ClassLoaderBase.

Definition at line 185 of file class_loader_imp.h.

template<class T >
std::vector< std::string > pluginlib::ClassLoader< T >::getDeclaredClasses ( ) [virtual]

Returns 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

Implements pluginlib::ClassLoaderBase.

Definition at line 128 of file class_loader_imp.h.

template<class T >
std::string pluginlib::ClassLoader< T >::getErrorStringForUnknownClass ( const std::string &  lookup_name) [private]

Returns an error message for an unknown class.

Parameters:
lookup_nameThe name of the class
Returns:
The error message

Definition at line 500 of file class_loader_imp.h.

template<class T >
std::vector< std::string > pluginlib::ClassLoader< T >::getLoadedLibraries ( ) [private]

Returns the libraries that are currently loaded.

Returns:
A vector of strings corresponding to the names of loaded libraries

Definition at line 387 of file class_loader_imp.h.

template<class T >
std::string pluginlib::ClassLoader< T >::getName ( const std::string &  lookup_name) [virtual]

Strips the package name off of a lookup name.

Parameters:
lookup_nameThe name of the plugin
Returns:
The name of the plugin stripped of the package name

Implements pluginlib::ClassLoaderBase.

Definition at line 170 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe name of the class
Returns:
The path of the associated plugin manifest

Implements pluginlib::ClassLoaderBase.

Definition at line 227 of file class_loader_imp.h.

template<class T >
std::vector< std::string > pluginlib::ClassLoader< T >::getRegisteredLibraries ( ) [virtual]

Returns the libraries that are registered and can be loaded.

Returns:
A vector of strings corresponding to the names of registered libraries

Implements pluginlib::ClassLoaderBase.

Definition at line 371 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe name of the plugin
Returns:
True if the plugin is available, false otherwise

Implements pluginlib::ClassLoaderBase.

Definition at line 179 of file class_loader_imp.h.

template<class T >
bool pluginlib::ClassLoader< T >::isClassLoaded ( const std::string &  lookup_name) [virtual]

Checks if a given class is currently loaded.

Parameters:
lookup_nameThe lookup name of the class to query
Returns:
True if the class is loaded, false otherwise

Implements pluginlib::ClassLoaderBase.

Definition at line 115 of file class_loader_imp.h.

template<class T >
bool pluginlib::ClassLoader< T >::loadClassLibrary ( const std::string &  library_path) [private]

Dynamicaly loads a library.

Parameters:
library_pathThe library to unload
Returns:
True if the library was successfully loaded, false otherwise

Definition at line 305 of file class_loader_imp.h.

template<class T >
void pluginlib::ClassLoader< T >::loadClassLibraryInternal ( const std::string &  library_path,
const std::string &  list_name_arg = std::string("") 
) [private]

Helper function for loading a shared library.

Parameters:
library_pathThe path to the library to load
list_nameThe name of the class list to load

Definition at line 322 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe lookup name of the class to load
Exceptions:
pluginlib::LibraryLoadExceptionThrown if the library for the class cannot be loaded

Implements pluginlib::ClassLoaderBase.

Definition at line 55 of file class_loader_imp.h.

template<class T >
void pluginlib::ClassLoader< T >::refreshDeclaredClasses ( ) [virtual]

Refreshs the list of all available classes for this ClassLoader's base class type

Exceptions:
pluginlib::LibraryLoadExceptionThrown if package manifest cannot be found.

Implements pluginlib::ClassLoaderBase.

Definition at line 139 of file class_loader_imp.h.

template<class T >
bool pluginlib::ClassLoader< T >::unloadClassLibrary ( const std::string &  library_path) [private]

Unloads a previously dynamically loaded lobrary.

Parameters:
library_pathThe library to unload
Returns:
True if the library was successfully unloaded, false otherwise

Definition at line 287 of file class_loader_imp.h.

template<class T >
int pluginlib::ClassLoader< T >::unloadClassLibraryInternal ( const std::string &  library_path) [private]

Helper function for unloading a shared library.

Parameters:
library_pathThe path to the library to unload
Returns:
The number of pending unloads until the library is removed from memory

Definition at line 335 of file class_loader_imp.h.

template<class T >
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.

Parameters:
lookup_nameThe lookup name of the class to unload
Exceptions:
pluginlib::LibraryUnloadExceptionThrown if the library for the class cannot be unloaded
Returns:
The number of pending unloads until the library is removed from memory

Implements pluginlib::ClassLoaderBase.

Definition at line 87 of file class_loader_imp.h.


Member Data Documentation

template<class T>
std::string pluginlib::ClassLoader< T >::attrib_name_ [private]

Definition at line 423 of file class_loader.h.

template<class T>
std::string pluginlib::ClassLoader< T >::base_class_ [private]

Definition at line 422 of file class_loader.h.

template<class T>
std::map<std::string, ClassDesc> pluginlib::ClassLoader< T >::classes_available_ [private]

Definition at line 420 of file class_loader.h.

template<class T>
LibraryCountMap pluginlib::ClassLoader< T >::loaded_libraries_ [private]

Definition at line 416 of file class_loader.h.

template<class T>
std::string pluginlib::ClassLoader< T >::package_ [private]

Definition at line 421 of file class_loader.h.

template<class T>
Poco::ClassLoader<T> pluginlib::ClassLoader< T >::poco_class_loader_ [private]

Definition at line 425 of file class_loader.h.


The documentation for this class was generated from the following files:


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:20