hdef.h 3.3 KB

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