cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | List of all members
osaDynamicLoaderAndFactory< BaseClass > Class Template Reference

Dynamically load a shared library file and find the factory methods in the file. More...

#include <osaDynamicLoaderAndFactory.h>

Inheritance diagram for osaDynamicLoaderAndFactory< BaseClass >:
osaDynamicLoaderAndFactoryBase osaDynamicLoader

Public Member Functions

 osaDynamicLoaderAndFactory ()
 
virtual ~osaDynamicLoaderAndFactory ()
 
bool Init (const char *name, const char *file, const char *path=0)
 
bool Init (const char *name)
 
void Reset ()
 
BaseClass * CreateObject () const
 
void DestroyObject (BaseClass *obj) const
 
- Public Member Functions inherited from osaDynamicLoaderAndFactoryBase
virtual ~osaDynamicLoaderAndFactoryBase ()
 
void Reset ()
 
- Public Member Functions inherited from osaDynamicLoader
 osaDynamicLoader ()
 
virtual ~osaDynamicLoader ()
 
bool Load (const char *file, const char *path=0)
 
void UnLoad ()
 

Additional Inherited Members

- Protected Member Functions inherited from osaDynamicLoaderAndFactoryBase
 osaDynamicLoaderAndFactoryBase ()
 
bool Init (const char *name, const char *file, const char *path, const std::type_info &tinfo, int version)
 
- Protected Attributes inherited from osaDynamicLoaderAndFactoryBase
void * create
 
void * destroy
 
- Protected Attributes inherited from osaDynamicLoader
void * handle
 

Detailed Description

template<class BaseClass>
class osaDynamicLoaderAndFactory< BaseClass >

Dynamically load a shared library file and find the factory methods in the file.

This is a templated class that is used to dynamically load "plugin" modules that are implemented as derived classes of the specified base class (template parameter). The advantage of this class over osaDynamicLoader is that any class can serve as the base class. It is not necessary for the base or derived class to inherit from cmnGenericObject. The only requirement is that it contain a public VERSION enum that specifies the "interface version" of the base class. The VERSION should be changed for any base class changes that could affect the derived classes (e.g., adding member data, changing public methods, etc.).

If the base class is cmnGenericObject (or derived from it), the osaDynamicLoader class should be used instead.

See Also
osaDynamicLoader

Constructor & Destructor Documentation

template<class BaseClass >
osaDynamicLoaderAndFactory< BaseClass >::osaDynamicLoaderAndFactory ( )
inline

Default constructor. Calls Reset() method.

template<class BaseClass >
virtual osaDynamicLoaderAndFactory< BaseClass >::~osaDynamicLoaderAndFactory ( )
inlinevirtual

Destructor. Does not unload library in case any objects created from within the library still exist. To close library, call Reset().

Member Function Documentation

template<class BaseClass >
BaseClass* osaDynamicLoaderAndFactory< BaseClass >::CreateObject ( ) const
inline

Create a new instance of the derived class (from the dynamically loaded library).

Returns
a pointer to the new instance (0 if class not initialized)
template<class BaseClass >
void osaDynamicLoaderAndFactory< BaseClass >::DestroyObject ( BaseClass *  obj) const
inline

Delete an instance of the derived class.

Parameters
objPointer to object to be destroyed.
template<class BaseClass >
bool osaDynamicLoaderAndFactory< BaseClass >::Init ( const char *  name,
const char *  file,
const char *  path = 0 
)
inline

Load the derived class from the specified file. Note that a file may contain more than one derived class, but each derived class must be accessed via a new dynamic loader object. The operating system ensures that a library is only loaded once.

Parameters
nameName of derived class
fileFile name for derived class (do not include extension)
pathPath to file (0 -> use default library load paths)
Returns
true if sucessful; false otherwise
template<class BaseClass >
bool osaDynamicLoaderAndFactory< BaseClass >::Init ( const char *  name)
inline

Load the derived class from a file that has the same name as the derived class (no extension).

Parameters
nameName of derived class
Returns
true if sucessful; false otherwise
template<class BaseClass >
void osaDynamicLoaderAndFactory< BaseClass >::Reset ( void  )
inline

Unload the library file and clear the factory functions. Do not call this method unless you are sure that all instances of the derived class have already been destroyed.


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