Interface Documentation
Version: 2.-1 (devel)
Public Types | Public Member Functions | Static Public Member Functions | List of all members
flecsi::utils::Factory_< RETURN, KEY, Args > Class Template Reference

Factory_ provides a generic object factory class. More...

Public Types

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.
 

Public Member Functions

 Factory_ (const Factory_ &f)=delete
 Constructor (hidden)
 
Factory_operator= (const Factory_ &)=delete
 Assignment operator (hidden)
 
bool registerType (const key_t key, const createHandler ch)
 
RETURN * create (const key_t key, Args &&... args)
 

Static Public Member Functions

static Factory_instance ()
 

Detailed Description

template<typename RETURN, typename KEY, typename... Args>
class flecsi::utils::Factory_< RETURN, KEY, Args >

Factory_ provides a generic object factory class.

Member Function Documentation

◆ create()

template<typename RETURN , typename KEY , typename... Args>
RETURN* flecsi::utils::Factory_< RETURN, KEY, Args >::create ( const key_t  key,
Args &&...  args 
)
inline

Create a new instance of the type associated with id.

Parameters
idThe integer id of the type to create.
argsThe 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>
static Factory_& flecsi::utils::Factory_< RETURN, KEY, Args >::instance ( )
inlinestatic

Return an instance of the Factory_ class. This uses a Meyer's singleton.

◆ registerType()

template<typename RETURN , typename KEY , typename... Args>
bool flecsi::utils::Factory_< RETURN, KEY, Args >::registerType ( const key_t  key,
const createHandler  ch 
)
inline

Register a type with the factory.

Parameters
idThe integer id to associate with this type. This id will be used to lookup the creation method.
chThe handler to call to create a new type associated with id.

The documentation for this class was generated from the following file: