forked from Tr0n/client
Solution refactoring and restructuring, removed Boost dependency, removed unused tools
This commit is contained in:
29
src/UserInterface/AbstractSingleton.h
Normal file
29
src/UserInterface/AbstractSingleton.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
class TAbstractSingleton
|
||||
{
|
||||
static T * ms_singleton;
|
||||
|
||||
public:
|
||||
TAbstractSingleton()
|
||||
{
|
||||
assert(!ms_singleton);
|
||||
int offset = (int) (T*) 1 - (int) (CSingleton <T>*) (T*) 1;
|
||||
ms_singleton = (T*) ((int) this + offset);
|
||||
}
|
||||
|
||||
virtual ~TAbstractSingleton()
|
||||
{
|
||||
assert(ms_singleton);
|
||||
ms_singleton = 0;
|
||||
}
|
||||
|
||||
__forceinline static T & GetSingleton()
|
||||
{
|
||||
assert(ms_singleton!=NULL);
|
||||
return (*ms_singleton);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> T * TAbstractSingleton <T>::ms_singleton = 0;
|
Reference in New Issue
Block a user