Mirror reflection library 0.5.13
|
Helper class for more convenient instantiation of the factory template. More...
#include <mirror/factory.hpp>
Classes | |
struct | factory |
This meta-function creates a factory creating the Product . More... |
Helper class for more convenient instantiation of the factory template.
This template class can be used for a convenient creation of factories of the same kind but generating different types. If one wants to use the same kind of factory (i.e. using the same Manufacturer
, Suppliers
and Enumerator
templates and the same SourceTraits
parameter) to create different products, this template can be used in the following way:
// implement the class which will be passed as the SourceTraits parameter class my_factory_param { ... some implementation ... }; // implement the parameter manufacturer template template <class Product, class Param> class my_manufacturer { ... some implementation ... }; // implement the parameter supplier(s) template template <class Product, class Param> class my_suppliers { ... some implementation ... }; // implement the parameter enumerator template template <class Product, class Param> class my_enumerator { ... some implementation ... }; // use the factory_maker template to define a custom factory maker typedef factory_maker< my_manufacturer, my_suppliers, my_enumerator, my_factory_param > my_maker; // use the maker to create some factories my_maker::factory<my_type_1>::type my_type_1_factory; my_maker::factory<my_type_2>::type my_type_2_factory; my_maker::factory<my_type_2>::type my_type_3_factory; my_type_1* x1 = my_type_1_factory.new_(); my_type_2* x2 = my_type_2_factory.new_(); my_type_3* x3 = my_type_3_factory.new_();
Manufacturer | a class template which knows how to construct the parametes for the constructors. this template can for example use this factory template recursivelly for elaborated types and specify how to construct and initialize instances of the native C++ types. |
Suppliers | a class template which knows how to get existing instances to be supplied as parameters to the constructors. |
Enumerator | a class template which knows how to get enumerated values from external representations, like their names or values. |
SourceTraits | a parameter for the Manufacturer , Suppliers and Enumerator templates, which can be used for further configuration and fine-tuning of the generated factory. |