sofa::core::ObjectFactory Class Reference

Main class used to register and dynamically create objects. More...

#include <ObjectFactory.h>

Collaboration diagram for sofa::core::ObjectFactory:

Collaboration graph
[legend]

Data Structures

class  ClassEntry
 Record storing information about a class. More...
class  Creator
 Abstract interface of objects used to create instances of a given type. More...

Public Member Functions

ClassEntry * getEntry (std::string classname)
 Get an entry given a class name (or alias).
void getAllEntries (std::vector< ClassEntry * > &result)
 Fill the given vector with all the registered classes.
bool addAlias (std::string name, std::string result, bool force=false, ClassEntry **previous=NULL)
 Add an alias name for an already registered class.
void resetAlias (std::string name, ClassEntry *previous)
 Reset an alias to a previous state.
objectmodel::BaseObject * createObject (objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
 Create an object given a context and a description.
void dump (std::ostream &out=std::cout)
 Dump the content of the factory to a text stream.
void dumpXML (std::ostream &out=std::cout)
 Dump the content of the factory to a XML stream.
void dumpHTML (std::ostream &out=std::cout)
 Dump the content of the factory to a HTML stream.

Static Public Member Functions

static ObjectFactory * getInstance ()
 Get the ObjectFactory singleton instance.
static objectmodel::BaseObject * CreateObject (objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
static bool AddAlias (std::string name, std::string result, bool force=false, ClassEntry **previous=NULL)
static void ResetAlias (std::string name, ClassEntry *previous)

Protected Attributes

std::map< std::string,
ClassEntry * > 
registry
 Main class registry.

Detailed Description

Main class used to register and dynamically create objects.

It uses the Factory design pattern, where each class is registered in a map, and dynamically retrieved given the type name.

It also stores metainformation on each classes, such as description, authors, license, and available template types.

See also:
RegisterObject for how new classes should be registered.

Definition at line 74 of file ObjectFactory.h.


Member Function Documentation

static bool sofa::core::ObjectFactory::AddAlias ( std::string  name,
std::string  result,
bool  force = false,
ClassEntry **  previous = NULL 
) [inline, static]

Add an alias name for an already registered class.

Parameters:
name name of the new alias
result class pointed to by the new alias
force set to true if this method should override any entry already registered for this name
previous (output) previous ClassEntry registered for this name

Definition at line 153 of file ObjectFactory.h.

References addAlias(), force, and getInstance().

Referenced by sofa::gui::qt::viewer::qtogre::QtOgreViewer::EnableViewer(), sofa::gui::qt::viewer::qt::QtViewer::EnableViewer(), sofa::gui::qt::viewer::qgl::QtGLViewer::EnableViewer(), and main().

bool sofa::core::ObjectFactory::addAlias ( std::string  name,
std::string  result,
bool  force = false,
ClassEntry **  previous = NULL 
)

Add an alias name for an already registered class.

Parameters:
name name of the new alias
result class pointed to by the new alias
force set to true if this method should override any entry already registered for this name
previous (output) previous ClassEntry registered for this name

Definition at line 50 of file ObjectFactory.cpp.

References sofa::core::ObjectFactory::ClassEntry::aliases, and registry.

Referenced by AddAlias(), and sofa::core::RegisterObject::operator int().

static objectmodel::BaseObject* sofa::core::ObjectFactory::CreateObject ( objectmodel::BaseContext *  context,
objectmodel::BaseObjectDescription *  arg 
) [inline, static]

Create an object given a context and a description.

Definition at line 147 of file ObjectFactory.h.

References createObject(), and getInstance().

Referenced by sofa::simulation::PipelineImpl::init(), and sofa::simulation::tree::xml::ObjectElement::initNode().

objectmodel::BaseObject * sofa::core::ObjectFactory::createObject ( objectmodel::BaseContext *  context,
objectmodel::BaseObjectDescription *  arg 
)

void sofa::core::ObjectFactory::dump ( std::ostream &  out = std::cout  ) 

void sofa::core::ObjectFactory::dumpHTML ( std::ostream &  out = std::cout  ) 

void sofa::core::ObjectFactory::dumpXML ( std::ostream &  out = std::cout  ) 

void sofa::core::ObjectFactory::getAllEntries ( std::vector< ClassEntry * > &  result  ) 

Fill the given vector with all the registered classes.

Definition at line 146 of file ObjectFactory.cpp.

References sofa::core::ObjectFactory::ClassEntry::className, and registry.

Referenced by sofa::gui::qt::SofaModeler::SofaModeler().

ObjectFactory::ClassEntry * sofa::core::ObjectFactory::getEntry ( std::string  classname  ) 

Get an entry given a class name (or alias).

Definition at line 39 of file ObjectFactory.cpp.

References sofa::core::ObjectFactory::ClassEntry::className, and registry.

Referenced by sofa::core::RegisterObject::operator int(), and sofa::gui::qt::ModifyObject::setNode().

ObjectFactory * sofa::core::ObjectFactory::getInstance (  )  [static]

static void sofa::core::ObjectFactory::ResetAlias ( std::string  name,
ClassEntry *  previous 
) [inline, static]

Reset an alias to a previous state.

Parameters:
name name of the new alias
previous previous ClassEntry that need to be registered back for this name

Definition at line 159 of file ObjectFactory.h.

References getInstance(), and resetAlias().

Referenced by sofa::gui::qt::viewer::qtogre::QtOgreViewer::DisableViewer(), sofa::gui::qt::viewer::qt::QtViewer::DisableViewer(), and sofa::gui::qt::viewer::qgl::QtGLViewer::DisableViewer().

void sofa::core::ObjectFactory::resetAlias ( std::string  name,
ClassEntry *  previous 
)

Reset an alias to a previous state.

Parameters:
name name of the new alias
previous previous ClassEntry that need to be registered back for this name

Definition at line 79 of file ObjectFactory.cpp.

References registry.

Referenced by ResetAlias().


Field Documentation

std::map<std::string,ClassEntry*> sofa::core::ObjectFactory::registry [protected]

Main class registry.

Definition at line 116 of file ObjectFactory.h.

Referenced by addAlias(), createObject(), dump(), dumpHTML(), dumpXML(), getAllEntries(), getEntry(), and resetAlias().


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

Generated on Sun Nov 23 04:22:07 2008 for Sofa by  doxygen 1.5.7.1