class ElementFactory

A factory for creating elements based on their type. More...

 
LOGO
 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Types

Public Methods

Public Static Methods

Public Members


Detailed Description

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.

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:

keythe element id/type. Must be unique.
cbfunction to be called when the element must be created.
Element*  create (const string& key, const char* arg)

create

Create an element.

Parameters:

keythe type of element that needs to be created.
arginitial 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:

keythe element to check for.

Returns: true if the element can be create via the factory.


Generated by: bms on anglepoise.lon.incunabulum.net on Wed Jul 23 10:05:56 2008, using kdoc 2.0a54+XORP.