BWAPI
SnippyHolloW-BroodwarBotQ-f01ab56/src/Utils/CSingleton.h
Go to the documentation of this file.
00001 #pragma once
00002 #ifndef NULL
00003 #define NULL 0
00004 #endif
00005 
00006 template <class T>
00007 class CSingleton
00008 {
00009 public :
00010 
00011     //----------------------------------------------------------------
00012     // Return the unique instance of the class
00013     //----------------------------------------------------------------
00014     static T& Instance()
00015     {
00016         if (!Inst)
00017             Inst = new T;
00018 
00019         return *Inst;
00020     }
00021 
00022     //----------------------------------------------------------------
00023     // Destroy the unique instance of the class
00024     //----------------------------------------------------------------
00025     static void Destroy()
00026     {
00027         delete Inst;
00028         Inst = NULL;
00029     }
00030 
00031 protected :
00032 
00033     //----------------------------------------------------------------
00034     // Constructor by default
00035     //----------------------------------------------------------------
00036     CSingleton() {}
00037 
00038     //----------------------------------------------------------------
00039     // Destructor
00040     //----------------------------------------------------------------
00041     ~CSingleton() {}
00042 
00043     //----------------------------------------------------------------
00044     // Member data
00045     //----------------------------------------------------------------
00046     static T* Inst; // Instance de la classe
00047 
00048 private :
00049     //----------------------------------------------------------------
00050     // Copy forbiden
00051     //----------------------------------------------------------------
00052     CSingleton(CSingleton&);
00053     void operator =(CSingleton&);
00054 };
00055 
00056 //----------------------------------------------------------------
00057 // Declaration of the static variable
00058 //----------------------------------------------------------------
00059 template <class T> T* CSingleton<T>::Inst = NULL;
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines