Singleton template class. More...
#include <Singleton.h>
Public Types | |
typedef ::coil::Mutex | Mutex |
typedef SingletonClass * | SingletonClassPtr |
Static Public Member Functions | |
static SingletonClass & | instance () |
Create instance. More... | |
Protected Member Functions | |
Singleton () | |
Constructor. More... | |
~Singleton () | |
Destructor. More... | |
Static Protected Attributes | |
static SingletonClass * | m_instance |
SingletonClass object. More... | |
static coil::Mutex | m_mutex |
Mutual exclusion object. More... | |
Private Member Functions | |
Singleton & | operator= (const Singleton &x) |
Singleton (const Singleton &x) | |
Singleton template class.
This class template makes any classed into Singleton classes. Usage is as follows.
class A { // }; typedef coil::Singleton<A> A_;
In the any places, A& a(A_:instance()); // a has singular instance of A
Since the constructor of A is still public, however, user can create other instance of A as follows.
A* a = new A();
If you want to prohibit user from creating new instance, please inherit Singleton class (CRTP) and declare it as a friend class in the target class.
class A : public coil::Singleton<A> { public: private: A(){}
friend class coil::Singelton<A>; };
A* a = new A(); // compile error A& a(A::instance()); // This is the only method to get unique instance
Definition at line 106 of file Singleton.h.
typedef ::coil::Mutex coil::Singleton< SingletonClass >::Mutex |
Definition at line 110 of file Singleton.h.
typedef SingletonClass* coil::Singleton< SingletonClass >::SingletonClassPtr |
Definition at line 109 of file Singleton.h.
|
inlineprotected |
|
inlineprotected |
|
private |
|
inlinestatic |
|
private |
|
staticprotected |
SingletonClass object.
Definition at line 202 of file Singleton.h.
|
staticprotected |
Mutual exclusion object.
Definition at line 193 of file Singleton.h.