ISingleton.h

Go to the documentation of this file.
00001 
00008 /* Copyright, 2004 Werewolf
00009  *
00010  * This file is part of Werewolf.
00011  * Werewolf is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2, or (at your option)
00014  * any later version.
00015 
00016  * Werewolf is distributed in the hope that it will be useful, but
00017  * WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00019  * General Public License for more details.
00020 
00021  * You should have received a copy of the GNU General Public License
00022  * along with Werewolf; see the file COPYING. If not, write to the
00023  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00024  * MA 02111-1307, USA.
00025  */
00026 
00027 #ifndef __ISINGLETON_H__
00028 #define __ISINGLETON_H__
00029 
00030 //
00031 // System Includes
00032 //
00033 
00034 //
00035 // NeL Includes
00036 //
00037 #include <nel/misc/debug.h>
00038 
00039 //
00040 // Werewolf Includes
00041 //
00042 
00043 //
00044 // Class
00045 //
00046 
00047 namespace WWCOMMON {
00048 
00057 template<class T>
00058 class ISingleton {
00059 public:
00060     
00061     static T &instance() {
00062         if(!m_Instance) {
00063             m_Instance = new T;
00064             nlassert(m_Instance);
00065         }
00066         return *m_Instance;
00067     }
00068 
00069     static T *getInstancePtr() {
00070         if(!m_Instance) {
00071             m_Instance = new T;
00072             nlassert(m_Instance);
00073         }
00074         return m_Instance;
00075     }
00076     
00077     static void uninstance() {
00078         if(m_Instance) {
00079             delete m_Instance;
00080             m_Instance = 0;
00081         }
00082     }
00083     
00084 protected:
00085     
00086     ISingleton() {}
00087     
00088     static T *m_Instance;
00089 };
00090 
00091 template <class T>
00092 T* ISingleton<T>::m_Instance = 0;
00093 
00094 }; // END OF NAMESPACE WWCOMMON
00095 
00096 #endif // __ISINGLETON_H__

Generated on Mon Jan 11 12:03:39 2010 for Werewolf by  doxygen 1.6.1