Classes | Public Types | Public Member Functions | Static Public Member Functions

gnash::GnashFactory< T, Init, Key > Class Template Reference

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

#include <GnashFactory.h>

List of all members.

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.
T * get (const Key &name)
 Return a Handler identified by a name.
void registerHandler (const Key &name, CreateHandler r)
 Register a Handler with a particular name.

Static Public Member Functions

static GnashFactoryinstance ()
 Get the GnashFactory singleton.

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:
T The base type to be produced by the factory
Init An object whose constructor ensures that the elements are registered. This helps avoid problems with unpredictable static initialization.
Key The 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:
name The 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 (  )  [inline, static]

Get the GnashFactory singleton.

References gnash::key::T.

Referenced by main(), and gnash::Player::run().

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.

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:
name The name to register the Handler under. Duplicated names will replace previous handlers!
r A pointer to a function that will return the Handler when called.

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