⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmsingleton.h

📁 Soul的源代码,类似于劲舞团之类的游戏
💻 H
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -