hexport.h 3.4 KB

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