hdef.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #ifndef H_DEF_H
  2. #define H_DEF_H
  3. typedef unsigned char uint8;
  4. typedef unsigned short uint16;
  5. typedef unsigned int uint32;
  6. typedef unsigned long long uint64;
  7. typedef char int8;
  8. typedef short int16;
  9. typedef int int32;
  10. typedef long long int64;
  11. typedef float float32;
  12. typedef double float64;
  13. typedef unsigned char BYTE;
  14. typedef unsigned short WORD;
  15. typedef int BOOL;
  16. typedef int (*method_t)(void* userdata);
  17. typedef void (*procedure_t)(void* userdata);
  18. #ifndef MAX_PATH
  19. #define MAX_PATH 260
  20. #endif
  21. #ifndef NULL
  22. #ifdef __cplusplus
  23. #define NULL 0
  24. #else
  25. #define NULL ((void *)0)
  26. #endif
  27. #endif
  28. #ifndef FALSE
  29. #define FALSE 0
  30. #endif
  31. #ifndef TRUE
  32. #define TRUE 1
  33. #endif
  34. #ifndef IN
  35. #define IN
  36. #endif
  37. #ifndef OUT
  38. #define OUT
  39. #endif
  40. #ifndef OPTIONAL
  41. #define OPTIONAL
  42. #endif
  43. #ifndef REQUIRED
  44. #define REQUIRED
  45. #endif
  46. #ifndef REPEATED
  47. #define REPEATED
  48. #endif
  49. #ifndef MAX
  50. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  51. #endif
  52. #ifndef MIN
  53. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  54. #endif
  55. #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
  56. #define SAFE_FREE(p) do{if (p) {free(p); (p) = NULL;}}while(0)
  57. #define SAFE_DELETE(p) do{if (p) {delete (p); (p) = NULL;}}while(0)
  58. #define SAFE_DELETE_ARRAY(p) do{if (p) {delete[] (p); (p) = NULL;}}while(0)
  59. #define SAFE_RELEASE(p) do{if (p) {(p)->release(); (p) = NULL;}}while(0)
  60. #ifndef MAKE_FOURCC
  61. #define MAKE_FOURCC(a,b,c,d) \
  62. ( ((uint32)d) | ( ((uint32)c) << 8 ) | ( ((uint32)b) << 16 ) | ( ((uint32)a) << 24 ) )
  63. #endif
  64. #ifndef MAKE_WORD
  65. #define MAKE_WORD(h,l) ( (((WORD)h) << 8) | (l & 0xff) )
  66. #endif
  67. #ifndef HIBYTE
  68. #define HIBYTE(w) ( (BYTE)(((WORD)w) >> 8) )
  69. #endif
  70. #ifndef LOBYTE
  71. #define LOBYTE(w) ( (BYTE)(w & 0xff) )
  72. #endif
  73. #define MAKE_INT32(h,l) ( ((int32)h) << 16 | (l & 0xffff) )
  74. #define HIINT16(n) ( (int16)(((int32)n) >> 16) )
  75. #define LOINI16(n) ( (int16)(n & 0xffff) )
  76. #define MAKE_INT64(h,l) ( ((int64)h) << 32 | (l & 0xffffffff) )
  77. #define HIINT32(n) ( (int32)(((int64)n) >> 32) )
  78. #define LOINI32(n) ( (int32)(n & 0xffffffff) )
  79. #define FLOAT_PRECISION 1e-6
  80. #define FLOAT_EQUAL_ZERO(f) (-FLOAT_PRECISION < (f) && (f) < FLOAT_PRECISION)
  81. #define STRINGIFY(x) STRINGIFY_HELPER(x)
  82. #define STRINGIFY_HELPER(x) #x
  83. #define STRINGCAT(x,y) STRINGCAT_HELPER(x,y)
  84. #define STRINGCAT_HELPER(x,y) x##y
  85. #define container_of(ptr, type, member) \
  86. ((type *) ((char *) (ptr) - offsetof(type, member)))
  87. #endif // H_DEF_H