17 #ifndef SURGSIM_FRAMEWORK_OBJECTFACTORY_INL_H 18 #define SURGSIM_FRAMEWORK_OBJECTFACTORY_INL_H 23 template <
class Derived>
26 boost::mutex::scoped_lock lock(m_mutex);
28 if (m_constructors.find(className) == m_constructors.end())
30 m_constructors[className] = boost::factory<std::shared_ptr<Derived>>();
39 boost::mutex::scoped_lock lock(m_mutex);
40 auto it = m_constructors.find(className);
41 if (it == m_constructors.end())
43 SURGSIM_FAILURE() <<
"ObjectFactory does not know about class called " << className;
47 return (it->second)();
51 template <
typename Base>
54 boost::mutex::scoped_lock lock(m_mutex);
55 auto it = m_constructors.find(className);
56 return (it != m_constructors.end());
60 template <
typename Base,
typename Parameter1>
61 template <
typename Derived>
64 boost::mutex::scoped_lock lock(m_mutex);
66 if (m_constructors.find(className) == m_constructors.end())
68 m_constructors[className] = boost::factory<std::shared_ptr<Derived>>();
74 template <
typename Base,
typename Parameter1>
76 const std::string& className,
77 const Parameter1& val)
79 boost::mutex::scoped_lock lock(m_mutex);
80 auto it = m_constructors.find(className);
82 if (it == m_constructors.end())
84 SURGSIM_FAILURE() <<
"ObjectFactory does not know about class called " << className;
88 return (it->second)(val);
91 template <
typename Base,
typename Parameter1>
94 boost::mutex::scoped_lock lock(m_mutex);
95 auto it = m_constructors.find(className);
96 return (it != m_constructors.end());
100 #endif // SURGSIM_FRAMEWORK_OBJECTFACTORY_INL_H std::shared_ptr< Base > create(const std::string &className, const Parameter1 &val)
Create an instance of a class based on the specific class name, whose constructor takes 1 parameter...
Definition: ObjectFactory-inl.h:75
#define SURGSIM_FAILURE()
Report that something very bad has happened and abort program execution.
Definition: Assert.h:95
bool registerClass(const std::string &className)
Register a class with the factory.
Definition: ObjectFactory-inl.h:62
bool isRegistered(const std::string &className) const
Check whether the class is registered in the factory.
Definition: ObjectFactory-inl.h:52
bool registerClass(const std::string &className)
Register a class with the factory.
Definition: ObjectFactory-inl.h:24
The header that provides the assertion API.
std::shared_ptr< Base > create(const std::string &className)
Create an instance of a class based on the specific class name.
Definition: ObjectFactory-inl.h:37
bool isRegistered(const std::string &className) const
Check whether the class is registered in the factory.
Definition: ObjectFactory-inl.h:92