hdef.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #ifndef BEGIN_NAMESPACE
  35. #define BEGIN_NAMESPACE(ns) namespace ns {
  36. #endif
  37. #ifndef END_NAMESPACE
  38. #define END_NAMESPACE(ns) } // ns
  39. #endif
  40. #ifndef EXTERN_C
  41. #define EXTERN_C extern "C"
  42. #endif
  43. #ifndef BEGIN_EXTERN_C
  44. #define BEGIN_EXTERN_C extern "C" {
  45. #endif
  46. #ifndef END_EXTERN_C
  47. #define END_EXTERN_C } // extern "C"
  48. #endif
  49. #else
  50. #define BEGIN_NAMESPACE(ns)
  51. #define END_NAMESPACE(ns)
  52. #define EXTERN_C
  53. #define BEGIN_EXTERN_C
  54. #define END_EXTERN_C
  55. #endif // __cplusplus
  56. #ifndef MAX_PATH
  57. #define MAX_PATH 260
  58. #endif
  59. #ifndef NULL
  60. #ifdef __cplusplus
  61. #define NULL 0
  62. #else
  63. #define NULL ((void *)0)
  64. #endif
  65. #endif
  66. #ifndef FALSE
  67. #define FALSE 0
  68. #endif
  69. #ifndef TRUE
  70. #define TRUE 1
  71. #endif
  72. #ifndef CR
  73. #define CR '\r'
  74. #endif
  75. #ifndef LF
  76. #define LF '\n'
  77. #endif
  78. #ifndef CRLF
  79. #define CRLF "\r\n"
  80. #endif
  81. #ifndef IN
  82. #define IN
  83. #endif
  84. #ifndef OUT
  85. #define OUT
  86. #endif
  87. #ifndef OPTIONAL
  88. #define OPTIONAL
  89. #endif
  90. #ifndef REQUIRED
  91. #define REQUIRED
  92. #endif
  93. #ifndef REPEATED
  94. #define REPEATED
  95. #endif
  96. #ifndef ABS
  97. #define ABS(n) ((n) < 0 ? -(n) : (n))
  98. #endif
  99. #ifndef MAX
  100. #define MAX(a, b) ((a) > (b) ? (a) : (b))
  101. #endif
  102. #ifndef MIN
  103. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  104. #endif
  105. #ifndef LIMIT
  106. #define LIMIT(lower, v, upper) MIN(MAX((lower), (v)), (upper))
  107. #endif
  108. #ifndef ARRAY_SIZE
  109. #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
  110. #endif
  111. #ifndef SAFE_FREE
  112. #define SAFE_FREE(p) do {if (p) {free(p); (p) = NULL;}}while(0)
  113. #endif
  114. #ifndef SAFE_DELETE
  115. #define SAFE_DELETE(p) do {if (p) {delete (p); (p) = NULL;}}while(0)
  116. #endif
  117. #ifndef SAFE_DELETE_ARRAY
  118. #define SAFE_DELETE_ARRAY(p) do {if (p) {delete[] (p); (p) = NULL;}}while(0)
  119. #endif
  120. #ifndef SAFE_RELEASE
  121. #define SAFE_RELEASE(p) do {if (p) {(p)->release(); (p) = NULL;}}while(0)
  122. #endif
  123. #ifndef MAKE_FOURCC
  124. #define MAKE_FOURCC(a, b, c, d) \
  125. ( ((uint32)d) | ( ((uint32)c) << 8 ) | ( ((uint32)b) << 16 ) | ( ((uint32)a) << 24 ) )
  126. #endif
  127. #ifndef OS_WIN
  128. #ifndef MAKE_WORD
  129. #define MAKE_WORD(h, l) ( (((WORD)h) << 8) | (l & 0xff) )
  130. #endif
  131. #ifndef HIBYTE
  132. #define HIBYTE(w) ( (BYTE)(((WORD)w) >> 8) )
  133. #endif
  134. #ifndef LOBYTE
  135. #define LOBYTE(w) ( (BYTE)(w & 0xff) )
  136. #endif
  137. #endif
  138. #define MAKE_INT32(h, l) ( ((int32)h) << 16 | (l & 0xffff) )
  139. #define HIINT16(n) ( (int16)(((int32)n) >> 16) )
  140. #define LOINI16(n) ( (int16)(n & 0xffff) )
  141. #define MAKE_INT64(h, l) ( ((int64)h) << 32 | (l & 0xffffffff) )
  142. #define HIINT32(n) ( (int32)(((int64)n) >> 32) )
  143. #define LOINI32(n) ( (int32)(n & 0xffffffff) )
  144. #define FLOAT_PRECISION 1e-6
  145. #define FLOAT_EQUAL_ZERO(f) (ABS(f) < FLOAT_PRECISION)
  146. #define STRINGIFY(x) STRINGIFY_HELPER(x)
  147. #define STRINGIFY_HELPER(x) #x
  148. #define STRINGCAT(x, y) STRINGCAT_HELPER(x, y)
  149. #define STRINGCAT_HELPER(x, y) x##y
  150. #define container_of(ptr, type, member) \
  151. ((type *) ((char *) (ptr) - offsetof(type, member)))
  152. #endif // HW_DEF_H_