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 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.

template<class T> Element*  createSet (const set<T>& s)

createSet

Create a set from an STL set.

The objects contained in the set are converted to a string representation via an ostringstream.

Parameters:

sSTL set to be converted to ElemSet.

Returns: the requested ElemSet.


Generated by: pavlin on possum.icir.org on Wed Apr 13 21:53:12 2005, using kdoc $.