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,
CreateHandler
Handlers
 

Public Member Functions

template<typename Iterator >
void listKeys (Iterator i, typename boost::enable_if< boost::is_same< typename std::iterator_traits< Iterator >::iterator_category, std::output_iterator_tag > >::type *dummy=0)
 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 = void, typename Key = std::string>
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

template<typename T , typename Init = void, typename Key = std::string>
typedef T*(* gnash::GnashFactory< T, Init, Key >::CreateHandler)()
template<typename T , typename Init = void, typename Key = std::string>
typedef std::map<std::string, CreateHandler> gnash::GnashFactory< T, Init, Key >::Handlers
template<typename T , typename Init = void, typename Key = std::string>
typedef Key gnash::GnashFactory< T, Init, Key >::key_type
template<typename T , typename Init = void, typename Key = std::string>
typedef T gnash::GnashFactory< T, Init, Key >::value_type

Member Function Documentation

template<typename T , typename Init = void, typename Key = std::string>
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.
template<typename T , typename Init = void, typename Key = std::string>
static GnashFactory& gnash::GnashFactory< T, Init, Key >::instance ( )
inlinestatic
template<typename T , typename Init = void, typename Key = std::string>
template<typename Iterator >
void gnash::GnashFactory< T, Init, Key >::listKeys ( Iterator  i,
typename boost::enable_if< boost::is_same< typename std::iterator_traits< Iterator >::iterator_category, std::output_iterator_tag > >::type *  dummy = 0 
)
inline

Dump the registered keys to the iterator.

Only usable with output iterators.

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

template<typename T , typename Init = void, typename Key = std::string>
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 gnash::key::r.

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


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