plugin  2.1.3
Runtime plugin loader and Ed25519 DSO signing for C++ applications
plugin::Creator< Base > Class Template Reference

Factory class for plugins. More...

#include <PluginCreator.hh>

Public Types

using DefaultFactory = std::function< Base *() >
 
using ConfigFactory = std::function< Base *(std::any const &) >
 

Public Member Functions

 Creator ()
 
 Creator (DefaultFactory defaultFn, bool isAlias=false)
 Constructor with default factory only (backward compatible). More...
 
 Creator (DefaultFactory defaultFn, ConfigFactory configFn, bool isAlias=false)
 Constructor with both default and config factories. More...
 
 Creator (Creator const &)=default
 
 Creator (Creator &&)=default
 
Creatoroperator= (Creator const &)=default
 
Creatoroperator= (Creator &&)=default
 
 ~Creator ()=default
 
Base * operator() ()
 Create an instance using the default (parameterless) factory. More...
 
Base * operator() (std::any const &config)
 Create an instance using a type-erased config. The config's actual type must match what was registered; a mismatch will throw std::bad_any_cast. More...
 
bool hasConfigFactory () const
 
bool isAlias () const
 

Private Attributes

DefaultFactory defaultFactory_
 
ConfigFactory configFactory_
 
bool alias_ = true
 

Detailed Description

template<class Base>
class plugin::Creator< Base >

Factory class for plugins.

Stores two factory callables:

  • A default factory: creates an instance with no arguments
  • A config factory: creates an instance from a type-erased std::any

The config factory is optional. If not provided, attempting to create with a config argument will throw std::runtime_error.

Template Parameters
BaseThe base class of the plugin hierarchy

Member Typedef Documentation

◆ DefaultFactory

template<class Base >
using plugin::Creator< Base >::DefaultFactory = std::function< Base*( ) >

◆ ConfigFactory

template<class Base >
using plugin::Creator< Base >::ConfigFactory = std::function< Base*( std::any const& ) >

Constructor & Destructor Documentation

◆ Creator() [1/5]

template<class Base >
plugin::Creator< Base >::Creator ( )
inline

◆ Creator() [2/5]

template<class Base >
plugin::Creator< Base >::Creator ( DefaultFactory  defaultFn,
bool  isAlias = false 
)
inline

Constructor with default factory only (backward compatible).

◆ Creator() [3/5]

template<class Base >
plugin::Creator< Base >::Creator ( DefaultFactory  defaultFn,
ConfigFactory  configFn,
bool  isAlias = false 
)
inline

Constructor with both default and config factories.

◆ Creator() [4/5]

template<class Base >
plugin::Creator< Base >::Creator ( Creator< Base > const &  )
default

◆ Creator() [5/5]

template<class Base >
plugin::Creator< Base >::Creator ( Creator< Base > &&  )
default

◆ ~Creator()

template<class Base >
plugin::Creator< Base >::~Creator ( )
default

Member Function Documentation

◆ operator=() [1/2]

template<class Base >
Creator& plugin::Creator< Base >::operator= ( Creator< Base > const &  )
default

◆ operator=() [2/2]

template<class Base >
Creator& plugin::Creator< Base >::operator= ( Creator< Base > &&  )
default

◆ operator()() [1/2]

template<class Base >
Base* plugin::Creator< Base >::operator() ( )
inline

Create an instance using the default (parameterless) factory.

Returns
Pointer to new instance, or nullptr if no default factory is set.

◆ operator()() [2/2]

template<class Base >
Base* plugin::Creator< Base >::operator() ( std::any const &  config)
inline

Create an instance using a type-erased config. The config's actual type must match what was registered; a mismatch will throw std::bad_any_cast.

Exceptions
std::runtime_errorif no config factory was registered
std::bad_any_castif the config type doesn't match

◆ hasConfigFactory()

template<class Base >
bool plugin::Creator< Base >::hasConfigFactory ( ) const
inline

◆ isAlias()

template<class Base >
bool plugin::Creator< Base >::isAlias ( ) const
inline

Member Data Documentation

◆ defaultFactory_

template<class Base >
DefaultFactory plugin::Creator< Base >::defaultFactory_
private

◆ configFactory_

template<class Base >
ConfigFactory plugin::Creator< Base >::configFactory_
private

◆ alias_

template<class Base >
bool plugin::Creator< Base >::alias_ = true
private

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