Macro.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:3k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2002/10/16
  3. file base: global
  4. file ext: h
  5. author: liupeng
  6. purpose: The file contains definitions, macros, and structures 
  7. to help me write gameengine
  8. *********************************************************************/
  9. #ifndef __INCLUDE_GAMEENGINE_GLOBAL_H__
  10. #define __INCLUDE_GAMEENGINE_GLOBAL_H__
  11. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  12. #pragma once
  13. #endif
  14. #ifndef _WINDOWS_
  15. #define WIN32_LEAN_AND_MEAN
  16. #include <windows.h> //For PutDebugString(...) API
  17. #undef WIN32_LEAN_AND_MEAN
  18. #endif
  19. /*
  20.  * For you debug app
  21.  */
  22. #ifdef _DEBUG
  23. //{
  24. void _trace(char *fmt, ...);
  25. #ifndef ASSERT
  26. #define ASSERT(x) { if ( !( x ) ) _asm{ int 0x03 } }
  27. #endif
  28. #ifndef VERIFY
  29. #define VERIFY(x) { if ( !( x ) ) _asm{ int 0x03 } }
  30. #endif
  31. //}
  32. #else
  33. //{
  34. #ifndef ASSERT
  35. #define ASSERT(x)
  36. #endif
  37. #ifndef VERIFY
  38. #define VERIFY(x) x
  39. #endif
  40. //}
  41. #endif
  42. #ifdef _DEBUG
  43. //{
  44. #ifndef TRACE
  45. #define TRACE _trace
  46. #endif
  47. //}
  48. #else
  49. //{
  50. inline void _trace(LPCTSTR fmt, ...) { }
  51. #ifndef TRACE
  52. #define TRACE  1 ? (void)0 : _trace
  53. #endif
  54. //}
  55. #endif
  56. /*
  57.  * Quickly and safely manage memory etc.
  58.  */
  59. #define INIT_PTR(x) do{ (x) = NULL; }while(0);
  60. #define SAFE_DELETE(x) try{ if( (x) != NULL ) { delete (x); (x) = NULL; } } catch(...) { TRACE("SAFE_DELETE errorn"); }
  61. #define SAFE_DELETE_ARRAY(x) try{ if( (x) != NULL ) { delete[] (x); (x) = NULL; } } catch(...) { TRACE("SAFE_DELETE_ARRAY errorn"); }
  62. #ifndef SAFE_FREE
  63. #undef SAFE_FREE
  64. #define SAFE_FREE(x) try{ if( (x) != NULL ) { free(x); (x)=NULL; } } catch(...) { TRACE("SAFE_FREE errorn"); }
  65. #endif
  66. #ifndef SAFE_RELEASE
  67. #undef SAFE_RELEASE
  68. #define SAFE_RELEASE(x) try{ if( (x) != NULL ) { (x)->Release(); (x) = NULL; } } catch(...) { TRACE("SAFE_RELEASE errorn"); }
  69. #endif
  70. #define SAFE_CLOSEHANDLE(x) try{ if (x) { CloseHandle(x); (x) = NULL; } } catch(...) { TRACE("SAFE_CLOSEHANDLE errorn"); }
  71. #define SAFE_FREELIB(x) try{ if (x) { FreeLibrary(x); (x) = NULL; } } catch(...) { TRACE("SAFE_FREELIB errorn"); }
  72. /*
  73.  * Quick and safely convert number format
  74.  */
  75. #ifndef MAKEFOURCC
  76. //{
  77. #define MAKEFOURCC(ch0, ch1, ch2, ch3)
  78. ((DWORD)(BYTE)(ch0) | ((DWORD)(BYTE)(ch1) << 8) |
  79. ((DWORD)(BYTE)(ch2) << 16) | ((DWORD)(BYTE)(ch3) << 24 ))
  80. //}
  81. #endif
  82. #define COUNT_OF_ARRAY(array) ( sizeof( array ) / sizeof( array[0] ) )
  83. /*
  84.  * 'c' must be a char and not be a expression in the _private macro 
  85.  */
  86. #define _private_IS_NUM(c)     ((c) >= '0' && (c) <= '9')
  87. #define _private_IS_SPACE(c)   ((c) == ' ' || (c) == 'r' || (c) == 'n' || (c) == 't' || (c) == 'x')
  88. #define IS_NUM(c) _private_IS_NUM(c)
  89. #define IS_SPACE(c) _private_IS_SPACE(c)
  90. #endif //#ifndef __INCLUDE_GAMEENGINE_GLOBAL_H__