Factory_ provides a generic object factory class.
More...
|
using | createHandler = RETURN *(*)(Args... args) |
| Function pointer type for creation method.
|
|
using | key_t = KEY |
| Map key type.
|
|
using | map_t = std::map< key_t, createHandler > |
| Map type to associate ids and creation methods.
|
|
template<typename RETURN, typename KEY, typename... Args>
class flecsi::utils::Factory_< RETURN, KEY, Args >
Factory_ provides a generic object factory class.
◆ create()
template<typename RETURN , typename KEY , typename... Args>
Create a new instance of the type associated with id.
- Parameters
-
id | The integer id of the type to create. |
args | The arguments to pass to the creation method. Note: The argument list uses a variadic template parameter to forward the arguments to the creation method. This does not mean that the creation method needs to have support for variadic argument lists. The std::forward method will expand the arguments appropriately. |
Note: Also note the use of the rvalue reference, "Args &&". This allows support of any create signature with perfect forwarding of the arguments. Cool!!! The improved type inference in C++0x means that the signature can be automatically detected from where this method is called.
If you try to use this passing lvalues for the args, the compiler will complain that it can't convert from an lvalue to an rvalue reference. If this happens, just wrap the argument in std::move(), like: factory_t::instance().create(id, std::move(my_lvalue_arg))
This will statically cast the lvalue to an rvalue reference and everything will be good.
◆ instance()
template<typename RETURN , typename KEY , typename... Args>
Return an instance of the Factory_ class. This uses a Meyer's singleton.
◆ registerType()
template<typename RETURN , typename KEY , typename... Args>
Register a type with the factory.
- Parameters
-
id | The integer id to associate with this type. This id will be used to lookup the creation method. |
ch | The handler to call to create a new type associated with id. |
The documentation for this class was generated from the following file:
- /home/bergen/devel/tuxfan/flecsi/flecsi/utils/factory.hh