Phongo Clap RT  1.0
Simple Raytracing Renderer
Singleton.h
Go to the documentation of this file.
1 
4 #ifndef _SINGLETON_H_
5 #define _SINGLETON_H_
6 
9 template <class T>
10 class Singleton
11 {
12 public:
13  //--------------------------------------------------------------------------------------------------------------------
15  //--------------------------------------------------------------------------------------------------------------------
16  static T* Instance()
17  {
18  if(!m_Instance)
19  {
20  m_Instance = new T;
21  }
22  return m_Instance;
23  }
24  //--------------------------------------------------------------------------------------------------------------------
26  //--------------------------------------------------------------------------------------------------------------------
27  static void destroyInstance()
28  {
29  delete m_Instance;
30  }
31 
32 private:
33  //--------------------------------------------------------------------------------------------------------------------
35  //--------------------------------------------------------------------------------------------------------------------
36  static T* m_Instance;
37 };
38 
39 // Set it initially to NULL
40 template<class T>
41 T* Singleton<T>::m_Instance = NULL;
42 
43 #endif // Singleton.h
static T * m_Instance
The instance of an object as an address.
Definition: Singleton.h:36
static void destroyInstance()
Destroys the instance thus freeing memory from the heap.
Definition: Singleton.h:27
Makes sure that no object is instanciated twice.
Definition: Singleton.h:10
static T * Instance()
If the instance is null it creates one, otherwise just returns the current one.
Definition: Singleton.h:16