Gnash  0.8.11dev
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
gnash::GnashFactory< T, Init, Key > Class Template Reference

A generic factory class for registering and retrieving objects by key. More...

#include <GnashFactory.h>

Classes

struct  RegisterHandler
 

Public Types

typedef T value_type
 
typedef Key key_type
 
typedef T *(* CreateHandler) ()
 
typedef std::map< std::string, CreateHandlerHandlers
 

Public Member Functions

template<typename Iterator >
void listKeys (Iterator i)
 Dump the registered keys to the iterator. More...
 
T * get (const Key &name)
 Return a Handler identified by a name. More...
 
void registerHandler (const Key &name, CreateHandler r)
 Register a Handler with a particular name. More...
 

Static Public Member Functions

static GnashFactoryinstance ()
 Get the GnashFactory singleton. More...
 

Detailed Description

template<typename T, typename Init, typename Key>
class gnash::GnashFactory< T, Init, Key >

A generic factory class for registering and retrieving objects by key.

Note: there is only one GnashFactory for any combination of template arguments. It's not advisable to have more than one factory for any type. Note that this relies on static initialization, so do not call get() before or after main().

Template Parameters
TThe base type to be produced by the factory
InitAn object whose constructor ensures that the elements are registered. This helps avoid problems with unpredictable static initialization.
KeyThe type to be used as a key.

Member Typedef Documentation

§ CreateHandler

template<typename T , typename Init , typename Key >
typedef T*(* gnash::GnashFactory< T, Init, Key >::CreateHandler) ()

§ Handlers

template<typename T , typename Init , typename Key >
typedef std::map<std::string, CreateHandler> gnash::GnashFactory< T, Init, Key >::Handlers

§ key_type

template<typename T , typename Init , typename Key >
typedef Key gnash::GnashFactory< T, Init, Key >::key_type

§ value_type

template<typename T , typename Init , typename Key >
typedef T gnash::GnashFactory< T, Init, Key >::value_type

Member Function Documentation

§ get()

template<typename T , typename Init , typename Key >
T* gnash::GnashFactory< T, Init, Key >::get ( const Key &  name)
inline

Return a Handler identified by a name.

Parameters
nameThe name of the handler to return. An empty string will return the first available handler. If the string is not empty and no match is found, a null pointer will be returned.

References name.

§ instance()

template<typename T , typename Init , typename Key >
static GnashFactory& gnash::GnashFactory< T, Init, Key >::instance ( )
inlinestatic

§ listKeys()

template<typename T , typename Init , typename Key >
template<typename Iterator >
void gnash::GnashFactory< T, Init, Key >::listKeys ( Iterator  i)
inline

Dump the registered keys to the iterator.

Only usable with output iterators.

References gnash::key::_1, and gnash::key::i.

§ registerHandler()

template<typename T , typename Init , typename Key >
void gnash::GnashFactory< T, Init, Key >::registerHandler ( const Key &  name,
CreateHandler  r 
)
inline

Register a Handler with a particular name.

Parameters
nameThe name to register the Handler under. Duplicated names will replace previous handlers!
rA pointer to a function that will return the Handler when called.

References name, and gnash::key::r.

Referenced by gnash::GnashFactory< T, Init, Key >::RegisterHandler< Derived >::RegisterHandler().


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