Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
56 lines (49 sloc) 1.61 KB
/*
-----------------------------------------------------------------------------
This file has been adapted from OGRE to suit our own purposes
-----------------------------------------------------------------------------
*/
/* Original version Copyright (C) Scott Bilas, 2000.
* All rights reserved worldwide.
*
* This software is provided "as is" without express or implied
* warranties. You may freely copy and compile this source into
* applications you distribute provided that the copyright text
* below is included in the resulting source code, for example:
* "Portions Copyright (C) Scott Bilas, 2000"
*/
#ifndef _SINGLETON_H__
#define _SINGLETON_H__
#include "Prerequisites.h"
#if UOX_COMPILER == COMPILER_MSVC
// Turn off warnings generated by this singleton implementation
# pragma warning (disable : 4311)
# pragma warning (disable : 4312)
#endif
namespace UOX {
/** Template class for creating single-instance global classes.
*/
template <typename T> class Singleton
{
protected:
static T* ms_Singleton;
public:
Singleton( void )
{
assert( !ms_Singleton );
#if defined( _MSC_VER ) && _MSC_VER < 1200
int offset = (int)(T*)1 - (int)(Singleton <T>*)(T*)1;
ms_Singleton = (T*)((int)this + offset);
#else
ms_Singleton = static_cast< T* >( this );
#endif
}
~Singleton( void )
{ assert( ms_Singleton ); ms_Singleton = 0; }
static T& getSingleton( void )
{ assert( ms_Singleton ); return ( *ms_Singleton ); }
static T* getSingletonPtr( void )
{ return ms_Singleton; }
};
}
#endif
Something went wrong with that request. Please try again.