6#ifndef MATERIALX_FACTORY_H
7#define MATERIALX_FACTORY_H
22 using Ptr = shared_ptr<T>;
23 using CreatorFunction = Ptr(*)();
24 using CreatorMap = std::unordered_map<string, CreatorFunction>;
30 _creatorMap[typeName] = f;
36 return _creatorMap.find(typeName) != _creatorMap.end();
42 auto it = _creatorMap.find(typeName);
43 if (it != _creatorMap.end())
45 _creatorMap.erase(it);
51 Ptr
create(
const string& typeName)
const
53 auto it = _creatorMap.find(typeName);
54 return (it != _creatorMap.end() ? it->second() :
nullptr);
58 CreatorMap _creatorMap;
Library-wide includes and types.
Factory class for creating instances of classes given their type name.
Definition: Factory.h:20
void unregisterClass(const string &typeName)
Unregister a registered class.
Definition: Factory.h:40
void registerClass(const string &typeName, CreatorFunction f)
Register a new class given a unique type name and a creator function for the class.
Definition: Factory.h:28
bool classRegistered(const string &typeName) const
Determine if a class has been registered for a type name.
Definition: Factory.h:34
Ptr create(const string &typeName) const
Create a new instance of the class with given type name.
Definition: Factory.h:51