cmsingleton.h

来自「Soul的源代码,类似于劲舞团之类的游戏」· C头文件 代码 · 共 48 行

H
48
字号
#ifndef  __Sync_Singleton_H
#define  __Sync_Singleton_H

#include <MatrixCore/System/CMObject.h>

namespace MatrixCore
{
	namespace Pattern
	{
		template< class T > 
		class CMSingleton : public CMObject
		{
		public:
			static T*	getInstance();
			static void releaseInstance();

			virtual void initialize() = 0;

		private:
			static T* m_pSelfInstance;
		};

		template < class T > 
			T* CMSingleton< T >::m_pSelfInstance = NULL;

		template < class T > 
			T* CMSingleton< T >::getInstance()
		{
			if( m_pSelfInstance == NULL )
			{
				m_pSelfInstance = new T();
				m_pSelfInstance->initialize();
			} 
			return m_pSelfInstance;
		}

		template < class T > 
			void CMSingleton< T >::releaseInstance()
		{
			if( m_pSelfInstance != 0 )
				delete m_pSelfInstance;

			m_pSelfInstance = NULL;
		}
	}
}

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?