Go to the documentation of this file.
16 #ifndef SURGSIM_FRAMEWORK_SHAREDINSTANCE_INL_H
17 #define SURGSIM_FRAMEWORK_SHAREDINSTANCE_INL_H
22 #include <boost/thread/mutex.hpp>
23 #include <boost/thread/locks.hpp>
35 m_instanceCreator(defaultInstanceCreator())
41 m_instanceCreator(instanceCreator)
53 boost::lock_guard<boost::mutex> lock(m_mutex);
54 std::shared_ptr<T> instance = m_weakInstance.lock();
57 instance = createInstance();
58 m_weakInstance = instance;
60 return std::move(instance);
66 std::shared_ptr<T> instance = m_instanceCreator();
68 return std::move(instance);
74 return []() {
return std::make_shared<T>(); };
81 #endif // SURGSIM_FRAMEWORK_SHAREDINSTANCE_INL_H
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
~SharedInstance()
Destroy the container and the data it contains.
Definition: SharedInstance-inl.h:46
std::shared_ptr< T > createInstance()
Creates an object instance.
Definition: SharedInstance-inl.h:64
static InstanceCreator defaultInstanceCreator()
Creates a function that can create an instance using std::make_shared<T>().
Definition: SharedInstance-inl.h:72
Definition: CompoundShapeToGraphics.cpp:29
std::shared_ptr< T > get()
Gets the shared object instance.
Definition: SharedInstance-inl.h:51
SharedInstance()
Create the SharedInstance object used to manage the shared instance.
Definition: SharedInstance-inl.h:34
std::function< std::shared_ptr< T >)> InstanceCreator
A type that can hold a function object or lambda that takes no arguments and returns std::shared_ptr<...
Definition: SharedInstance.h:109