Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
caffa::Factory< BaseType, KeyType > Class Template Reference

#include <cafFactory.h>

Public Types

typedef std::map< KeyType, ObjectCreatorBase * >::iterator iterator_type
 

Public Member Functions

template<typename TypeToCreate >
bool registerCreator (const KeyType &key)
 
BaseType * create (const KeyType &key)
 
std::vector< KeyType > allKeys ()
 

Static Public Member Functions

static Factory< BaseType, KeyType > * instance ()
 

Detailed Description

template<typename BaseType, typename KeyType>
class caffa::Factory< BaseType, KeyType >

A generic Factory class template Usage: Simply add the classes that is supposed to be created by the factory by doing the folowing:

caffa::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key);

This must only be done once for each TypeToCreate. It will assert if you try to do it several times. This method returns a bool to make it possible to make this initialization as a static variable initialization. That is useful if you do not want a centralized registering (but rather making each class register itself):

static bool uniqueVarname = caffa::Factory<BaseType, KeyType>::instance()->registerCreator<TypeToCreate>(key);

You can also use the macro CAFFA_FACTORY_REGISTER(BaseType, TypeToCreate, KeyType, key)

See also cafUiFieldEditorHandle.h for an advanced example.

When you need an object:

BaseType* newObject = caffa::Factory<BaseType, KeyType>::instance()->create(key);


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