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

◆ Mutex

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

Definition at line 110 of file Singleton.h.

◆ SingletonClassPtr

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

Definition at line 109 of file Singleton.h.

Constructor & Destructor Documentation

◆ Singleton() [1/2]

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

Constructor.

Constructor

Definition at line 162 of file Singleton.h.

◆ ~Singleton()

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

Destructor.

Destructor

Definition at line 179 of file Singleton.h.

◆ Singleton() [2/2]

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

Member Function Documentation

◆ instance()

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

Create instance.

Create instance.

Returns
Instances

Definition at line 131 of file Singleton.h.

◆ operator=()

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

Member Data Documentation

◆ m_instance

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

SingletonClass object.

Definition at line 202 of file Singleton.h.

◆ m_mutex

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 Feb 28 2022 23:00:46