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. | |
Protected Member Functions | |
Singleton () | |
Constructor. | |
~Singleton () | |
Destructor. | |
Static Protected Attributes | |
static SingletonClass * | m_instance |
SingletonClass object. | |
static coil::Mutex | m_mutex |
Mutual exclusion object. | |
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.
coil::Singleton< SingletonClass >::Singleton | ( | ) | [inline, protected] |
coil::Singleton< SingletonClass >::~Singleton | ( | ) | [inline, protected] |
coil::Singleton< SingletonClass >::Singleton | ( | const Singleton< SingletonClass > & | x | ) | [private] |
static SingletonClass& coil::Singleton< SingletonClass >::instance | ( | ) | [inline, static] |
Singleton& coil::Singleton< SingletonClass >::operator= | ( | const Singleton< SingletonClass > & | x | ) | [private] |
Singleton< SingletonClass >::SingletonClassPtr coil::Singleton< SingletonClass >::m_instance [static, protected] |
SingletonClass object.
Definition at line 202 of file Singleton.h.
Singleton< SingletonClass >::Mutex coil::Singleton< SingletonClass >::m_mutex [static, protected] |
Mutual exclusion object.
Definition at line 193 of file Singleton.h.