12 #include <boost/shared_ptr.hpp> 37 static T&
Instance(
bool a_delete =
false, T* a_new = NULL)
39 static boost::shared_ptr<T> theSingleInstance;
43 if (theSingleInstance)
45 theSingleInstance.reset();
50 if (NULL == theSingleInstance)
52 theSingleInstance.reset(a_new ? a_new :
new T);
55 if (theSingleInstance)
57 return *theSingleInstance;
61 return *theSingleInstance.get();
85 typedef boost::shared_ptr<T>
Ptr;
94 static Ptr
Instance(Ptr a_new = Ptr(),
bool a_delete =
false)
96 static boost::shared_ptr<T> theSingleInstance;
100 if (theSingleInstance)
102 theSingleInstance.reset();
109 if (NULL == theSingleInstance)
111 theSingleInstance = a_new;
114 return theSingleInstance;
Singleton which can share the same instance with other singletons.
static void Delete()
Delete the singleton instance.
static void Delete()
Delete the current instance.
static Ptr Instance(Ptr a_new=Ptr(), bool a_delete=false)
Get a singleton instance.
Base class for classes that follow the singleton pattern.
static T & Instance(bool a_delete=false, T *a_new=NULL)
Get the instance of the singleton.
boost::shared_ptr< T > Ptr
Instance pointer.