SOFA API  b5aefb45
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...
 
template<class BaseClass >
void getEntriesDerivedFrom (std::vector< ClassEntry::SPtr > &result) const
 Fill the given vector with all the registered classes derived from BaseClass. More...
 
template<class BaseClass >
std::string listClassesDerivedFrom (const std::string &separator=", ") const
 Return the list of classes derived from BaseClass as a string. 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

◆ m_callbackOnCreate

OnCreateCallback sofa::core::ObjectFactory::m_callbackOnCreate
protected

◆ registry

ClassEntryMap sofa::core::ObjectFactory::registry
protected

Main class registry.

Constructor details

◆ ~ObjectFactory()

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

Function details

◆ AddAlias()

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

◆ addAlias()

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

◆ createObject()

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

Create an object given a context and a description.

◆ CreateObject()

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

Create an object given a context and a description.

◆ dump()

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

Dump the content of the factory to a text stream.

◆ dumpHTML()

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

Dump the content of the factory to a HTML stream.

◆ dumpXML()

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

Dump the content of the factory to a XML stream.

◆ getAllEntries()

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

Fill the given vector with all the registered classes.

◆ getEntriesDerivedFrom()

template<class BaseClass >
void sofa::core::ObjectFactory::getEntriesDerivedFrom ( std::vector< ClassEntry::SPtr > &  result) const

Fill the given vector with all the registered classes derived from BaseClass.

◆ getEntriesFromTarget()

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.

◆ getEntry()

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

Get an entry given a class name (or alias)

◆ getInstance()

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

Get the ObjectFactory singleton instance.

◆ hasCreator()

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

Test if a creator exists for a given classname.

◆ HasCreator()

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

Test if a creator exists for a given classname.

◆ listClassesDerivedFrom()

template<class BaseClass >
std::string sofa::core::ObjectFactory::listClassesDerivedFrom ( const std::string &  separator = ", ") const

Return the list of classes derived from BaseClass as a string.

◆ listClassesFromTarget()

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

Return the list of classes from a given target.

◆ resetAlias()

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

◆ ResetAlias()

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

◆ setCallback()

void sofa::core::ObjectFactory::setCallback ( OnCreateCallback  cb)
inline

◆ shortName()

std::string sofa::core::ObjectFactory::shortName ( std::string  classname)

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

◆ ShortName()

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