PlatformDef.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef __PLATFORMDEF_H
  2. #define __PLATFORMDEF_H
  3. #include <string>
  4. #include <vector>
  5. #include <list>
  6. #include <map>
  7. #include <set>
  8. #include <sstream>
  9. #ifdef XW64
  10. #ifdef WIN32
  11. typedef __int64 XPInt;
  12. #else
  13. typedef long long XPInt;
  14. #endif
  15. #else
  16. typedef int XPInt ;
  17. #endif
  18. #ifdef WIN32
  19. #define WIN32_LEAN_AND_MEAN
  20. #define BOOST_SPIRIT_UNICODE
  21. #include <Windows.h>
  22. #include <io.h>
  23. #define __XT(x) L ## x
  24. typedef wchar_t XCHAR;
  25. typedef __int64 XINT64;
  26. typedef unsigned __int64 XUINT64;
  27. typedef std::wstring XString;
  28. //兼容APPLE 的数据类型
  29. typedef void* CFStringRef;
  30. typedef CFStringRef CFNumberRef;
  31. typedef CFStringRef CFBooleanRef;
  32. typedef CFStringRef CFDateRef;
  33. typedef CFStringRef CFDataRef;
  34. typedef CFStringRef CFDictionaryRef;
  35. typedef CFStringRef CFArrayRef;
  36. typedef CFStringRef CFMutableDataRef;
  37. typedef CFStringRef CFMutableArrayRef;
  38. typedef CFStringRef CFMutableDictionaryRef;
  39. typedef CFStringRef CFWriteStreamRef;
  40. typedef int CFPropertyListFormat;
  41. typedef void* CFAllocatorRef;
  42. typedef void* CFPropertyListRef;
  43. typedef void* CFTypeRef;
  44. typedef void CFArrayCallBacks;
  45. typedef void CFDictionaryKeyCallBacks;
  46. typedef void CFDictionaryValueCallBacks;
  47. typedef unsigned long CFOptionFlags;
  48. typedef int CFTypeID;
  49. typedef XPInt CFIndex;
  50. typedef double CFAbsoluteTime;
  51. typedef bool Boolean;
  52. #define XFSeek _fseeki64
  53. #define XFTell _ftelli64
  54. #define XPreferredSeparator L"\\"
  55. #define _XFUNCTION_ __FUNCTIONW__
  56. #define _XFILE_ __FILEW__
  57. #define XStrLen wcslen
  58. #define XStrCpy wcscpy
  59. typedef std::wstringstream XStringStream;
  60. std::string Unicode_to_UTF8(const wchar_t* in, int len);
  61. std::string Unicode_to_Local(const wchar_t* in, int len);
  62. XString UTF8_to_Unicode(const char* in, int len);
  63. XString Local_to_Unicode(const char* in, int len);
  64. #define XStringToUTF8(str) Unicode_to_UTF8(str.c_str(),str.length())
  65. #define UTF8TOXString(str) UTF8_to_Unicode(str.c_str(),str.length())
  66. #define XStringToLocal(str) Unicode_to_Local(str.c_str(),str.length())
  67. #define LocalToXString(str) Local_to_Unicode(str.c_str(),str.length())
  68. #define UTF8TOXString2(str) UTF8_to_Unicode(str,strlen(str))
  69. typedef BITMAPINFOHEADER XBITMAPINFOHEADER;
  70. enum CFStringEncoding{
  71. kCFStringEncodingMacRoman = 0,
  72. kCFStringEncodingWindowsLatin1 = 0x0500, /* ANSI codepage 1252 */
  73. kCFStringEncodingISOLatin1 = 0x0201, /* ISO 8859-1 */
  74. kCFStringEncodingNextStepLatin = 0x0B01, /* NextStep encoding*/
  75. kCFStringEncodingASCII = 0x0600, /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */
  76. kCFStringEncodingUnicode = 0x0100, /* kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */
  77. kCFStringEncodingUTF8 = 0x08000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */
  78. kCFStringEncodingNonLossyASCII = 0x0BFF /* 7bit Unicode variants used by Cocoa & Java */
  79. };
  80. enum CFNumberType {
  81. /* Fixed-width types */
  82. kCFNumberSInt8Type = 1,
  83. kCFNumberSInt16Type = 2,
  84. kCFNumberSInt32Type = 3,
  85. kCFNumberSInt64Type = 4,
  86. kCFNumberFloat32Type = 5,
  87. kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */
  88. /* Basic C types */
  89. kCFNumberCharType = 7,
  90. kCFNumberShortType = 8,
  91. kCFNumberIntType = 9,
  92. kCFNumberLongType = 10,
  93. kCFNumberLongLongType = 11,
  94. kCFNumberFloatType = 12,
  95. kCFNumberDoubleType = 13,
  96. /* Other */
  97. kCFNumberCFIndexType = 14,
  98. kCFNumberNSIntegerType = 15,
  99. kCFNumberCGFloatType = 16,
  100. kCFNumberMaxType = 16
  101. };
  102. #else
  103. #include <CoreFoundation/CoreFoundation.h>
  104. #define __XT(x) x
  105. typedef std::string XString;
  106. typedef char XCHAR;
  107. typedef long long XINT64;
  108. typedef unsigned long long XUINT64;
  109. typedef void* HMODULE;
  110. #define XFSeek fseeko
  111. #define XFTell ftello
  112. typedef std::stringstream XStringStream;
  113. #define XPreferredSeparator "/"
  114. #define _XFUNCTION_ __FUNCTION__
  115. #define _XFILE_ __FILE__
  116. #define XStringToUTF8(str) str
  117. #define UTF8TOXString(str) str
  118. #define UTF8TOXString2(str) std::string(str)
  119. #define XStringToLocal(str) str
  120. #define LocalToXString(str) str
  121. #define XStrLen strlen
  122. #define XStrCpy strcpy
  123. //这玩意是2字节对齐
  124. #pragma pack(2)
  125. struct BITMAPFILEHEADER {
  126. unsigned short bfType;
  127. unsigned int bfSize;
  128. unsigned short bfReserved1;
  129. unsigned short bfReserved2;
  130. unsigned int bfOffBits;
  131. } ;
  132. struct XBITMAPINFOHEADER{
  133. unsigned int biSize;
  134. unsigned int biWidth;
  135. unsigned int biHeight;
  136. unsigned short biPlanes;
  137. unsigned short biBitCount;
  138. unsigned int biCompression;
  139. unsigned int biSizeImage;
  140. unsigned int biXPelsPerMeter;
  141. unsigned int biYPelsPerMeter;
  142. unsigned int biClrUsed;
  143. unsigned int biClrImportant;
  144. };
  145. #pragma pack()
  146. #endif
  147. //定义一个32,64 数字类型自适应类型,根据平台不同确定是int 还是int64
  148. typedef unsigned char byte;
  149. ///////////////////////////////////////////////////////////////////////////////
  150. inline void endian_swap(short& x)
  151. {
  152. x = (x>>8) |
  153. (x<<8);
  154. }
  155. ///////////////////////////////////////////////////////////////////////////////
  156. inline void endian_swap(unsigned short& x)
  157. {
  158. x = (x>>8) |
  159. (x<<8);
  160. }
  161. ///////////////////////////////////////////////////////////////////////////////
  162. inline void endian_swap(int& x)
  163. {
  164. x = (x>>24) |
  165. ((x<<8) & 0x00FF0000) |
  166. ((x>>8) & 0x0000FF00) |
  167. (x<<24);
  168. }
  169. ///////////////////////////////////////////////////////////////////////////////
  170. inline void endian_swap(unsigned int& x)
  171. {
  172. x = (x>>24) |
  173. ((x<<8) & 0x00FF0000) |
  174. ((x>>8) & 0x0000FF00) |
  175. (x<<24);
  176. }
  177. ///////////////////////////////////////////////////////////////////////////////
  178. inline void endian_swap(XINT64& x)
  179. {
  180. x = (x>>56) |
  181. ((x<<40) & 0x00FF000000000000) |
  182. ((x<<24) & 0x0000FF0000000000) |
  183. ((x<<8) & 0x000000FF00000000) |
  184. ((x>>8) & 0x00000000FF000000) |
  185. ((x>>24) & 0x0000000000FF0000) |
  186. ((x>>40) & 0x000000000000FF00) |
  187. (x<<56);
  188. }
  189. ///////////////////////////////////////////////////////////////////////////////
  190. inline void endian_swap(XUINT64& x)
  191. {
  192. x = (x>>56) |
  193. ((x<<40) & 0x00FF000000000000) |
  194. ((x<<24) & 0x0000FF0000000000) |
  195. ((x<<8) & 0x000000FF00000000) |
  196. ((x>>8) & 0x00000000FF000000) |
  197. ((x>>24) & 0x0000000000FF0000) |
  198. ((x>>40) & 0x000000000000FF00) |
  199. (x<<56);
  200. }
  201. #endif