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

📄 singletonmacros.h

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 H
字号:
/*____________________________________________________________________________
		Copyright (C) 2002 PGP Corporation
        All rights reserved.

        $Id: SingletonMacros.h,v 1.3 2002/08/06 20:10:38 dallen Exp $
____________________________________________________________________________*/

#ifndef Included_SingletonMacros_h	// [
#define Included_SingletonMacros_h

#include "pgpClassesConfig.h"

_PGP_BEGIN

// Macros for declaring singleton variables and functions

#define DECLARE_SINGLETON_VARIABLE(type)								\
	protected:															\
		static type	*mInstance;											\
																		\
	public:																\
		static type&	Instance();

#define DECLARE_SINGLETON_NEWDELFUNCS()									\
	public:																\
		static SMART_ERROR	CreateInstance();							\
		static void			DestroyInstance();


// Macros for defining singleton variables and functions

#define DEFINE_SINGLETON_VARIABLE(type)									\
	type	*type::mInstance	= NULL;									\
																		\
	type&																\
	type::Instance()													\
	{																	\
		return *mInstance;												\
	}

#if PGP_EXCEPTIONS

#define DEFINE_SINGLETON_NEWDELFUNCS(type)								\
	void																\
	type::CreateInstance()												\
	{																	\
		if (IsNull(mInstance))											\
			mInstance = new type;										\
	}																	\
																		\
	void																\
	type::DestroyInstance()												\
	{																	\
		if (IsntNull(mInstance))										\
		{																\
			pgpAssertAddrValid(mInstance, type);						\
																		\
			delete mInstance;											\
			mInstance = NULL;											\
		}																\
	}

#else	// !PGP_EXCEPTIONS

#define DEFINE_SINGLETON_NEWDELFUNCS(type)								\
	CComboError															\
	type::CreateInstance()												\
	{																	\
		CComboError	error;												\
																		\
		if (IsNull(mInstance))											\
		{																\
			if (IsNull(mInstance = new type))							\
				error.pgpErr = kPGPError_OutOfMemory;					\
																		\
			if (error.IsntError())										\
			{															\
				error = mInstance->Status();							\
																		\
				if (error.IsError())									\
				{														\
					delete mInstance;									\
					mInstance = NULL;									\
				}														\
			}															\
		}																\
																		\
		return error;													\
	}																	\
																		\
	void																\
	type::DestroyInstance()												\
	{																	\
		if (IsntNull(mInstance))										\
		{																\
			pgpAssertAddrValid(mInstance, type);						\
																		\
			delete mInstance;											\
			mInstance = NULL;											\
		}																\
	}

#endif	// PGP_EXCEPTIONS

_PGP_END

#endif	// Included_SingletonMacros_h

⌨️ 快捷键说明

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