cppexpose  1.0.0.b785e04f23b8
C++ library for type introspection, reflection, and scripting interface
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
cppexpose::ComponentManager Class Reference

Class for managing components and plugins. More...

#include <cppexpose/include/cppexpose/plugin/ComponentManager.h>

Collaboration diagram for cppexpose::ComponentManager:
Collaboration graph
[legend]

Public Member Functions

 ComponentManager ()
 Constructor. More...
 
 ComponentManager (const ComponentManager &)=delete
 Copy constructor (deleted) More...
 
virtual ~ComponentManager ()
 Destructor. More...
 
ComponentManageroperator= (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...
 
AbstractComponentcomponent (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 ComponentRegistryregistry ()
 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

cppexpose::ComponentManager::ComponentManager ( )

Constructor.

cppexpose::ComponentManager::ComponentManager ( const ComponentManager )
delete

Copy constructor (deleted)

virtual cppexpose::ComponentManager::~ComponentManager ( )
virtual

Destructor.

Member Function Documentation

static ComponentRegistry& cppexpose::ComponentManager::registry ( )
static

Get component registry.

Returns
Component registry
ComponentManager& cppexpose::ComponentManager::operator= ( const ComponentManager )
delete

Copy assignment operator (deleted)

const std::vector<std::string>& cppexpose::ComponentManager::pluginPaths ( PluginPathType  type = PluginPathType::UserDefined) const

Get plugin paths.

Parameters
[in]typePlugin path type
Returns
List of paths that are searched for plugins
void cppexpose::ComponentManager::addPluginPath ( const std::string &  path,
PluginPathType  type = PluginPathType::UserDefined 
)

Add plugin path.

Parameters
[in]pathPlugin path
[in]typePlugin path type
Remarks
If path is empty or already in the path list, the path list is not changed. If no plugin path is provided, the default application path is used. The type must be either UserDefined or Internal, calls to addPluginPath with PluginPathType::All are ignored.
void cppexpose::ComponentManager::removePluginPath ( const std::string &  path)

Remove plugin path.

Parameters
[in]pathPlugin path
void cppexpose::ComponentManager::scanPlugins ( const std::string &  suffix = "",
bool  reload = false 
)

Scan for plugins and load all found ones.

Parameters
[in]suffixLoad only libraries with the given suffix. If empty, all libraries are loaded.
[in]reloadReload plugin libraries that are already loaded?
bool cppexpose::ComponentManager::loadPlugin ( const std::string &  filePath,
bool  reload = true 
)

Load plugin library.

Parameters
[in]filePathPath to the plugin library
[in]reloadReload plugin libraries that are already loaded?
Returns
'true' if library has been loaded successfully, else 'false'
std::vector<PluginLibrary *> cppexpose::ComponentManager::pluginLibraries ( ) const

Get list of loaded plugin libraries.

Returns
List of plugin libraries
const std::vector<AbstractComponent *>& cppexpose::ComponentManager::components ( ) const

Get list of available components.

Returns
List of components
template<typename BaseType >
std::vector< typename ComponentTypes< BaseType >::AbstractComponentType * > cppexpose::ComponentManager::components ( ) const

Get list of available components of a specific type.

Returns
List of typed components

References component(), m_components, and updateComponents().

AbstractComponent* cppexpose::ComponentManager::component ( const std::string &  name) const

Get component by name.

Parameters
[in]nameComponent name
Returns
Pointer to the component, nullptr if no component with that name exists

Referenced by component(), and components().

template<typename BaseType >
ComponentTypes< BaseType >::AbstractComponentType * cppexpose::ComponentManager::component ( const std::string &  name) const

Get typed component.

Parameters
[in]nameComponent name
Returns
Pointer to the component, nullptr if component doesn't exist or has the wrong type

References component().

void cppexpose::ComponentManager::printComponents ( ) const

Print list of available components to log.

bool cppexpose::ComponentManager::loadLibrary ( const std::string &  filePath,
bool  reload 
)
protected

Load plugin library and add all contained plugins.

Parameters
[in]filePathPath to library
[in]reloadReload plugin libraries that are already loaded?
Returns
'true' if library has been loaded successfully, else 'false'
void cppexpose::ComponentManager::unloadLibrary ( PluginLibrary library)
protected

Unload plugin library.

Parameters
[in]libraryPlugin library
Remarks
Before calling the function, it must be made sure that the plugin library is not used anymore, i.e., no instances of the contained plugins must be remaining.
void cppexpose::ComponentManager::addComponent ( AbstractComponent component)
protected

Add component.

Parameters
[in]componentComponent
void cppexpose::ComponentManager::updateComponents ( PluginLibrary library = nullptr) const
protected

Update components.

Parameters
[in]libraryPlugin library (can be null)
Remarks
This function updates the component list by looking at the list of newly registered components and adding them to the component manager. If a library pointer is given, the found components are considered to belong to that library.

Referenced by components().

Member Data Documentation

Signal cppexpose::ComponentManager::componentsChanged

Called when a component has been added.

std::vector<std::string> cppexpose::ComponentManager::m_paths
protected

Plugin paths (all)

std::vector<std::string> cppexpose::ComponentManager::m_pathsInternal
protected

Plugin paths (internal)

std::vector<std::string> cppexpose::ComponentManager::m_pathsUser
protected

Plugin paths (user defined)

std::vector<AbstractComponent *> cppexpose::ComponentManager::m_components
protected

Available components, statically initialized once per component class via the COMPONENT macro.

Referenced by components().

std::map<std::string, AbstractComponent *> cppexpose::ComponentManager::m_componentsByName
protected

Available components by name.

std::map<std::string, std::unique_ptr<PluginLibrary> > cppexpose::ComponentManager::m_librariesByFilePath
protected

Plugin libraries by path.


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