hexport.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef HV_EXPORT_H_
  2. #define HV_EXPORT_H_
  3. /*
  4. * @功能: 此头文件主要是定义动态库导出宏HV_EXPORT
  5. *
  6. * @备注: 如果是以静态库方式使用,需将HV_STATICLIB加入到预编译宏
  7. *
  8. */
  9. // HV_EXPORT
  10. // 接口导出宏
  11. #if defined(HV_STATICLIB) || defined(HV_SOURCE)
  12. #define HV_EXPORT
  13. #elif defined(_MSC_VER)
  14. #if defined(HV_DYNAMICLIB) || defined(HV_EXPORTS) || defined(hv_EXPORTS)
  15. #define HV_EXPORT __declspec(dllexport)
  16. #else
  17. #define HV_EXPORT __declspec(dllimport)
  18. #endif
  19. #elif defined(__GNUC__)
  20. #define HV_EXPORT __attribute__((visibility("default")))
  21. #else
  22. #define HV_EXPORT
  23. #endif
  24. // HV_DEPRECATED
  25. // 接口过时声明宏
  26. #if defined(HV_NO_DEPRECATED)
  27. #define HV_DEPRECATED
  28. #elif defined(__GNUC__) || defined(__clang__)
  29. #define HV_DEPRECATED __attribute__((deprecated))
  30. #elif defined(_MSC_VER)
  31. #define HV_DEPRECATED __declspec(deprecated)
  32. #else
  33. #define HV_DEPRECATED
  34. #endif
  35. // HV_UNUSED
  36. // 参数未使用宏
  37. #if defined(__GNUC__)
  38. #define HV_UNUSED __attribute__((visibility("unused")))
  39. #else
  40. #define HV_UNUSED
  41. #endif
  42. // @param[IN | OUT | INOUT]
  43. /*
  44. * 参数描述宏:
  45. * IN => 输入参数
  46. * OUT => 输出参数
  47. * INOUT=> 既作输入参数,又作输出参数
  48. *
  49. */
  50. #ifndef IN
  51. #define IN
  52. #endif
  53. #ifndef OUT
  54. #define OUT
  55. #endif
  56. #ifndef INOUT
  57. #define INOUT
  58. #endif
  59. // @field[OPTIONAL | REQUIRED | REPEATED]
  60. /*
  61. * 字段描述宏:
  62. * OPTIONAL => 可选字段
  63. * REQUIRED => 必需字段
  64. * REPEATED => 可重复字段
  65. *
  66. */
  67. #ifndef OPTIONAL
  68. #define OPTIONAL
  69. #endif
  70. #ifndef REQUIRED
  71. #define REQUIRED
  72. #endif
  73. #ifndef REPEATED
  74. #define REPEATED
  75. #endif
  76. #ifdef __cplusplus
  77. /*
  78. * @NOTE:extern "C"的作用
  79. * 由于C++支持函数重载,而C语言不支持,因此函数被C++编译后在符号库中的名字是与C语言不同的;
  80. * C++编译后的函数需要加上参数的类型才能唯一标定重载后的函数,
  81. * 加上extern "C",是为了向编译器指明这段代码按照C语言的方式进行编译。
  82. *
  83. */
  84. #ifndef EXTERN_C
  85. #define EXTERN_C extern "C"
  86. #endif
  87. #ifndef BEGIN_EXTERN_C
  88. #define BEGIN_EXTERN_C extern "C" {
  89. #endif
  90. #ifndef END_EXTERN_C
  91. #define END_EXTERN_C } // extern "C"
  92. #endif
  93. // 命名空间声明宏
  94. #ifndef BEGIN_NAMESPACE
  95. #define BEGIN_NAMESPACE(ns) namespace ns {
  96. #endif
  97. #ifndef END_NAMESPACE
  98. #define END_NAMESPACE(ns) } // namespace ns
  99. #endif
  100. #ifndef USING_NAMESPACE
  101. #define USING_NAMESPACE(ns) using namespace ns;
  102. #endif
  103. // 缺省值
  104. #ifndef DEFAULT
  105. #define DEFAULT(x) = x
  106. #endif
  107. // 枚举类型声明
  108. #ifndef ENUM
  109. #define ENUM(e) enum e
  110. #endif
  111. // 结构体类型声明
  112. #ifndef STRUCT
  113. #define STRUCT(s) struct s
  114. #endif
  115. #else
  116. #define EXTERN_C extern
  117. #define BEGIN_EXTERN_C
  118. #define END_EXTERN_C
  119. #define BEGIN_NAMESPACE(ns)
  120. #define END_NAMESPACE(ns)
  121. #define USING_NAMESPACE(ns)
  122. #ifndef DEFAULT
  123. #define DEFAULT(x)
  124. #endif
  125. #ifndef ENUM
  126. #define ENUM(e)\
  127. typedef enum e e;\
  128. enum e
  129. #endif
  130. #ifndef STRUCT
  131. #define STRUCT(s)\
  132. typedef struct s s;\
  133. struct s
  134. #endif
  135. #endif // __cplusplus
  136. #define BEGIN_NAMESPACE_HV BEGIN_NAMESPACE(hv)
  137. #define END_NAMESPACE_HV END_NAMESPACE(hv)
  138. #define USING_NAMESPACE_HV USING_NAMESPACE(hv)
  139. // MSVC ports
  140. #ifdef _MSC_VER
  141. #if _MSC_VER < 1900 // < VS2015
  142. #ifndef __cplusplus
  143. #ifndef inline
  144. #define inline __inline
  145. #endif
  146. #endif
  147. #ifndef snprintf
  148. #define snprintf _snprintf
  149. #endif
  150. #endif
  151. #endif
  152. #endif // HV_EXPORT_H_