|
xorp
|
A factory for creating elements based on their type. More...
#include <element_factory.hh>
Classes | |
| class | UnknownElement |
| Exception thrown if an Unknown element is being created. More... | |
Public Types | |
| typedef Element *(* | Callback )(const char *) |
| typedef map< string, Callback > | Map |
Public Member Functions | |
| void | add (const string &key, Callback cb) |
| Register a callback with the factory. | |
| Element * | create (const string &key, const char *arg) |
| Create an element. | |
Static Public Member Functions | |
| static bool | can_create (const string &key) |
| Checks whether a type exists. | |
Static Private Attributes | |
| static Map | _map |
| There is only one factory map. | |
| static RegisterElements | _regelems |
| A class which registers defined callbacks upon creation. | |
A factory for creating elements based on their type.
Elements are created via their string represented type. They are initialized via a c-style string. If this string is null, then a default value is assigned to the element.
Functions that perform the creation are registered with the factory at run-time.
An exception is throw on element creationg failure.
Similar to Dispatcher.
| void ElementFactory::add | ( | const string & | key, |
| Callback | cb | ||
| ) |
| bool ElementFactory::can_create | ( | const string & | key | ) | [static] |
| Element * ElementFactory::create | ( | const string & | key, |
| const char * | arg | ||
| ) |
ElementFactory::Map ElementFactory::_map [static, private] |
There is only one factory map.
Creating additional factory objects is therefore safe. No need to pass a global factory around in the various classes.
RegisterElements ElementFactory::_regelems [static, private] |
A class which registers defined callbacks upon creation.
Callbacks are thus registered once [static] and before the factory is actually used.