Gnash  0.8.10
Classes | Public Types | Public Member Functions | Static Public Member Functions
gnash::GnashFactory Class 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

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

typedef std::map<std::string, CreateHandler> gnash::GnashFactory::Handlers

Member Function Documentation

T* gnash::GnashFactory::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.
static GnashFactory& gnash::GnashFactory::instance ( ) [inline, static]
template<typename Iterator >
void gnash::GnashFactory::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::i, and gnash::key::_1.

void gnash::GnashFactory::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::RegisterHandler::RegisterHandler().


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