Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/ogre_src_v1-9-0/OgreMain/include/OgreSingleton.h @ 151

Last change on this file since 151 was 148, checked in by patricwi, 6 years ago

Added new dependencies for ogre1.9 and cegui0.8

File size: 3.3 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28/* Original version Copyright (C) Scott Bilas, 2000.
29 * All rights reserved worldwide.
30 *
31 * This software is provided "as is" without express or implied
32 * warranties. You may freely copy and compile this source into
33 * applications you distribute provided that the copyright text
34 * below is included in the resulting source code, for example:
35 * "Portions Copyright (C) Scott Bilas, 2000"
36 */
37#ifndef _SINGLETON_H__
38#define _SINGLETON_H__
39
40// Added by Steve Streeting for Ogre
41#include "OgrePrerequisites.h"
42
43#if OGRE_COMPILER == OGRE_COMPILER_MSVC
44// Turn off warnings generated by this singleton implementation
45#   pragma warning (disable : 4311)
46#   pragma warning (disable : 4312)
47#   pragma warning (disable : 4661)
48#endif
49
50#if defined ( OGRE_GCC_VISIBILITY )
51#   pragma GCC visibility push(default)
52#endif
53namespace Ogre {
54        /** \addtogroup Core
55        *  @{
56        */
57        /** \addtogroup General
58        *  @{
59        */
60
61// End SJS additions
62    /** Template class for creating single-instance global classes.
63    */
64    template <typename T> class Singleton
65    {
66        private:
67                /** @brief Explicit private copy constructor. This is a forbidden operation.*/
68                Singleton(const Singleton<T> &);
69
70                /** @brief Private operator= . This is a forbidden operation. */
71                Singleton& operator=(const Singleton<T> &);
72   
73        protected:
74
75        static T* msSingleton;
76
77    public:
78        Singleton( void )
79        {
80            assert( !msSingleton );
81#if defined( _MSC_VER ) && _MSC_VER < 1200       
82            int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
83            msSingleton = (T*)((int)this + offset);
84#else
85            msSingleton = static_cast< T* >( this );
86#endif
87        }
88        ~Singleton( void )
89            {  assert( msSingleton );  msSingleton = 0;  }
90        static T& getSingleton( void )
91                {       assert( msSingleton );  return ( *msSingleton ); }
92        static T* getSingletonPtr( void )
93                { return msSingleton; }
94    };
95        /** @} */
96        /** @} */
97
98}
99#if defined ( OGRE_GCC_VISIBILITY )
100#   pragma GCC visibility pop
101#endif
102
103#endif
Note: See TracBrowser for help on using the repository browser.