1
0

hdef.h 2.6 KB

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