ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
|
Factory template. More...
#include <Factory.hpp>
Public Types | |
using | pointer_type = std::unique_ptr< T > |
The returned pointer type. | |
using | builder_type = pointer_type(*)() |
Type of the constructor functions. | |
Public Member Functions | |
pointer_type | make (const std::string &name) const |
Construct an instance by name. | |
bool | has_builder (const std::string &name) const |
Check if the factory knows how to make name . | |
template<typename Derived > | |
void | register_new (const std::string &name) |
Register a new type with the default construction function. | |
const std::string & | type_name (T const &o) const |
Look up name for type. | |
Factory template.
Can be used to construct registered instances of classes derived from the base type (T
) by name. One registry per base type (T
). To get a new one, use new type ( struct NewT : public T {};
). To add a new type it has to be given a name an a function of type Factory<T>::builder_type
to create an instance has to be provided. The class contains a default implementation for the creation function (Factory<T>::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 78 of file Factory.hpp.
using Utils::Factory< T >::builder_type = pointer_type (*)() |
Type of the constructor functions.
Definition at line 83 of file Factory.hpp.
using Utils::Factory< T >::pointer_type = std::unique_ptr<T> |
The returned pointer type.
Definition at line 81 of file Factory.hpp.
|
inline |
Check if the factory knows how to make name
.
name | Given name to check. |
name
. Definition at line 104 of file Factory.hpp.
|
inline |
Construct an instance by name.
Definition at line 89 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, has to be unique in this Factory<T>. |
Definition at line 113 of file Factory.hpp.
Referenced by ScriptInterface::BondBreakage::initialize(), ScriptInterface::Shapes::initialize(), ScriptInterface::Accumulators::initialize(), ScriptInterface::Analysis::initialize(), ScriptInterface::CellSystem::initialize(), ScriptInterface::ClusterAnalysis::initialize(), ScriptInterface::CodeInfo::initialize(), ScriptInterface::CollisionDetection::initialize(), ScriptInterface::Constraints::initialize(), ScriptInterface::Coulomb::initialize(), ScriptInterface::Galilei::initialize(), ScriptInterface::Writer::initialize(), ScriptInterface::Integrators::initialize(), ScriptInterface::Interactions::initialize(), ScriptInterface::LeesEdwards::initialize(), ScriptInterface::Dipoles::initialize(), ScriptInterface::Math::initialize(), ScriptInterface::MPIIO::initialize(), ScriptInterface::PairCriteria::initialize(), ScriptInterface::Particles::initialize(), ScriptInterface::Profiler::initialize(), ScriptInterface::ReactionMethods::initialize(), ScriptInterface::System::initialize(), ScriptInterface::Thermostat::initialize(), and ScriptInterface::walberla::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. |
Definition at line 132 of file Factory.hpp.