Go to the documentation of this file.
16 #ifndef SURGSIM_FRAMEWORK_OBJECTFACTORY_H
17 #define SURGSIM_FRAMEWORK_OBJECTFACTORY_H
23 #include <boost/function.hpp>
24 #include <boost/functional/factory.hpp>
25 #include <boost/thread/mutex.hpp>
39 template <
typename Base>
48 template <
typename Derived>
55 std::shared_ptr<Base>
create(
const std::string& className);
82 template <
typename Base,
typename Parameter1>
91 template <
typename Derived>
99 std::shared_ptr<Base>
create(
const std::string& className,
const Parameter1& val);
108 typedef boost::function<std::shared_ptr<Base>(
const Parameter1&)>
Constructor;
139 template <
class T,
class P>
164 #define SURGSIM_REGISTER(BaseClass, DerivedClass, ClassName) \
165 SURGSIM_USED_VARIABLE(bool SURGSIM_CONCATENATE(ClassName, Registered)) = \
166 BaseClass::getFactory().registerClass<DerivedClass>(#DerivedClass);
181 #define SURGSIM_STATIC_REGISTRATION(ClassName) \
182 extern bool SURGSIM_CONCATENATE(ClassName, Registered); \
183 SURGSIM_USED_VARIABLE(static bool SURGSIM_CONCATENATE(ClassName, IsRegistered)) = \
184 SURGSIM_CONCATENATE(ClassName, Registered);
186 #endif // SURGSIM_FRAMEWORK_OBJECTFACTORY_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
ObjectFactory1< T, P > FactoryType
Definition: ObjectFactory.h:143
bool isRegistered(const std::string &className) const
Check whether the class is registered in the factory.
Definition: ObjectFactory-inl.h:52
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:40
bool registerClass(const std::string &className)
Register a class with the factory.
Definition: ObjectFactory-inl.h:62
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:140
boost::function< std::shared_ptr< Base >const Parameter1 &)> Constructor
Definition: ObjectFactory.h:108
Definition: CompoundShapeToGraphics.cpp:29
boost::mutex m_mutex
Threadsafety for registration.
Definition: ObjectFactory.h:114
bool isRegistered(const std::string &className) const
Check whether the class is registered in the factory.
Definition: ObjectFactory-inl.h:92
static FactoryType & getFactory()
Definition: ObjectFactory.h:128
boost::function< std::shared_ptr< Base >)> Constructor
Definition: ObjectFactory.h:64
An object factory, once a class is registered with the factory it can be used to create instances of ...
Definition: ObjectFactory.h:83
boost::mutex m_mutex
Threadsafety for registration.
Definition: ObjectFactory.h:70
static FactoryType & getFactory()
Definition: ObjectFactory.h:146
ObjectFactory< T > FactoryType
Definition: ObjectFactory.h:125
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:122
bool registerClass(const std::string &className)
Register a class with the factory.
Definition: ObjectFactory-inl.h:24
std::map< std::string, Constructor > m_constructors
All the constructors.
Definition: ObjectFactory.h:111
std::map< std::string, Constructor > m_constructors
All the constructors.
Definition: ObjectFactory.h:67
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