source: GTP/trunk/App/Demos/Geom/OgreStuff/include/CEGUI/CEGUISingleton.h @ 1812

Revision 1812, 2.6 KB checked in by gumbau, 18 years ago (diff)
RevLine 
[1812]1/************************************************************************
2        filename:       CEGUISingleton.h
3        created:        22/2/2004
4        author:         Paul D Turner
5       
6        purpose:        Singleton Base Class
7*************************************************************************/
8/*************************************************************************
9    Crazy Eddie's GUI System (http://www.cegui.org.uk)
10    Copyright (C)2004 - 2005 Paul D Turner (paul@cegui.org.uk)
11
12    This library is free software; you can redistribute it and/or
13    modify it under the terms of the GNU Lesser General Public
14    License as published by the Free Software Foundation; either
15    version 2.1 of the License, or (at your option) any later version.
16
17    This library is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20    Lesser General Public License for more details.
21
22    You should have received a copy of the GNU Lesser General Public
23    License along with this library; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
25*************************************************************************/
26/*************************************************************************
27       
28        The code in this file is taken from article 1.3 in the the book:
29        Game Programming Gems from Charles River Media
30
31*************************************************************************/
32#ifndef _CEGUISingleton_h_
33#define _CEGUISingleton_h_
34
35#include "CEGUIBase.h"
36#include <cassert>
37
38// Start of CEGUI namespace section
39namespace CEGUI
40{
41/* Copyright (C) Scott Bilas, 2000.
42 * All rights reserved worldwide.
43 *
44 * This software is provided "as is" without express or implied
45 * warranties. You may freely copy and compile this source into
46 * applications you distribute provided that the copyright text
47 * below is included in the resulting source code, for example:
48 * "Portions Copyright (C) Scott Bilas, 2000"
49 */
50
51
52template <typename T> class CEGUIEXPORT Singleton
53{
54protected:
55    static T* ms_Singleton;
56
57public:
58    Singleton( void )
59    {
60        assert( !ms_Singleton );
61        ms_Singleton = static_cast<T*>(this);
62    }
63   ~Singleton( void )
64        {  assert( ms_Singleton );  ms_Singleton = 0;  }
65    static T& getSingleton( void )
66        {  assert( ms_Singleton );  return ( *ms_Singleton );  }
67    static T* getSingletonPtr( void )
68        {  return ( ms_Singleton );  }
69};
70
71} // End of  CEGUI namespace section
72
73
74
75#endif  // end of guard _CEGUISingleton_h_
Note: See TracBrowser for help on using the repository browser.