commondef.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /************************************************************************/
  2. /* copyright */
  3. /* version 1.1 修改TPoint TRect 的数据类型为int */
  4. /************************************************************************/
  5. #ifndef __COMMON_DEF_H__
  6. #define __COMMON_DEF_H__
  7. //////////////////////////////////////////////////////////////////////////
  8. /* 平台相关的一些定义 */
  9. /** 调用方式约定 */
  10. #if (defined WIN32 || defined WIN64)
  11. //-----------windows-----------------------------
  12. #define STD_CDECL __cdecl //C调用约定
  13. #define STD_STDCALL __stdcall //pascall调用约定
  14. #define STD_EXPORTS __declspec(dllexport)
  15. #define STD_WINAPI __stdcall
  16. #else
  17. //-----------linux-------------------------------
  18. #define STD_CDECL
  19. #define STD_STDCALL
  20. #define STD_EXPORTS __attribute__ ((visibility("default")))
  21. #endif
  22. /* 导出方式定义 */
  23. #ifndef STD_EXTERN_C
  24. #ifdef __cplusplus
  25. #define STD_EXTERN_C extern "C"
  26. #else
  27. #define STD_EXTERN_C extern
  28. #endif
  29. #endif
  30. /* 接口定义:采用标准的C调用约定 */
  31. #ifndef STD_API
  32. #define STD_API(rettype) STD_EXTERN_C STD_EXPORTS rettype STD_CDECL
  33. /* 接口实现:采用标准的C调用约定 */
  34. #define STD_IMPL STD_EXTERN_C STD_EXPORTS
  35. #endif
  36. /* C++接口定义 */
  37. #ifndef CPP_API
  38. #define CPP_API(rettype) STD_EXPORTS rettype STD_CDECL
  39. #define CPP_IMPL STD_EXPORTS
  40. #endif
  41. //////////////////////////////////////////////////////////////////////////
  42. //常用定义宏
  43. /* MIN, MAX, ABS */
  44. #define ZMIN(a, b) ((a)>(b) ? (b) : (a))
  45. #define ZMAX(a, b) ((a)<(b) ? (b) : (a))
  46. #define ZABS(a) ((a) < 0 ? (-(a)) : a)
  47. #define ZSIGN(x) (((x) < 0) ? -1 : 1)
  48. #define ZFALSE (0)
  49. #define ZTRUE (1)
  50. #define ZPI (3.1415926535)
  51. #define PROCNAME(name) static const char procName[] = name
  52. #define ROUND(a) ((int)((a) + ((a) >= 0 ? 0.5 : -0.5)))
  53. #define FLOOR(a) ( ROUND(a) + ((a - ROUND(a)) < 0 ) )
  54. #define CEIL(a) ( ROUND(a) + ((ROUND(a) - a) < 0 ) )
  55. //////////////////////////////////////////////////////////////////////////
  56. //64位大数,由于下面long被重定义了,所以这个要提前
  57. #if (defined WIN32 || defined WIN64)
  58. typedef __int64 TInt64;
  59. #else
  60. typedef long long TInt64;
  61. #endif
  62. //由于long的长度有32位好64位的问题,统一用int来处理,识别内核没有问题
  63. //#define long int
  64. //////////////////////////////////////////////////////////////////////////
  65. /**common data types, when we write code, we must use this data type to make our code partable
  66. *more easily, and make our code write more precise in data type.*/
  67. typedef signed char TInt8;
  68. typedef signed short TInt16;
  69. typedef signed int TInt32;
  70. typedef signed int TInt;
  71. typedef signed long TLong; //长度x32,4byte,x64是8byte
  72. typedef unsigned char TUint8;
  73. typedef unsigned short TUint16;
  74. typedef unsigned int TUint32;
  75. typedef unsigned int TUint; //DWORD
  76. typedef unsigned char TUchar; //BYTE
  77. typedef unsigned short TUshort; //WORD
  78. typedef unsigned long TUlong; //长度x32,4byte,x64是8byte
  79. typedef float TReal32;
  80. typedef double TReal64;
  81. typedef int TBool;
  82. typedef void TVoid;
  83. typedef void* THandle; // handle=void*
  84. typedef int TStatus;
  85. typedef int TSTATUS;
  86. typedef void* THandle;
  87. //////////////////////////////////////////////////////////////////////////
  88. /* 点 */
  89. typedef struct TPoint_
  90. {
  91. int x;
  92. int y;
  93. }TPoint;
  94. /* 矩形(包含关系) */
  95. typedef struct TRect_
  96. {
  97. int nLft;
  98. int nRgt;
  99. int nTop;
  100. int nBtm;
  101. }TRect;
  102. //////////////////////////////////////////////////////////////////////////
  103. //数据类型最大值和最小值
  104. #define TINT8_MIN (-128)
  105. #define TINT16_MIN (-32768)
  106. #define TINT32_MIN (-2147483647 - 1)
  107. #define TINT64_MIN (-9223372036854775807LL - 1)
  108. #define TINT8_MAX 127
  109. #define TINT16_MAX 32767
  110. #define TINT32_MAX 2147483647
  111. #define TINT64_MAX 9223372036854775807LL
  112. #define TUINT8_MAX 0xff /* 255U */
  113. #define TUINT16_MAX 0xffff /* 65535U */
  114. #define TUINT32_MAX 0xffffffff /* 4294967295U */
  115. #define TUINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
  116. //////////////////////////////////////////////////////////////////////////
  117. //错误类型 错误编码 <0 发生错误 否则正确,32位的错误编码
  118. /** 判断语句 */
  119. #define ISFAILED(iStatus) ((iStatus) < 0 )
  120. #define ISSUCCEEDED(iStatus) ((iStatus) >= 0 )
  121. /** 没有错误 */
  122. #define STATUS_OK (0 )
  123. /** 内存不足 */
  124. #define STATUS_NOMEMORY (-80001)
  125. /** 输入参数不对 */
  126. #define STATUS_INVALIDARG (-80002)
  127. /** 无此接口 */
  128. #define STATUS_NOINTERFACE (-80003)
  129. /** 无效指针 */
  130. #define STATUS_INVALIDPTR (-80004)
  131. /* 文件错误 */
  132. #define STATUS_FILEERROR (-80005)
  133. /** 识别字典没有初始化 */
  134. #define STATUS_DICT_UNINIT (-80006)
  135. /** 识别字典错误 */
  136. #define STATUS_RECG_ERROR (-80007)
  137. /** 字典初始化错误 */
  138. #define STATUS_DICT_ERROR (-80008)
  139. /** 指针为空 */
  140. #define STATUS_NULLPTR (-80009)
  141. /** not supported image formate */
  142. #define STATUS_UNKNOWFMT (-80010)
  143. /** 图像错误 */
  144. #define STATUS_BADIMAGE (-80011)
  145. /** 添加其他错误 ........................ */
  146. /** 定位错误 */
  147. #define STATUS_DETECTERR (-80020)
  148. /** 解码错误 */
  149. #define STATUS_DECODEERR (-80021)
  150. /** 编码错误 */
  151. #define STATUS_ENCODEERR (-80022)
  152. /** 库过期了*/
  153. #define STATUS_OVERTIME (-80023)
  154. /**其他错误 */
  155. #define STATUS_UNEXPECTED (-88888)
  156. //////////////////////////////////////////////////////////////////////////
  157. #endif //__COMMON_DEF_H__