25template<
typename BaseType,
typename Type> BaseType *
CreateObject(){
return new Type();}
38 template<
typename Type>
void AddEntry(
const KeyType &key) {
39 registry_[key] = &CreateObject<BaseType, Type>;
49 BaseType *
Create(
const KeyType &key)
const{
50 typename RegistryMap::const_iterator entry =
registry_.find(key);
51 if (entry ==
registry_.end())
return NULL;
52 return (entry->second)();
60 typedef BaseType *(*CreateFunc)();
BaseType * CreateObject()
Template function for creating an instance of Type.
Definition: ObjectFactory.h:25
Generic factory for a class and its subclasses.
Definition: ObjectFactory.h:30
std::map< KeyType, CreateFunc > RegistryMap
Type used to store registered entries.
Definition: ObjectFactory.h:65
RegistryMap registry_
Map from an identifier to a creation function.
Definition: ObjectFactory.h:70
BaseType * Create(const KeyType &key) const
Creates an instance of some registered class.
Definition: ObjectFactory.h:49
void AddEntry(const KeyType &key)
Register a new entry.
Definition: ObjectFactory.h:38