![]() |
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
Factory template. More...
#include <Factory.hpp>
Public Types | |
| using | pointer_type = std::unique_ptr< Base > |
| The returned pointer type. | |
| using | builder_type = pointer_type(*)() |
| Type of the constructor functions. | |
Public Member Functions | |
| pointer_type | make (std::string const &name) const |
| Construct an instance by name. | |
| bool | has_builder (std::string const &name) const |
Check if the factory knows how to make name. | |
| template<typename Derived > | |
| void | register_new (std::string const &name) |
| Register a new type with the default construction function. | |
| auto const & | type_name (Base const &o) const |
| Look up name for type. | |
Factory template.
Can be used to construct registered instances of classes derived from the base type (Base) by name. Only one registry per base type (Base). To get a new one, use a new type ( struct Derived : public Base {}; ). To add a new type it has to be given a name an a function of type Factory<Base>::builder_type to create an instance has to be provided. The class contains a default implementation for the creation function (Factory<Base>::builder<Derived>) which just calls new to create an instance. A user provided function could be used to use a non-default constructor, or to allocate memory for the instance in a specific way, e.g. by placing all new instances in a vector.
Example usage:
Definition at line 73 of file Factory.hpp.
| using Utils::Factory< Base >::builder_type = pointer_type (*)() |
Type of the constructor functions.
Definition at line 78 of file Factory.hpp.
| using Utils::Factory< Base >::pointer_type = std::unique_ptr<Base> |
The returned pointer type.
Definition at line 76 of file Factory.hpp.
|
inline |
Check if the factory knows how to make name.
| name | Given name to check. |
name. Definition at line 99 of file Factory.hpp.
|
inline |
Construct an instance by name.
Definition at line 84 of file Factory.hpp.
Referenced by ScriptInterface::LocalContext::make_shared().
|
inline |
Register a new type with the default construction function.
| name | Given name for the type, must be unique. |
Definition at line 108 of file Factory.hpp.
Referenced by ScriptInterface::BondBreakage::initialize(), and ScriptInterface::Shapes::initialize().
|
inline |
Look up name for type.
For an object whose type can be created by the factory this returns the name under which it is registered. This will consider the dynamic type of polymorphic objects, e.g. it will return the name of the most derived type.
| o | Object whose type is to be considered. |
| std::out_of_range | If the type is not registered. |
Base can be made. Definition at line 130 of file Factory.hpp.