hdef.h 2.9 KB

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