Gnash
0.8.10
|
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. | |
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 GnashFactory & | instance () |
Get the GnashFactory singleton. |
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().
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. |
typedef T*(* gnash::GnashFactory::CreateHandler)() |
typedef std::map<std::string, CreateHandler> gnash::GnashFactory::Handlers |
typedef Key gnash::GnashFactory::key_type |
typedef T gnash::GnashFactory::value_type |
T* gnash::GnashFactory::get | ( | const Key & | name | ) | [inline] |
Return a Handler identified by a name.
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. |
static GnashFactory& gnash::GnashFactory::instance | ( | ) | [inline, static] |
Get the GnashFactory singleton.
References gnash::key::m.
Referenced by gnash::GnashFactory::RegisterHandler::RegisterHandler(), gnash::Player::run(), and main().
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.
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. |
References gnash::key::r.
Referenced by gnash::GnashFactory::RegisterHandler::RegisterHandler().