OpenMD 3.1
Molecular Dynamics in the Open
|
GenericFactory is a template based Object Factory Factory pattern is used to define an interface for creating an object. More...
#include "utils/GenericFactory.hpp"
Public Types | |
using | FactoryType = GenericFactory<Object, IdentType, Creator> |
using | CreatorMapType = std::map<IdentType, Creator> |
Public Member Functions | |
bool | registerCreator (const IdentType &id, Creator creator) |
Registers a creator with a type identifier. | |
bool | unregisterCreator (const IdentType &id) |
Unregisters the creator for the given type identifier. | |
Object * | createObject (const IdentType &id) |
Looks up the type identifier in the internal map. | |
std::vector< IdentType > | getIdents () |
Returns all of the registed type identifiers. | |
Static Public Member Functions | |
static FactoryType * | getInstance () |
Returns an instance of object factory. | |
Public Attributes | |
CreatorMapType | creatorMap_ |
Static Public Attributes | |
static FactoryType * | instance_ |
GenericFactory is a template based Object Factory Factory pattern is used to define an interface for creating an object.
Object | the base class of the hierarchy for which you provide the object factory. |
IdentType | the object that identifies the type of the concrete object. Default type is std::string * |
Creator | the callable entity that creates objects. This type must support operator(), taking no parameters and returning a pointer to Object. Default type is function pointer. |
Usage:
Or the user can use predefined macro DECLARE_CREATOR and REGISTER_CREATOR
Definition at line 157 of file GenericFactory.hpp.
using OpenMD::GenericFactory< Object, IdentType, Creator >::CreatorMapType = std::map<IdentType, Creator> |
Definition at line 160 of file GenericFactory.hpp.
using OpenMD::GenericFactory< Object, IdentType, Creator >::FactoryType = GenericFactory<Object, IdentType, Creator> |
Definition at line 159 of file GenericFactory.hpp.
|
inline |
Looks up the type identifier in the internal map.
If it is found, it invokes the corresponding creator for the type identifier and returns its result.
id | the identification of the concrete object |
Definition at line 200 of file GenericFactory.hpp.
|
inline |
Returns all of the registed type identifiers.
Definition at line 214 of file GenericFactory.hpp.
Referenced by OpenMD::operator<<().
|
inlinestatic |
Returns an instance of object factory.
Definition at line 166 of file GenericFactory.hpp.
|
inline |
Registers a creator with a type identifier.
id | the identification of the concrete object |
creator | the object responsible to create the concrete object |
Definition at line 177 of file GenericFactory.hpp.
|
inline |
Unregisters the creator for the given type identifier.
If the type identifier was previously registered, the function returns true.
id | the identification of the concrete object |
Definition at line 188 of file GenericFactory.hpp.
CreatorMapType OpenMD::GenericFactory< Object, IdentType, Creator >::creatorMap_ |
Definition at line 227 of file GenericFactory.hpp.
|
static |
Definition at line 226 of file GenericFactory.hpp.