SOFA API  c4ac86de
Open source framework for multi-physics simuation
sofa::core::ObjectFactory Class Reference

#include <ObjectFactory.h>

Classes

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

Protected Attributes

ClassEntryMap registry
 Main class registry. More...
 
OnCreateCallback m_callbackOnCreate
 

Public Member Functions

 ~ObjectFactory ()
 
ClassEntrygetEntry (std::string classname)
 Get an entry given a class name (or alias) More...
 
bool hasCreator (std::string classname)
 Test if a creator exists for a given classname. More...
 
std::string shortName (std::string classname)
 
void getAllEntries (std::vector< ClassEntry::SPtr > &result)
 Fill the given vector with all the registered classes. More...
 
void getEntriesFromTarget (std::vector< ClassEntry::SPtr > &result, std::string target)
 Fill the given vector with the registered classes from a given target. More...
 
std::string listClassesFromTarget (std::string target, std::string separator=", ")
 Return the list of classes from a given target. More...
 
bool addAlias (std::string name, std::string target, bool force=false, ClassEntry::SPtr *previous=nullptr)
 
void resetAlias (std::string name, ClassEntry::SPtr previous)
 
objectmodel::BaseObject::SPtr createObject (objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
 Create an object given a context and a description. More...
 
void dump (std::ostream &out=std::cout)
 Dump the content of the factory to a text stream. More...
 
void dumpXML (std::ostream &out=std::cout)
 Dump the content of the factory to a XML stream. More...
 
void dumpHTML (std::ostream &out=std::cout)
 Dump the content of the factory to a HTML stream. More...
 
void setCallback (OnCreateCallback cb)
 

Static Public Member Functions

static ObjectFactorygetInstance ()
 Get the ObjectFactory singleton instance. More...
 
static objectmodel::BaseObject::SPtr CreateObject (objectmodel::BaseContext *context, objectmodel::BaseObjectDescription *arg)
 Create an object given a context and a description. More...
 
static bool AddAlias (std::string name, std::string result, bool force=false, ClassEntry::SPtr *previous=nullptr)
 
static void ResetAlias (std::string name, ClassEntry::SPtr previous)
 
static bool HasCreator (std::string classname)
 Test if a creator exists for a given classname. More...
 
static std::string ShortName (std::string classname)
 

Attribute details

OnCreateCallback sofa::core::ObjectFactory::m_callbackOnCreate
protected
ClassEntryMap sofa::core::ObjectFactory::registry
protected

Main class registry.

Constructor details

sofa::core::ObjectFactory::~ObjectFactory ( )

Function details

bool sofa::core::ObjectFactory::addAlias ( std::string  name,
std::string  target,
bool  force = false,
ClassEntry::SPtr previous = nullptr 
)

Add an alias name for an already registered class

Parameters
namename of the new alias
targetclass pointed to by the new alias
forceset to true if this method should override any entry already registered for this name
previous(output) previous ClassEntry registered for this name
static bool sofa::core::ObjectFactory::AddAlias ( std::string  name,
std::string  result,
bool  force = false,
ClassEntry::SPtr previous = nullptr 
)
inlinestatic

Add an alias name for an already registered class

Parameters
namename of the new alias
targetclass pointed to by the new alias
forceset to true if this method should override any entry already registered for this name
previous(output) previous ClassEntry registered for this name
objectmodel::BaseObject::SPtr sofa::core::ObjectFactory::createObject ( objectmodel::BaseContext context,
objectmodel::BaseObjectDescription arg 
)

Create an object given a context and a description.

static objectmodel::BaseObject::SPtr sofa::core::ObjectFactory::CreateObject ( objectmodel::BaseContext context,
objectmodel::BaseObjectDescription arg 
)
inlinestatic

Create an object given a context and a description.

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

Dump the content of the factory to a text stream.

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

Dump the content of the factory to a HTML stream.

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

Dump the content of the factory to a XML stream.

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

Fill the given vector with all the registered classes.

void sofa::core::ObjectFactory::getEntriesFromTarget ( std::vector< ClassEntry::SPtr > &  result,
std::string  target 
)

Fill the given vector with the registered classes from a given target.

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

Get an entry given a class name (or alias)

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

Get the ObjectFactory singleton instance.

bool sofa::core::ObjectFactory::hasCreator ( std::string  classname)

Test if a creator exists for a given classname.

static bool sofa::core::ObjectFactory::HasCreator ( std::string  classname)
inlinestatic

Test if a creator exists for a given classname.

std::string sofa::core::ObjectFactory::listClassesFromTarget ( std::string  target,
std::string  separator = ", " 
)

Return the list of classes from a given target.

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

Reset an alias to a previous state

Parameters
namename of the new alias
previousprevious ClassEntry that need to be registered back for this name
static void sofa::core::ObjectFactory::ResetAlias ( std::string  name,
ClassEntry::SPtr  previous 
)
inlinestatic

Reset an alias to a previous state

Parameters
namename of the new alias
previousprevious ClassEntry that need to be registered back for this name
void sofa::core::ObjectFactory::setCallback ( OnCreateCallback  cb)
inline
std::string sofa::core::ObjectFactory::shortName ( std::string  classname)

Return the shortname for this classname. Empty string if no creator exists for this classname.

static std::string sofa::core::ObjectFactory::ShortName ( std::string  classname)
inlinestatic