/************** Begin of GlobalMacro.h *******************************************/
/**********************************************************
* 版权所有 (C)2008, 51.com
*
* 文件名称：GlobalMacro.h
* 内容摘要：全局宏定义的头文件
*			本文件包含了所有要用到的全局宏的定义
* 其它说明：
* 当前版本：
* 作    者：温辉敏
* 完成日期：2009-1-02
*
* 修改记录1：
*    修改日期：
*    版 本 号：
*    修 改 人：
*    修改内容：
**********************************************************/
#if !defined(AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_)
#define AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// 获取数组的维数 [7/1/2008 温辉敏]
#define PARRAYSIZE(array) ((sizeof(array)/sizeof(array[0])))

/** Declare all the standard PWlib class information.
This macro is used to provide the basic run-time typing capability needed
by the library. All descendent classes from the #PObject# class require
these functions for correct operation. Either use ptrThis macro or the
#PDECLARE_CLASS# macro.

The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
of compatibility with documentation systems.
*/
#define CLASSINFO(cls, par) \
  public: \
	static const char * Class() \
	{ return #cls; } \
	virtual const char * GetClass(unsigned ancestor = 0) const \
	{ return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \
	virtual BOOL IsClass(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0; } \
	virtual BOOL IsDescendant(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0 || \
	  par::IsDescendant(clsName); } 


/** Declare all the standard PWlib class information.
This macro is used to provide the basic run-time typing capability needed
by the library. All descendent classes from the #PObject# class require
these functions for correct operation. Either use ptrThis macro or the
#PDECLARE_CLASS# macro.

The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
of compatibility with documentation systems.
*/
#define CLASSINFO_BASE(cls) \
  public: \
	static const char * Class() \
	{ return #cls; } \
	virtual const char * GetClass(unsigned ancestor = 0) const \
	{ return cls::Class(); } \
	virtual BOOL IsClass(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0; } \
	virtual BOOL IsDescendant(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0; } 


/* 函数返回基本状态信息  */
#ifdef OK
#undef OK
#endif /* #ifdef OK */
#ifndef OK
#define OK               (0)    /* 成功返回	*/
#endif /* #ifndef OK */

/* 函数返回基本状态信息  */
#ifdef FAILURE
#undef FAILURE
#endif /* #ifdef FAILURE */
#ifndef FAILURE
#define FAILURE           (-1)    /* 失败返回	*/
#endif /* #ifndef FAILURE */

//////////////////////////////////////////////////////////////////////////
///一些宏定义

///删除一个数组指针的宏定义
//lint -emacro(774, DELETEA)
#ifndef DELETEA
#define DELETEA(ptr) \
	if(NULL != ptr) \
	{ \
		delete[] ptr; \
		ptr = NULL; \
	}
#endif

///删除一个指针的宏定义
#ifndef FREEP
#define FREEP(ptr)		\
	if(NULL != ptr)		\
	{					\
		free(ptr) ;		\
		ptr = NULL;		\
	}
#endif

///删除一个指针的宏定义
//lint -emacro(774, DELETEP)
#define DELETEP(ptr)	\
	if(NULL != (ptr))		\
	{					\
		delete (ptr);		\
		(ptr) = NULL;		\
	}

///删除一个GDI对象的宏定义
//lint -emacro(774, DELETEOBJECT)
#define DELETEOBJECT(ptr)	\
	if(NULL != (ptr))		\
	{					\
		::DeleteObject (ptr);		\
		(ptr) = NULL;		\
	}

///Destroy一个Window
//lint -emacro(774, DESTROYWINDOW)
#define DESTROYWINDOW(hWnd)	\
	if (IsWindow(hWnd)) \
	{ \
		DestroyWindow(hWnd); \
	}

///删除一个指针的宏定义
//lint -emacro(774, FREEP)
#undef  FREEP
#define FREEP(ptr)		\
	if(NULL != ptr)		\
	{					\
		free(ptr) ;		\
		ptr = NULL;		\
	}


/** 定义的根据输入类型来删除不同类型的指针的宏定义
*/
#define DELETE_TYPE_P(Type, ptrEvent) \
	{\
		Type *ptrEventLocal = (Type *)ptrEvent; \
		DELETEP(ptrEventLocal); \
		ptrEvent = NULL; \
	}


/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行statement语句，然后以return_value值return
*/
#define PAssert_ReturnWithValue(condition, return_value) \
	{  \
		if (!(condition)) \
		{ \
			return (return_value); \
		} \
	}

/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行statement语句，然后return
*/
#define PAssert_Return(condition) \
	{  \
		if (!(condition)) \
		{ \
			return ; \
		} \
	}

#ifndef VOS_DELETE_SEM
#define VOS_DELETE_SEM(semId)	\
	if (NULL != semId)			\
	{							\
		VOS_DeleteSem(semId);	\
		semId = NULL;			\
	}
#endif

/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行statement语句，然后以return_value值return
*/
#define PAssert_Statement_ReturnWithValue(condition, statement, return_value) \
	{  \
		if (!(condition)) \
		{ \
			statement; \
			return (return_value); \
		} \
	}

/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行statement语句，然后return
*/
#define PAssert_Statement_Return(condition, statement) \
	{  \
		if (!(condition)) \
		{ \
			statement; \
			return ; \
		} \
	}

/** This macro is used to assert that a pointer must be non-null.
若指针ptr为NULL则执行statement语句，然后以return_value值return
*/
#define PAssertNotNull_Statement_ReturnWithValue(ptr, statement, return_value) \
	{ \
		if( (ptr) == NULL) \
		{ \
			statement; \
			return (return_value); \
		} \
	}


/** This macro is used to assert that a pointer must be non-null.
若指针ptr为NULL则执行statement语句，然后return
*/
#define PAssertNotNull_Statement_Return(ptr, statement) \
	{ \
		if( (ptr) == NULL) \
		{ \
			statement; \
			return ; \
		} \
	}

/** This macro is used to assert that a pointer must be non-null.
若指针ptr为NULL则执行statement语句，然后以return_value值return
*/
#define PAssertNotNull_ReturnWithValue(ptr, return_value) \
	{ \
		if( (ptr) == NULL) \
		{ \
			return (return_value); \
		} \
	}


/** This macro is used to assert that a pointer must be non-null.
若指针ptr为NULL则执行statement语句，然后return
*/
#define PAssertNotNull_Return(ptr) \
	{ \
		if( (ptr) == NULL) \
		{ \
			return ; \
		} \
	}

/** This macro is used to do something and return 
执行一个语句statement，然后return return_value
*/
#define PStatement_Return(statement, return_value) \
{ \
	statement; \
	return return_value; \
}

/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行break语句
*/
#define PAssert_Break(condition) \
{  \
	if (!(condition)) \
	{ \
		break ; \
	} \
}

/** This macro is used to do something and break 
执行一个语句statement，然后break
*/
#define PStatement_Break(statement) \
{ \
	statement; \
	break; \
}

/** This macro is used to assert that a condition must be TRUE.
若condition条件不成立则执行statement语句，然后执行break语句
*/
#define PAssert_Statement_Break(condition, statement) \
{  \
	if (!(condition)) \
	{ \
		statement; \
		break ; \
	} \
}

/** 空操作
*/
#define NULL_OPERATION

// 获取数组的维数 
#define PARRAYSIZE(array) ((sizeof(array)/sizeof(array[0])))

/** Declare all the standard RTTI class information.
This macro is used to provide the basic run-time typing capability needed
by the library. All descendent classes from the #PObject# class require
these functions for correct operation. Either use ptrThis macro or the
#PDECLARE_CLASS# macro.

The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
of compatibility with documentation systems.
*/
#define CLASSINFO(cls, par) \
  public: \
	static const char * Class() \
	{ return #cls; } \
	virtual const char * GetClass(unsigned ancestor = 0) const \
	{ return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \
	virtual BOOL IsClass(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0; } \
	virtual BOOL IsDescendant(const char * clsName) const \
	{ return strcmp(clsName, cls::Class()) == 0 || \
	par::IsDescendant(clsName); } 


///memset缺省构造函数
#ifndef MEMSET_CONSTRUCTOR
#define MEMSET_CONSTRUCTOR(ClassType) \
	ClassType() \
	{ \
		memset(this, 0, sizeof(ClassType)); \
	}
#endif

#if 0
#ifdef __cplusplus
/** 
按照特定数据类型删除该数据类型的数组指针
*/
#ifndef DELETE_ARRAY_TEMPLATE
#define DELETE_ARRAY_TEMPLATE
template <class classType>
void DeleteArray(void *&ptr)
{
	classType *ptrClassType = (classType *)ptr;
	DELETEA(ptrClassType);
	ptr = NULL;
}
#endif

/** 
按照特定数据类型删除该数据类型的指针
*/
#ifndef DELETE_TEMPLATE
#define DELETE_TEMPLATE
template <class classType>
void Delete(void *&ptr)
{
	classType *ptrClassType = (classType *)ptr;
	DELETEP(ptrClassType);
	ptr = NULL;
}
#endif
#endif
#endif


#endif // !defined(AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_)

/************** End of GlobalMacro.h *******************************************/