|
GMP 0.3.0
Generative Metaprogramming library for C++
|
A singleton-backed runtime factory that creates products by string key. More...
#include <object_factory.hpp>
Classes | |
| struct | register_type |
| Register a concrete product type under a string key. More... | |
Public Member Functions | |
| void | unregister_type (const std::string &key) |
| Remove a previously registered product key from the factory. | |
| AbstractProduct * | create (const std::string &key, const ConstructorArgs &... args) |
Create a concrete product with raw new semantics. | |
| std::shared_ptr< AbstractProduct > | create_shared (const std::string &key, const ConstructorArgs &... args) |
Create a concrete product and return it as std::shared_ptr. | |
| std::unique_ptr< AbstractProduct > | create_unique (const std::string &key, const ConstructorArgs &... args) |
Create a concrete product and return it as std::unique_ptr. | |
object_factory stores a mapping from textual identifiers to constructor callbacks for concrete types derived from AbstractProduct. Product types are typically registered through register_type or the GMP_FACTORY_REGISTER(...) helper macro, and can later be instantiated by calling create, create_shared, or create_unique.
The factory itself is a singleton so registrations and lookups operate on a single process-wide registry for a given <AbstractProduct, ConstructorArgs...> specialization.
| AbstractProduct | The abstract base type returned by the factory. |
| ConstructorArgs | The constructor argument types forwarded to concrete products. |
Definition at line 57 of file object_factory.hpp.
|
inline |
This function looks up key, invokes the registered constructor callback, and returns the resulting object as a raw pointer.
| key | The registered lookup key of the desired concrete type. |
| args | The constructor arguments forwarded to the concrete product. |
| std::invalid_argument | If key is not registered. |
create_shared() or create_unique() when ownership should be explicit. Definition at line 115 of file object_factory.hpp.
References gmp::enum_values().
Referenced by gmp::object_factory< AbstractProduct, ConstructorArgs >::create_shared(), and gmp::object_factory< AbstractProduct, ConstructorArgs >::create_unique().
|
inline |
| key | The registered lookup key of the desired concrete type. |
| args | The constructor arguments forwarded to the concrete product. |
| std::invalid_argument | If key is not registered. |
Definition at line 130 of file object_factory.hpp.
References gmp::object_factory< AbstractProduct, ConstructorArgs >::create(), and gmp::enum_values().
|
inline |
| key | The registered lookup key of the desired concrete type. |
| args | The constructor arguments forwarded to the concrete product. |
| std::invalid_argument | If key is not registered. |
Definition at line 144 of file object_factory.hpp.
References gmp::object_factory< AbstractProduct, ConstructorArgs >::create(), and gmp::enum_values().
|
inline |
Removing a key only affects future lookups. It does not modify or destroy any objects that were already created.
| key | The registered lookup key to erase. |
Definition at line 95 of file object_factory.hpp.
References gmp::enum_values().