00001 00002 #ifndef __ISINGLETON_H__ 00003 #define __ISINGLETON_H__ 00004 /* 00005 Peon - Win32 Games Programming Library 00006 Copyright (C) 2002-2005 Erik Yuzwa 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public 00010 License as published by the Free Software Foundation; either 00011 version 2 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public 00019 License along with this library; if not, write to the Free 00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 00022 Erik Yuzwa 00023 peon AT wazooinc DOT com 00024 */ 00025 00026 /* Original version Copyright (C) Scott Bilas, 2000. 00027 * All rights reserved worldwide. 00028 * 00029 * This software is provided "as is" without express or implied 00030 * warranties. You may freely copy and compile this source into 00031 * applications you distribute provided that the copyright text 00032 * below is included in the resulting source code, for example: 00033 * "Portions Copyright (C) Scott Bilas, 2000" 00034 */ 00035 00036 #include "Peonstdafx.h" 00037 00038 namespace peon 00039 { 00040 00047 template <typename T> class PEONMAIN_API ISingleton 00048 { 00049 protected: 00050 00052 static T* ms_Singleton; 00053 00054 public: 00058 ISingleton( void ) 00059 { 00060 assert( !ms_Singleton ); 00061 ms_Singleton = static_cast< T* >( this ); 00062 } 00063 00067 ~ISingleton( void ) 00068 { assert( ms_Singleton ); ms_Singleton = 0; } 00069 00075 static T& getSingleton( void ) 00076 { assert( ms_Singleton ); return ( *ms_Singleton ); } 00077 00083 static T* getSingletonPtr( void ) 00084 { return ms_Singleton; } 00085 }; 00086 } 00087 00088 #endif