macros_def.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*************************************************
  2. // Copyright (C), 2017-2018, Sininm Game.
  3. // File name: macros_def.h
  4. // Author: sll
  5. // Version: 1.0
  6. // Date: 2017/08/10
  7. // Description: useful macro define
  8. // Others:
  9. // History:
  10. *************************************************/
  11. #ifndef _MACROS_H_
  12. #define _MACROS_H_
  13. //////////////////////////////////////////////////////////////////////////
  14. // platform
  15. #ifdef _WIN32
  16. #pragma execution_character_set("utf-8") //中文使用utf8存储
  17. #ifndef _PLATFORM_WINDOWS_
  18. #define _PLATFORM_WINDOWS_
  19. #endif // end of _PLATFORM_WINDOWS_
  20. #ifdef _WIN64
  21. #ifndef _PLATFORM_X64_
  22. #define _PLATFORM_X64_
  23. #endif // end of _PLATFORM_X64_
  24. #else
  25. #ifndef _PLATFORM_X32_
  26. #define _PLATFORM_X32_
  27. #endif // end of _PLATFORM_X32_
  28. #endif // _WIN64
  29. #endif // _WIN32
  30. #ifdef __linux__
  31. #ifndef _PLATFORM_LINUX_
  32. #define _PLATFORM_LINUX_
  33. #endif // end of _PLATFORM_LINUX_
  34. #ifdef __ANDROID__
  35. #ifdef __ARM_32BIT_STATE
  36. #ifndef _PLATFORM_X32_
  37. #define _PLATFORM_X32_
  38. #endif
  39. #else
  40. #ifndef _PLATFORM_X64_
  41. #define _PLATFORM_X64_
  42. #endif // end of _PLATFORM_X64_
  43. #endif
  44. #else
  45. #ifndef _PLATFORM_X64_
  46. #define _PLATFORM_X64_
  47. #endif // end of _PLATFORM_X64_
  48. #endif
  49. #endif // __linux__
  50. #ifdef __APPLE__
  51. #ifndef _PLATFORM_APPLE_
  52. #define _PLATFORM_APPLE_
  53. #endif // end of _PLATFORM_APPLE_
  54. #ifndef _PLATFORM_X64_
  55. #define _PLATFORM_X64_
  56. #endif // end of _PLATFORM_X64_
  57. #endif // __APPLE__
  58. //////////////////////////////////////////////////////////////////////////
  59. // type define
  60. // Unsigned base types.
  61. typedef float len_t;
  62. #ifdef _PLATFORM_WINDOWS_
  63. #ifndef NOMINMAX
  64. #define NOMINMAX
  65. #endif
  66. #include <stddef.h>
  67. #include <stdint.h>
  68. #pragma warning(disable: 4786)
  69. #pragma warning(disable: 4996)
  70. #pragma warning(disable: 4819)
  71. #ifndef PRId64
  72. #define PRId64 "lld"
  73. #endif
  74. #ifndef DLL_EXPORT
  75. #define DLL_EXPORT __declspec(dllexport)
  76. #endif // end of DLL_EXPORT
  77. #endif // _PLATFORM_WINDOWS_
  78. #if defined(_PLATFORM_LINUX_) || defined(_PLATFORM_APPLE_)
  79. #define _cdecl __attribute__((__cdecl__))
  80. #include <stddef.h>
  81. #include <stdint.h>
  82. #include <string.h>
  83. #ifndef stricmp
  84. #define stricmp strcasecmp
  85. #endif // end of stricmp
  86. #ifndef strnicmp
  87. #define strnicmp strncasecmp
  88. #endif // end of strnicmp
  89. #ifndef wcsicmp
  90. #define wcsicmp wcscasecmp
  91. #endif // end of wcsicmp
  92. #ifndef wcsnicmp
  93. #define wcsnicmp wcsncasecmp
  94. #endif // end of wcsnicmp
  95. #ifndef DLL_EXPORT
  96. #define DLL_EXPORT __attribute__((visibility("default")))
  97. #endif // end of DLL_EXPORT
  98. #ifndef __cdecl
  99. #define __cdecl
  100. #endif // end of __cdecl
  101. #define MAX_PATH 260
  102. #endif // _PLATFORM_LINUX_, _PLATFORM_APPLE_
  103. //////////////////////////////////////////////////////////////////////////
  104. // macro
  105. // release
  106. #ifndef SAFE_RELEASE
  107. #define SAFE_RELEASE(p) { if (p) { (p)->release(); (p) = NULL; } }
  108. #endif // end of SAFE_RELEASE
  109. // delete
  110. #ifndef SAFE_DELETE
  111. #define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } }
  112. #endif // end of SAFE_DELETE
  113. // delete array
  114. #ifndef SAFE_DELETE_ARRAY
  115. #define SAFE_DELETE_ARRAY(p) { if (p) { delete [] (p); (p) = NULL; } }
  116. #endif // end of SAFE_DELETE_ARRAY
  117. // open optimize(for function)(sample: #pragma OPTIMIZE_ON)
  118. #ifndef OPTIMIZE_ON
  119. #define OPTIMIZE_ON optimize("",on)
  120. #endif // end of OPTIMIZE_ON
  121. // close optimize((for function)(sample: #pragma OPTIMIZE_OFF)
  122. #ifndef OPTIMIZE_OFF
  123. #define OPTIMIZE_OFF optimize("",off)
  124. #endif // end of OPTIMIZE_OFF
  125. #ifndef FALSE
  126. #define FALSE 0
  127. #endif
  128. #ifndef TRUE
  129. #define TRUE 1
  130. #endif
  131. #ifndef FORCE_INLINE
  132. #define FORCE_INLINE inline
  133. #endif
  134. #ifndef _INTERFACE
  135. #define _INTERFACE class
  136. #endif // end of _INTERFACE
  137. #if defined(_PLATFORM_WINDOWS_)
  138. #elif defined(_PLATFORM_LINUX_) // end of _PLATFORM_WINDOWS_
  139. #include <signal.h>
  140. #endif // end of _PLATFORM_LINUX_
  141. FORCE_INLINE void debug_point()
  142. {
  143. #if defined(_PLATFORM_WINDOWS_)
  144. // not implement
  145. #elif defined(_PLATFORM_LINUX_) // end of _PLATFORM_WINDOWS_
  146. raise(SIGSTOP);
  147. #endif // end of _PLATFORM_LINUX_
  148. }
  149. #ifndef STRING_FACTOR
  150. #define STRING_FACTOR 4
  151. #endif
  152. #ifdef __GNUC__
  153. // #define DEPRECATED __attribute__((deprecated))
  154. #define DEPRECATED
  155. #elif defined(_MSC_VER)
  156. #define DEPRECATED __declspec(deprecated)
  157. #else
  158. #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
  159. #define DEPRECATED
  160. #endif
  161. #endif // end of _MACROS_H_