GlobalMacro.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /************** Begin of GlobalMacro.h *******************************************/
  2. /**********************************************************
  3. * 版权所有 (C)2008, 51.com
  4. *
  5. * 文件名称:GlobalMacro.h
  6. * 内容摘要:全局宏定义的头文件
  7. * 本文件包含了所有要用到的全局宏的定义
  8. * 其它说明:
  9. * 当前版本:
  10. * 作 者:温辉敏
  11. * 完成日期:2009-1-02
  12. *
  13. * 修改记录1:
  14. * 修改日期:
  15. * 版 本 号:
  16. * 修 改 人:
  17. * 修改内容:
  18. **********************************************************/
  19. #if !defined(AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_)
  20. #define AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_
  21. #if _MSC_VER > 1000
  22. #pragma once
  23. #endif // _MSC_VER > 1000
  24. // 获取数组的维数 [7/1/2008 温辉敏]
  25. #define PARRAYSIZE(array) ((sizeof(array)/sizeof(array[0])))
  26. /** Declare all the standard PWlib class information.
  27. This macro is used to provide the basic run-time typing capability needed
  28. by the library. All descendent classes from the #PObject# class require
  29. these functions for correct operation. Either use ptrThis macro or the
  30. #PDECLARE_CLASS# macro.
  31. The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
  32. of compatibility with documentation systems.
  33. */
  34. #define CLASSINFO(cls, par) \
  35. public: \
  36. static const char * Class() \
  37. { return #cls; } \
  38. virtual const char * GetClass(unsigned ancestor = 0) const \
  39. { return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \
  40. virtual BOOL IsClass(const char * clsName) const \
  41. { return strcmp(clsName, cls::Class()) == 0; } \
  42. virtual BOOL IsDescendant(const char * clsName) const \
  43. { return strcmp(clsName, cls::Class()) == 0 || \
  44. par::IsDescendant(clsName); }
  45. /** Declare all the standard PWlib class information.
  46. This macro is used to provide the basic run-time typing capability needed
  47. by the library. All descendent classes from the #PObject# class require
  48. these functions for correct operation. Either use ptrThis macro or the
  49. #PDECLARE_CLASS# macro.
  50. The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
  51. of compatibility with documentation systems.
  52. */
  53. #define CLASSINFO_BASE(cls) \
  54. public: \
  55. static const char * Class() \
  56. { return #cls; } \
  57. virtual const char * GetClass(unsigned ancestor = 0) const \
  58. { return cls::Class(); } \
  59. virtual BOOL IsClass(const char * clsName) const \
  60. { return strcmp(clsName, cls::Class()) == 0; } \
  61. virtual BOOL IsDescendant(const char * clsName) const \
  62. { return strcmp(clsName, cls::Class()) == 0; }
  63. /* 函数返回基本状态信息 */
  64. #ifdef OK
  65. #undef OK
  66. #endif /* #ifdef OK */
  67. #ifndef OK
  68. #define OK (0) /* 成功返回 */
  69. #endif /* #ifndef OK */
  70. /* 函数返回基本状态信息 */
  71. #ifdef FAILURE
  72. #undef FAILURE
  73. #endif /* #ifdef FAILURE */
  74. #ifndef FAILURE
  75. #define FAILURE (-1) /* 失败返回 */
  76. #endif /* #ifndef FAILURE */
  77. //////////////////////////////////////////////////////////////////////////
  78. ///一些宏定义
  79. ///删除一个数组指针的宏定义
  80. //lint -emacro(774, DELETEA)
  81. #ifndef DELETEA
  82. #define DELETEA(ptr) \
  83. if(NULL != ptr) \
  84. { \
  85. delete[] ptr; \
  86. ptr = NULL; \
  87. }
  88. #endif
  89. ///删除一个指针的宏定义
  90. #ifndef FREEP
  91. #define FREEP(ptr) \
  92. if(NULL != ptr) \
  93. { \
  94. free(ptr) ; \
  95. ptr = NULL; \
  96. }
  97. #endif
  98. ///删除一个指针的宏定义
  99. //lint -emacro(774, DELETEP)
  100. #define DELETEP(ptr) \
  101. if(NULL != (ptr)) \
  102. { \
  103. delete (ptr); \
  104. (ptr) = NULL; \
  105. }
  106. ///删除一个GDI对象的宏定义
  107. //lint -emacro(774, DELETEOBJECT)
  108. #define DELETEOBJECT(ptr) \
  109. if(NULL != (ptr)) \
  110. { \
  111. ::DeleteObject (ptr); \
  112. (ptr) = NULL; \
  113. }
  114. ///Destroy一个Window
  115. //lint -emacro(774, DESTROYWINDOW)
  116. #define DESTROYWINDOW(hWnd) \
  117. if (IsWindow(hWnd)) \
  118. { \
  119. DestroyWindow(hWnd); \
  120. }
  121. ///删除一个指针的宏定义
  122. //lint -emacro(774, FREEP)
  123. #undef FREEP
  124. #define FREEP(ptr) \
  125. if(NULL != ptr) \
  126. { \
  127. free(ptr) ; \
  128. ptr = NULL; \
  129. }
  130. /** 定义的根据输入类型来删除不同类型的指针的宏定义
  131. */
  132. #define DELETE_TYPE_P(Type, ptrEvent) \
  133. {\
  134. Type *ptrEventLocal = (Type *)ptrEvent; \
  135. DELETEP(ptrEventLocal); \
  136. ptrEvent = NULL; \
  137. }
  138. /** This macro is used to assert that a condition must be TRUE.
  139. 若condition条件不成立则执行statement语句,然后以return_value值return
  140. */
  141. #define PAssert_ReturnWithValue(condition, return_value) \
  142. { \
  143. if (!(condition)) \
  144. { \
  145. return (return_value); \
  146. } \
  147. }
  148. /** This macro is used to assert that a condition must be TRUE.
  149. 若condition条件不成立则执行statement语句,然后return
  150. */
  151. #define PAssert_Return(condition) \
  152. { \
  153. if (!(condition)) \
  154. { \
  155. return ; \
  156. } \
  157. }
  158. #ifndef VOS_DELETE_SEM
  159. #define VOS_DELETE_SEM(semId) \
  160. if (NULL != semId) \
  161. { \
  162. VOS_DeleteSem(semId); \
  163. semId = NULL; \
  164. }
  165. #endif
  166. /** This macro is used to assert that a condition must be TRUE.
  167. 若condition条件不成立则执行statement语句,然后以return_value值return
  168. */
  169. #define PAssert_Statement_ReturnWithValue(condition, statement, return_value) \
  170. { \
  171. if (!(condition)) \
  172. { \
  173. statement; \
  174. return (return_value); \
  175. } \
  176. }
  177. /** This macro is used to assert that a condition must be TRUE.
  178. 若condition条件不成立则执行statement语句,然后return
  179. */
  180. #define PAssert_Statement_Return(condition, statement) \
  181. { \
  182. if (!(condition)) \
  183. { \
  184. statement; \
  185. return ; \
  186. } \
  187. }
  188. /** This macro is used to assert that a pointer must be non-null.
  189. 若指针ptr为NULL则执行statement语句,然后以return_value值return
  190. */
  191. #define PAssertNotNull_Statement_ReturnWithValue(ptr, statement, return_value) \
  192. { \
  193. if( (ptr) == NULL) \
  194. { \
  195. statement; \
  196. return (return_value); \
  197. } \
  198. }
  199. /** This macro is used to assert that a pointer must be non-null.
  200. 若指针ptr为NULL则执行statement语句,然后return
  201. */
  202. #define PAssertNotNull_Statement_Return(ptr, statement) \
  203. { \
  204. if( (ptr) == NULL) \
  205. { \
  206. statement; \
  207. return ; \
  208. } \
  209. }
  210. /** This macro is used to assert that a pointer must be non-null.
  211. 若指针ptr为NULL则执行statement语句,然后以return_value值return
  212. */
  213. #define PAssertNotNull_ReturnWithValue(ptr, return_value) \
  214. { \
  215. if( (ptr) == NULL) \
  216. { \
  217. return (return_value); \
  218. } \
  219. }
  220. /** This macro is used to assert that a pointer must be non-null.
  221. 若指针ptr为NULL则执行statement语句,然后return
  222. */
  223. #define PAssertNotNull_Return(ptr) \
  224. { \
  225. if( (ptr) == NULL) \
  226. { \
  227. return ; \
  228. } \
  229. }
  230. /** This macro is used to do something and return
  231. 执行一个语句statement,然后return return_value
  232. */
  233. #define PStatement_Return(statement, return_value) \
  234. { \
  235. statement; \
  236. return return_value; \
  237. }
  238. /** This macro is used to assert that a condition must be TRUE.
  239. 若condition条件不成立则执行break语句
  240. */
  241. #define PAssert_Break(condition) \
  242. { \
  243. if (!(condition)) \
  244. { \
  245. break ; \
  246. } \
  247. }
  248. /** This macro is used to do something and break
  249. 执行一个语句statement,然后break
  250. */
  251. #define PStatement_Break(statement) \
  252. { \
  253. statement; \
  254. break; \
  255. }
  256. /** This macro is used to assert that a condition must be TRUE.
  257. 若condition条件不成立则执行statement语句,然后执行break语句
  258. */
  259. #define PAssert_Statement_Break(condition, statement) \
  260. { \
  261. if (!(condition)) \
  262. { \
  263. statement; \
  264. break ; \
  265. } \
  266. }
  267. /** 空操作
  268. */
  269. #define NULL_OPERATION
  270. // 获取数组的维数
  271. #define PARRAYSIZE(array) ((sizeof(array)/sizeof(array[0])))
  272. /** Declare all the standard RTTI class information.
  273. This macro is used to provide the basic run-time typing capability needed
  274. by the library. All descendent classes from the #PObject# class require
  275. these functions for correct operation. Either use ptrThis macro or the
  276. #PDECLARE_CLASS# macro.
  277. The use of the #PDECLARE_CLASS# macro is no longer recommended for reasons
  278. of compatibility with documentation systems.
  279. */
  280. #define CLASSINFO(cls, par) \
  281. public: \
  282. static const char * Class() \
  283. { return #cls; } \
  284. virtual const char * GetClass(unsigned ancestor = 0) const \
  285. { return ancestor > 0 ? par::GetClass(ancestor-1) : cls::Class(); } \
  286. virtual BOOL IsClass(const char * clsName) const \
  287. { return strcmp(clsName, cls::Class()) == 0; } \
  288. virtual BOOL IsDescendant(const char * clsName) const \
  289. { return strcmp(clsName, cls::Class()) == 0 || \
  290. par::IsDescendant(clsName); }
  291. ///memset缺省构造函数
  292. #ifndef MEMSET_CONSTRUCTOR
  293. #define MEMSET_CONSTRUCTOR(ClassType) \
  294. ClassType() \
  295. { \
  296. memset(this, 0, sizeof(ClassType)); \
  297. }
  298. #endif
  299. #if 0
  300. #ifdef __cplusplus
  301. /**
  302. 按照特定数据类型删除该数据类型的数组指针
  303. */
  304. #ifndef DELETE_ARRAY_TEMPLATE
  305. #define DELETE_ARRAY_TEMPLATE
  306. template <class classType>
  307. void DeleteArray(void *&ptr)
  308. {
  309. classType *ptrClassType = (classType *)ptr;
  310. DELETEA(ptrClassType);
  311. ptr = NULL;
  312. }
  313. #endif
  314. /**
  315. 按照特定数据类型删除该数据类型的指针
  316. */
  317. #ifndef DELETE_TEMPLATE
  318. #define DELETE_TEMPLATE
  319. template <class classType>
  320. void Delete(void *&ptr)
  321. {
  322. classType *ptrClassType = (classType *)ptr;
  323. DELETEP(ptrClassType);
  324. ptr = NULL;
  325. }
  326. #endif
  327. #endif
  328. #endif
  329. #endif // !defined(AFX_GLOBALMACRO_H__DD58A78D_C125_410F_B4C8_F0067B797121__INCLUDED_)
  330. /************** End of GlobalMacro.h *******************************************/