Lunchbox
1.16.0
Multi-threaded C++ toolbox library for all application developers creating high-performance multi-threaded programs.
|
Factory for Plugin classes. More...
#include <pluginFactory.h>
Public Types | |
typedef Plugin< T > | PluginT |
typedef std::vector< PluginT > | Plugins |
Public Member Functions | |
bool | handles (const typename T::InitDataT &initData) |
T * | create (const typename T::InitDataT &initData) |
Create a plugin instance. More... | |
void | register_ (const PluginT &plugin) |
Register a plugin type. More... | |
bool | deregister (const PluginT &plugin) |
Deregister a plugin type. More... | |
void | deregisterAll () |
Unregister all plugin types. More... | |
std::string | getDescriptions () const |
Automatic loading of plugin DSOs. | |
void | load (const int version, const std::string &path, const std::string &pattern) |
Load all compatible plugin libraries from a directory matching a pattern. More... | |
void | load (const int version, const Strings &paths, const std::string &pattern) |
Static Public Member Functions | |
static PluginFactory & | getInstance () |
Get the single class instance. More... | |
Factory for Plugin classes.
The PluginFactory selects the a plugin for a given T::InitDataT, based on a plugin's handles() function. In case a InitDataT can be handled by multiple plugins, which plugin is chosen is undefined.
This class has been designed as a singleton to allow for link time plugin registration, but nothing prevents an application from registering new types at run time.
To do the registration of a plugin during the static initialization phase use the PluginRegisterer.
Example:
Definition at line 56 of file pluginFactory.h.
T * lunchbox::PluginFactory< T >::create | ( | const typename T::InitDataT & | initData | ) |
Create a plugin instance.
initData | The initData passed to the plugin constructor. |
std::runtime_error | if no plugin can handle the initData. |
Definition at line 51 of file pluginFactory.ipp.
References LBTHROW.
bool lunchbox::PluginFactory< T >::deregister | ( | const PluginT & | plugin | ) |
void lunchbox::PluginFactory< T >::deregisterAll | ( | ) |
std::string lunchbox::PluginFactory< T >::getDescriptions | ( | ) | const |
Definition at line 89 of file pluginFactory.ipp.
References lunchbox::PluginFactory< T >::load(), and lunchbox::usort().
|
static |
Get the single class instance.
Definition at line 25 of file pluginFactory.ipp.
Referenced by lunchbox::PluginRegisterer< T >::PluginRegisterer().
bool lunchbox::PluginFactory< T >::handles | ( | const typename T::InitDataT & | initData | ) |
Definition at line 42 of file pluginFactory.ipp.
void lunchbox::PluginFactory< T >::load | ( | const int | version, |
const std::string & | path, | ||
const std::string & | pattern | ||
) |
Load all compatible plugin libraries from a directory matching a pattern.
The pattern is the core name of the library, and is extended by the system-specific shared library suffix and postfix. The plugin has to implement the C functions 'int LunchboxPluginGetVersion()' and 'bool LunchboxPluginRegister()'. Only plugins with the same ABI version as the given one are registered.
version | the current ABI version of the application loading the plugins. |
path | the directory to search for plugins. |
pattern | the core pattern of plugin names. |
Definition at line 110 of file pluginFactory.ipp.
References lunchbox::DSO::getFunctionPointer(), lunchbox::DSO::isOpen(), LBERROR, LBINFO, and lunchbox::searchDirectory().
Referenced by lunchbox::PluginFactory< T >::getDescriptions().
void lunchbox::PluginFactory< T >::register_ | ( | const PluginT & | plugin | ) |
Register a plugin type.
Definition at line 62 of file pluginFactory.ipp.
Referenced by lunchbox::PluginRegisterer< T >::PluginRegisterer().