Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
drwnFactory< U > Class Template Reference

Templated factory for creating or cloning objects for a particular base class. More...

Public Member Functions

void registerClass (const char *name, drwnCreatorFcn fcn)
 register a class and creator function
void unregisterClass (const char *name)
 unregister a previously registered class
list< string > getRegisteredClasses () const
 get a list of all registered classes
U * create (const char *name) const
 create a default object
U * createFromXML (drwnXMLNode &xml) const
 create an object from an XML node
U * createFromFile (const char *filename) const
 create an object from file
void dump () const
 dump the contents of the registery for debugging

Static Public Member Functions

static drwnFactory< U > & get ()
 get the factory

Protected Types

typedef U *(* drwnCreatorFcn )(void)

Protected Member Functions

 drwnFactory ()
 singleton class so hide constructor

Protected Attributes

bool _initialized
map< string, drwnCreatorFcn > _registry

Detailed Description

template<typename U>
class drwnFactory< U >

Templated factory for creating or cloning objects for a particular base class.

The base class must be default constructable and implement an XML load function (e.g., be derived from drwnWriteable).

Each derived object should register with factory using the register function, for example,

drwnClassifier *createMyClassifier() { return new myClassifier(); }
drwnFactory<drwnClassifier>::get().registerClass("myClassifier", createMyClassifier);

The macro DRWN_FACTORY_REGISTER(U, T) provides a short way to register class T in factory drwnFactory<U>.

Built-in Darwin classes are (statically) registered on construction using the drwnFactoryTraits class. External (i.e., add-on) factory object should be explicitly registered.

The documentation for this class was generated from the following file: