|
|
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.
typedef Element* (*Callback) (const char*) | (*Callback) |
typedef map<string,Callback> Map | Map |
ElementFactory ()
| ElementFactory |
UnknownElement (class) | UnknownElement |
When creating an element of a type which has no registered creation callback with the factory.
void add (const string& key, Callback cb)
| add |
Register a callback with the factory.
Parameters:
key | the element id/type. Must be unique. |
cb | function to be called when the element must be created. |
Element* create (const string& key, const char* arg)
| create |
Create an element.
Parameters:
key | the type of element that needs to be created. |
arg | initial value of element. If null, a default is assigned. |
Returns: the requested element. Caller is responsible for deletion.
bool can_create (const string& key)
| can_create |
[static]
Checks whether a type exists.
Parameters:
key | the element to check for. |
Returns: true if the element can be create via the factory.