Flow123d
release_2.2.0-914-gf1a3a4f
|
This class implements more general factory mechanism to construct classes. More...
#include <factory.hh>
Public Member Functions | |
shared_ptr< Type > const | create (string name, Arguments...arguments) const |
create an instance of a registered class More... | |
Static Public Member Functions | |
static Factory * | instance () |
Get the single instance of the factory. More... | |
template<class Child > | |
static int | register_class (string class_name) |
Register lambda function that calls default constructor of Type. More... | |
Private Member Functions | |
Factory () | |
Forbid default constructor. More... | |
Private Attributes | |
map< string, boost::any > | factory_registry_ |
the registry of factory functions More... | |
This class implements more general factory mechanism to construct classes.
One factory allows constructing derived classes of one base class. This class is determined by template parameter Type and all descendants must implement constructor with same parameters (given by template parameter Arguments). This constructor is called by factory.
All descendants must contain:
Simple example of usage:
Factory allow to accept constructor with one or more parameters. In this case Factory is also templated by these parameters. For example Factory< SomeBase, int, double > accepts constructors with two parameters (int, double).
If registered class is templated the following design have to be used:
Factory can be used in two ways:
For correct functionality must be used two macros defined in global_defs.h:
Definition at line 132 of file factory.hh.
|
inlineprivate |
Forbid default constructor.
Definition at line 150 of file factory.hh.
const shared_ptr< Type > Input::Factory< Type, Arguments >::create | ( | string | name, |
Arguments... | arguments | ||
) | const |
create an instance of a registered class
Definition at line 49 of file factory_impl.hh.
|
static |
Get the single instance of the factory.
Definition at line 27 of file factory_impl.hh.
|
static |
Register lambda function that calls default constructor of Type.
Definition at line 36 of file factory_impl.hh.
|
private |
the registry of factory functions
Definition at line 153 of file factory.hh.