Public Types | Static Public Member Functions | Protected Member Functions | Static Protected Attributes | Private Member Functions | List of all members
coil::Singleton< SingletonClass > Class Template Reference

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

Singletonoperator= (const Singleton &x)
 
 Singleton (const Singleton &x)
 

Detailed Description

template<class SingletonClass>
class coil::Singleton< SingletonClass >

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.

Member Typedef Documentation

template<class SingletonClass>
typedef ::coil::Mutex coil::Singleton< SingletonClass >::Mutex

Definition at line 110 of file Singleton.h.

template<class SingletonClass>
typedef SingletonClass* coil::Singleton< SingletonClass >::SingletonClassPtr

Definition at line 109 of file Singleton.h.

Constructor & Destructor Documentation

template<class SingletonClass>
coil::Singleton< SingletonClass >::Singleton ( )
inlineprotected

Constructor.

Constructor

Definition at line 162 of file Singleton.h.

template<class SingletonClass>
coil::Singleton< SingletonClass >::~Singleton ( )
inlineprotected

Destructor.

Destructor

Definition at line 179 of file Singleton.h.

template<class SingletonClass>
coil::Singleton< SingletonClass >::Singleton ( const Singleton< SingletonClass > &  x)
private

Member Function Documentation

template<class SingletonClass>
static SingletonClass& coil::Singleton< SingletonClass >::instance ( )
inlinestatic

Create instance.

Create instance.

Returns
Instances

Definition at line 131 of file Singleton.h.

template<class SingletonClass>
Singleton& coil::Singleton< SingletonClass >::operator= ( const Singleton< SingletonClass > &  x)
private

Member Data Documentation

template<class SingletonClass>
Singleton< SingletonClass >::SingletonClassPtr coil::Singleton< SingletonClass >::m_instance
staticprotected

SingletonClass object.

Definition at line 202 of file Singleton.h.

template<class SingletonClass>
Singleton< SingletonClass >::Mutex coil::Singleton< SingletonClass >::m_mutex
staticprotected

Mutual exclusion object.

Definition at line 193 of file Singleton.h.


The documentation for this class was generated from the following file:


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:59