[148] | 1 | /* |
---|
| 2 | ----------------------------------------------------------------------------- |
---|
| 3 | This source file is part of OGRE |
---|
| 4 | (Object-oriented Graphics Rendering Engine) |
---|
| 5 | For the latest info, see http://www.ogre3d.org/ |
---|
| 6 | |
---|
| 7 | Copyright (c) 2000-2013 Torus Knot Software Ltd |
---|
| 8 | |
---|
| 9 | Permission is hereby granted, free of charge, to any person obtaining a copy |
---|
| 10 | of this software and associated documentation files (the "Software"), to deal |
---|
| 11 | in the Software without restriction, including without limitation the rights |
---|
| 12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
---|
| 13 | copies of the Software, and to permit persons to whom the Software is |
---|
| 14 | furnished to do so, subject to the following conditions: |
---|
| 15 | |
---|
| 16 | The above copyright notice and this permission notice shall be included in |
---|
| 17 | all copies or substantial portions of the Software. |
---|
| 18 | |
---|
| 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
| 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
| 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
| 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
| 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
---|
| 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
---|
| 25 | THE 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 |
---|
| 53 | namespace 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 |
---|