6#ifndef MATERIALX_FACTORY_H
7#define MATERIALX_FACTORY_H
14MATERIALX_NAMESPACE_BEGIN
21 using Ptr = shared_ptr<T>;
22 using CreatorFunction = Ptr (*)();
23 using CreatorMap = std::unordered_map<string, CreatorFunction>;
29 _creatorMap[typeName] = f;
35 return _creatorMap.find(typeName) != _creatorMap.end();
41 auto it = _creatorMap.find(typeName);
42 if (it != _creatorMap.end())
44 _creatorMap.erase(it);
50 Ptr
create(
const string& typeName)
const
52 auto it = _creatorMap.find(typeName);
53 return (it != _creatorMap.end() ? it->second() :
nullptr);
57 CreatorMap _creatorMap;
60MATERIALX_NAMESPACE_END
Library-wide includes and types.
Factory class for creating instances of classes given their type name.
Definition: Factory.h:19
void unregisterClass(const string &typeName)
Unregister a registered class.
Definition: Factory.h:39
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:27
bool classRegistered(const string &typeName) const
Determine if a class has been registered for a type name.
Definition: Factory.h:33
Ptr create(const string &typeName) const
Create a new instance of the class with given type name.
Definition: Factory.h:50