7 #include <boost/foreach.hpp> 22 void FactoryStorage::destroy() {
27 FactoryStorage::FactoryStorage() : entityMap() {}
40 "Another entity class already defined with the same name. ",
41 "(while adding entity class <%s> inside the factory).",
44 "Another entity class already defined with the same name. " 45 "(while adding entity class <%s> inside the factory).",
51 "Bad entity constructor.");
54 dgDEBUG(30) <<
"Register entity <" << entname <<
"> in the factory." 66 "(while removing entity class <%s>).", entname.c_str());
68 "Entity class not defined yet. " 69 "(while removing entity class <%s>).",
72 dgDEBUG(30) <<
"Deregister entity <" << entname <<
"> from the factory." 80 const std::string &objname)
const {
81 dgDEBUG(15) <<
"New <" << classname <<
">Entity <" << objname <<
">" 84 EntityMap::const_iterator entPtr =
entityMap.find(classname);
88 " (while calling new_entity <%s>)", classname.c_str());
90 return entPtr->second(objname);
96 EntityMap::const_iterator lb =
entityMap.lower_bound(name);
102 typedef std::pair<std::string, EntityConstructor_ptr> iter_t;
103 BOOST_FOREACH (
const iter_t &entity,
entityMap)
104 outList.push_back(entity.first);
109 : entityName(entityClassName) {
void registerEntity(const std::string &entname, EntityConstructor_ptr ent)
Add a new entity to the factory.
static FactoryStorage * instance_
to the unique object of the class
This class represents an entity, i.e. a generic computational unit that provides input and output sig...
#define dgDEBUGOUT(level)
bool existEntity(const std::string &name) const
Check if an Entity associated with a particular name has already been registered. ...
void deregisterEntity(const std::string &entname)
Delete an entity from the factory.
#define dgDEBUGINOUT(level)
void listEntities(std::vector< std::string > &list) const
List the available entities.
void dgERRORF(const int, const char *,...)
const std::string entityName
Name of the entity registered when the instance has been initialized.
Entity *(* EntityConstructor_ptr)(const std::string &)
Function pointer providing an entity instance from its name.
EntityMap entityMap
The entity map storing information about how to instantiate an Entity.
~EntityRegisterer()
Unregister entity to the global factory.
Entity * newEntity(const std::string &classname, const std::string &objname) const
Instantiate (and allocate) an entity.
static FactoryStorage * getInstance()
Get pointer to unique object of the class.
Provides a way to create Entity objects from their class name.
#define dgDEBUGIN(level)
VP_DEBUG.
EntityRegisterer(const std::string &entityClassName, FactoryStorage::EntityConstructor_ptr maker)
Register entity to the global factory.