Singleton.hh

Go to the documentation of this file.
00001 // $Id: Singleton.hh,v 1.3 2007/04/27 01:54:32 jeremy Exp $
00002 
00003 #ifndef LCDD_SINGLETON_HH
00004 #define LCDD_SINGLETON_HH 1
00005 
00006 template<class T>
00007 class Singleton
00008 {
00009 public:
00010   static T* instance();
00011   void release();
00012   
00013   Singleton();
00014   ~Singleton();
00015   
00016 private:
00017   static T* m_singleton;
00018 };
00019 
00020 template<class T> T* Singleton<T>::m_singleton = 0;
00021 
00022 template<class T>
00023 Singleton<T>::Singleton()
00024 {}
00025 
00026 template<class T>
00027 Singleton<T>::~Singleton()
00028 {}
00029 
00030 template<class T>
00031 T* Singleton<T>::instance()
00032 {
00033   if (m_singleton == 0) {
00034     m_singleton = new T;
00035   }
00036   return m_singleton;
00037 }
00038 
00039 template<class T>
00040 void Singleton<T>::release ()
00041 {
00042   if (m_singleton == 0)
00043     return;
00044   delete m_singleton;
00045   m_singleton = 0;
00046 }
00047 
00048 #endif
00049 

Generated on Thu Nov 15 15:24:16 2007 for Simulator for the Linear Collider by  doxygen 1.5.4