
#pragma once

#include "../EngineDef.h"


template <typename T>
class CSingleton
{
public:
	CSingleton(VOID)
	{
		assert(ms_Singleton == NULL);
		INT offset = (INT)(T*)1 - (INT)(CSingleton <T> *)(T*)1;
		ms_Singleton = (T*)((INT)this + offset);
	}
	~CSingleton(VOID)  {  assert(ms_Singleton != NULL);  ms_Singleton = NULL;  }

	static T&   GetSingleton      (VOID)  {  assert(ms_Singleton != NULL);  return (*ms_Singleton);  }
	static T*   GetSingletonPtr   (VOID)  {  return (ms_Singleton);  }
	static BOOL DoesSingletonExist(VOID)  {  return (ms_Singleton != NULL);  }

private:
	static T* ms_Singleton;	
};
template <typename T> T* CSingleton <T>::ms_Singleton = NULL;