#ifndef __SINGLETON__
#define __SINGLETON__


/////////////////////////////////////////////////////////////////////////////
// A universal singleton class through template casting
/////////////////////////////////////////////////////////////////////////////
template <typename T>
class Singleton
{
	private:

		// Unique instance
		static T * pInstance;


	protected:

		// Construction/Destruction
		Singleton(){}
		~Singleton(){}


	public:

		// Give a pointer to the instance / create the instance if not already done
		static T * GetInstance ()
		{
			if (!pInstance)
				pInstance = new T;
			return (static_cast<T*> (pInstance));
		}

		// Kill the only existing instance
		static void Kill()
		{
			if (NULL != pInstance)
			{
				delete pInstance;
				pInstance = NULL;
			}
		}
};

template <typename T>
T *Singleton<T>::pInstance = NULL;

#endif
