Singleton.h
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_SINGLETON_H
21 #define COIL_SINGLETON_H
22 
23 #include <coil/Mutex.h>
24 #include <coil/Guard.h>
25 
26 namespace coil
27 {
105  template <class SingletonClass>
106  class Singleton
107  {
108  public:
109  typedef SingletonClass* SingletonClassPtr;
110  typedef ::coil::Mutex Mutex;
111 
131  static SingletonClass& instance()
132  {
133 
134  // DLC pattern
135  if (!m_instance)
136  {
138  if (!m_instance)
139  {
140  m_instance = new SingletonClass();
141  }
142  }
143  return *m_instance;
144  }
145 
146  protected:
163 
180 
181  private:
182  Singleton(const Singleton& x);
183  Singleton& operator=(const Singleton& x);
184 
185  protected:
194 
202  static SingletonClass* m_instance;
203  };
204 
205  template <class SingletonClass>
208 
209  template <class SingletonClass>
212 }; // namepsace coil
213 
214 #endif // COIL_SINGLETON_H
Singleton & operator=(const Singleton &x)
static coil::Mutex m_mutex
Mutual exclusion object.
Definition: Singleton.h:193
Mutex class.
::coil::Mutex Mutex
Definition: Singleton.h:110
static SingletonClass & instance()
Create instance.
Definition: Singleton.h:131
static SingletonClass * m_instance
SingletonClass object.
Definition: Singleton.h:202
Singleton template class.
Definition: Singleton.h:106
SingletonClass * SingletonClassPtr
Definition: Singleton.h:109
~Singleton()
Destructor.
Definition: Singleton.h:179
Singleton()
Constructor.
Definition: Singleton.h:162
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00