cppexpose
1.0.0.b785e04f23b8
C++ library for type introspection, reflection, and scripting interface
|
Class for managing components and plugins. More...
#include <cppexpose/include/cppexpose/plugin/ComponentManager.h>
Public Member Functions | |
ComponentManager () | |
Constructor. More... | |
ComponentManager (const ComponentManager &)=delete | |
Copy constructor (deleted) More... | |
virtual | ~ComponentManager () |
Destructor. More... | |
ComponentManager & | operator= (const ComponentManager &)=delete |
Copy assignment operator (deleted) More... | |
const std::vector< std::string > & | pluginPaths (PluginPathType type=PluginPathType::UserDefined) const |
Get plugin paths. More... | |
void | addPluginPath (const std::string &path, PluginPathType type=PluginPathType::UserDefined) |
Add plugin path. More... | |
void | removePluginPath (const std::string &path) |
Remove plugin path. More... | |
void | scanPlugins (const std::string &suffix="", bool reload=false) |
Scan for plugins and load all found ones. More... | |
bool | loadPlugin (const std::string &filePath, bool reload=true) |
Load plugin library. More... | |
std::vector< PluginLibrary * > | pluginLibraries () const |
Get list of loaded plugin libraries. More... | |
const std::vector< AbstractComponent * > & | components () const |
Get list of available components. More... | |
template<typename BaseType > | |
std::vector< typename ComponentTypes< BaseType >::AbstractComponentType * > | components () const |
Get list of available components of a specific type. More... | |
AbstractComponent * | component (const std::string &name) const |
Get component by name. More... | |
template<typename BaseType > | |
ComponentTypes< BaseType >::AbstractComponentType * | component (const std::string &name) const |
Get typed component. More... | |
void | printComponents () const |
Print list of available components to log. More... | |
Static Public Member Functions | |
static ComponentRegistry & | registry () |
Get component registry. More... | |
Public Attributes | |
Signal | componentsChanged |
Called when a component has been added. More... | |
Protected Member Functions | |
bool | loadLibrary (const std::string &filePath, bool reload) |
Load plugin library and add all contained plugins. More... | |
void | unloadLibrary (PluginLibrary *library) |
Unload plugin library. More... | |
void | addComponent (AbstractComponent *component) |
Add component. More... | |
void | updateComponents (PluginLibrary *library=nullptr) const |
Update components. More... | |
Protected Attributes | |
std::vector< std::string > | m_paths |
Plugin paths (all) More... | |
std::vector< std::string > | m_pathsInternal |
Plugin paths (internal) More... | |
std::vector< std::string > | m_pathsUser |
Plugin paths (user defined) More... | |
std::vector< AbstractComponent * > | m_components |
Available components, statically initialized once per component class via the COMPONENT macro. More... | |
std::map< std::string, AbstractComponent * > | m_componentsByName |
Available components by name. More... | |
std::map< std::string, std::unique_ptr< PluginLibrary > > | m_librariesByFilePath |
Plugin libraries by path. More... | |
Class for managing components and plugins.
This class manages a list of components, which can be instantiated dynamically. A component, which is in fact a factory object, can either be defined directly inside a library or application, or be loaded from a plugin library.
The component manager offers functionality to register components, list components (either all or per type), and get components by name. It also provides functions for search and loading plugin libraries, which in turn register components on the component manager.
cppexpose::ComponentManager::ComponentManager | ( | ) |
Constructor.
|
delete |
Copy constructor (deleted)
|
virtual |
Destructor.
|
static |
Get component registry.
|
delete |
Copy assignment operator (deleted)
const std::vector<std::string>& cppexpose::ComponentManager::pluginPaths | ( | PluginPathType | type = PluginPathType::UserDefined | ) | const |
Get plugin paths.
[in] | type | Plugin path type |
void cppexpose::ComponentManager::addPluginPath | ( | const std::string & | path, |
PluginPathType | type = PluginPathType::UserDefined |
||
) |
Add plugin path.
[in] | path | Plugin path |
[in] | type | Plugin path type |
void cppexpose::ComponentManager::removePluginPath | ( | const std::string & | path | ) |
Remove plugin path.
[in] | path | Plugin path |
void cppexpose::ComponentManager::scanPlugins | ( | const std::string & | suffix = "" , |
bool | reload = false |
||
) |
Scan for plugins and load all found ones.
[in] | suffix | Load only libraries with the given suffix. If empty, all libraries are loaded. |
[in] | reload | Reload plugin libraries that are already loaded? |
bool cppexpose::ComponentManager::loadPlugin | ( | const std::string & | filePath, |
bool | reload = true |
||
) |
Load plugin library.
[in] | filePath | Path to the plugin library |
[in] | reload | Reload plugin libraries that are already loaded? |
std::vector<PluginLibrary *> cppexpose::ComponentManager::pluginLibraries | ( | ) | const |
Get list of loaded plugin libraries.
const std::vector<AbstractComponent *>& cppexpose::ComponentManager::components | ( | ) | const |
Get list of available components.
std::vector< typename ComponentTypes< BaseType >::AbstractComponentType * > cppexpose::ComponentManager::components | ( | ) | const |
Get list of available components of a specific type.
References component(), m_components, and updateComponents().
AbstractComponent* cppexpose::ComponentManager::component | ( | const std::string & | name | ) | const |
Get component by name.
[in] | name | Component name |
Referenced by component(), and components().
ComponentTypes< BaseType >::AbstractComponentType * cppexpose::ComponentManager::component | ( | const std::string & | name | ) | const |
Get typed component.
[in] | name | Component name |
References component().
void cppexpose::ComponentManager::printComponents | ( | ) | const |
Print list of available components to log.
|
protected |
Load plugin library and add all contained plugins.
[in] | filePath | Path to library |
[in] | reload | Reload plugin libraries that are already loaded? |
|
protected |
Unload plugin library.
[in] | library | Plugin library |
|
protected |
Add component.
[in] | component | Component |
|
protected |
Update components.
[in] | library | Plugin library (can be null) |
Referenced by components().
Signal cppexpose::ComponentManager::componentsChanged |
Called when a component has been added.
|
protected |
Plugin paths (all)
|
protected |
Plugin paths (internal)
|
protected |
Plugin paths (user defined)
|
protected |
Available components, statically initialized once per component class via the COMPONENT macro.
Referenced by components().
|
protected |
Available components by name.
|
protected |
Plugin libraries by path.