📄 singletonmacros.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 + -