|
AstraLog-HPC
|
A generic object factory. More...
#include <GenericFactory.hpp>

Public Types | |
| using | AbstractProduct_type = AbstractProduct |
| The container for the rules. | |
| using | Identifier_type = Identifier |
| The identifier. | |
| using | Builder_type = Builder |
| The builder type. | |
| using | Container_type = std::unordered_map< Identifier, Builder_type > |
| Method to access the only instance of the factory. | |
Public Member Functions | |
| template<typename... Args> | |
| std::unique_ptr< AbstractProduct > | create (Identifier const &name, Args &&...args) const |
| Get the rule with given name . | |
| Builder | get (Identifier const &name) const |
| void | add (Identifier const &, Builder_type const &) |
| Register the given rule. | |
| std::vector< Identifier > | registered () const |
| Returns a list of registered rules. | |
| void | unregister (Identifier const &name) |
| Unregister a rule. | |
| void | clear () |
| clear the factory | |
| bool | empty () const |
| Test if factory has some items registered. | |
| Container_type const & | getStorage () const |
| Factory (Factory const &)=delete | |
| Deleted since it is a Singleton. | |
| Factory & | operator= (Factory const &)=delete |
| Deleted since it is a Singleton. | |
Static Public Member Functions | |
| static Factory & | Instance () |
Private Member Functions | |
| Factory ()=default | |
| Made private since it is a Singleton. | |
Private Attributes | |
| Container_type | _storage |
| It contains the actual object factory. | |
A generic object factory.
Freely inspired from the Alexandrescu Book.
It is implemented as a Singleton. The compulsory way to access a method is Factory::Instance().method(). Typically to access the factory one does
| AbstractProduct | The type of the base abstract class whose object are produced by the factory |
| Identifier | The identifier used to select the concrete object produced by the factory. It must have an ordering relation since they will be stored as key in a std::map |
| Builder | The type of the callable object that produces the the concrete object derived from AbstractProduct It may have arguments but its return type must be std::unique_ptr<AbstractProduct>. |
| An | astralog::RuleError if something goes wrong when querying the factory (unknown or doubly-registered identifier). |
| using GenericFactory::Factory< AbstractProduct, Identifier, Builder >::AbstractProduct_type = AbstractProduct |
The container for the rules.
| using GenericFactory::Factory< AbstractProduct, Identifier, Builder >::Builder_type = Builder |
The builder type.
The default is a function wrapper that returns a unique_ptr<AbstractProduct> and with no arguments.
| using GenericFactory::Factory< AbstractProduct, Identifier, Builder >::Container_type = std::unordered_map<Identifier, Builder_type> |
Method to access the only instance of the factory.
| using GenericFactory::Factory< AbstractProduct, Identifier, Builder >::Identifier_type = Identifier |
The identifier.
It is used to identify the rules.
|
delete |
Deleted since it is a Singleton.
|
privatedefault |
Made private since it is a Singleton.
| void GenericFactory::Factory< AbstractProduct, Identifier, Builder >::add | ( | Identifier const & | name, |
| Builder_type const & | func | ||
| ) |
Register the given rule.
|
inline |
clear the factory
| std::unique_ptr< AbstractProduct > GenericFactory::Factory< AbstractProduct, Identifier, Builder >::create | ( | Identifier const & | name, |
| Args &&... | args | ||
| ) | const |
Get the rule with given name .
The pointer is null if no rule is present.
| Args | Automatically deduced parameter pack, it is the list of types of the builder arguments. It may be empty. |
| name | The identifier |
| args | The arguments pack to be passed to the builder. It may be empty |
|
inline |
Test if factory has some items registered.
| Builder GenericFactory::Factory< AbstractProduct, Identifier, Builder >::get | ( | Identifier const & | name | ) | const |
Returns the builder
|
inline |
|
static |

|
delete |
Deleted since it is a Singleton.
| std::vector< Identifier > GenericFactory::Factory< AbstractProduct, Identifier, Builder >::registered | ( | ) | const |
Returns a list of registered rules.
|
inline |
Unregister a rule.
|
private |
It contains the actual object factory.