#ifndef __PLATFORMDEF_H #define __PLATFORMDEF_H #include #include #include #include #include #include #ifdef XW64 #ifdef WIN32 typedef __int64 XPInt; #else typedef long long XPInt; #endif #else typedef int XPInt ; #endif #ifdef WIN32 #define WIN32_LEAN_AND_MEAN #define BOOST_SPIRIT_UNICODE #include #include #define __XT(x) L ## x typedef wchar_t XCHAR; typedef __int64 XINT64; typedef unsigned __int64 XUINT64; typedef std::wstring XString; //兼容APPLE 的数据类型 typedef void* CFStringRef; typedef CFStringRef CFNumberRef; typedef CFStringRef CFBooleanRef; typedef CFStringRef CFDateRef; typedef CFStringRef CFDataRef; typedef CFStringRef CFDictionaryRef; typedef CFStringRef CFArrayRef; typedef CFStringRef CFMutableDataRef; typedef CFStringRef CFMutableArrayRef; typedef CFStringRef CFMutableDictionaryRef; typedef CFStringRef CFWriteStreamRef; typedef int CFPropertyListFormat; typedef void* CFAllocatorRef; typedef void* CFPropertyListRef; typedef void* CFTypeRef; typedef void CFArrayCallBacks; typedef void CFDictionaryKeyCallBacks; typedef void CFDictionaryValueCallBacks; typedef unsigned long CFOptionFlags; typedef int CFTypeID; typedef XPInt CFIndex; typedef double CFAbsoluteTime; typedef bool Boolean; #define XFSeek _fseeki64 #define XFTell _ftelli64 #define XPreferredSeparator L"\\" #define _XFUNCTION_ __FUNCTIONW__ #define _XFILE_ __FILEW__ #define XStrLen wcslen #define XStrCpy wcscpy typedef std::wstringstream XStringStream; std::string Unicode_to_UTF8(const wchar_t* in, int len); std::string Unicode_to_Local(const wchar_t* in, int len); XString UTF8_to_Unicode(const char* in, int len); XString Local_to_Unicode(const char* in, int len); #define XStringToUTF8(str) Unicode_to_UTF8(str.c_str(),str.length()) #define UTF8TOXString(str) UTF8_to_Unicode(str.c_str(),str.length()) #define XStringToLocal(str) Unicode_to_Local(str.c_str(),str.length()) #define LocalToXString(str) Local_to_Unicode(str.c_str(),str.length()) #define UTF8TOXString2(str) UTF8_to_Unicode(str,strlen(str)) typedef BITMAPINFOHEADER XBITMAPINFOHEADER; enum CFStringEncoding{ kCFStringEncodingMacRoman = 0, kCFStringEncodingWindowsLatin1 = 0x0500, /* ANSI codepage 1252 */ kCFStringEncodingISOLatin1 = 0x0201, /* ISO 8859-1 */ kCFStringEncodingNextStepLatin = 0x0B01, /* NextStep encoding*/ kCFStringEncodingASCII = 0x0600, /* 0..127 (in creating CFString, values greater than 0x7F are treated as corresponding Unicode value) */ kCFStringEncodingUnicode = 0x0100, /* kTextEncodingUnicodeDefault + kTextEncodingDefaultFormat (aka kUnicode16BitFormat) */ kCFStringEncodingUTF8 = 0x08000100, /* kTextEncodingUnicodeDefault + kUnicodeUTF8Format */ kCFStringEncodingNonLossyASCII = 0x0BFF /* 7bit Unicode variants used by Cocoa & Java */ }; enum CFNumberType { /* Fixed-width types */ kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4, kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, /* 64-bit IEEE 754 */ /* Basic C types */ kCFNumberCharType = 7, kCFNumberShortType = 8, kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12, kCFNumberDoubleType = 13, /* Other */ kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16, kCFNumberMaxType = 16 }; #else #include #define __XT(x) x typedef std::string XString; typedef char XCHAR; typedef long long XINT64; typedef unsigned long long XUINT64; typedef void* HMODULE; #define XFSeek fseeko #define XFTell ftello typedef std::stringstream XStringStream; #define XPreferredSeparator "/" #define _XFUNCTION_ __FUNCTION__ #define _XFILE_ __FILE__ #define XStringToUTF8(str) str #define UTF8TOXString(str) str #define UTF8TOXString2(str) std::string(str) #define XStringToLocal(str) str #define LocalToXString(str) str #define XStrLen strlen #define XStrCpy strcpy //这玩意是2字节对齐 #pragma pack(2) struct BITMAPFILEHEADER { unsigned short bfType; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; } ; struct XBITMAPINFOHEADER{ unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; }; #pragma pack() #endif //定义一个32,64 数字类型自适应类型,根据平台不同确定是int 还是int64 typedef unsigned char byte; /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(short& x) { x = (x>>8) | (x<<8); } /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(unsigned short& x) { x = (x>>8) | (x<<8); } /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(int& x) { x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); } /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(unsigned int& x) { x = (x>>24) | ((x<<8) & 0x00FF0000) | ((x>>8) & 0x0000FF00) | (x<<24); } /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(XINT64& x) { x = (x>>56) | ((x<<40) & 0x00FF000000000000) | ((x<<24) & 0x0000FF0000000000) | ((x<<8) & 0x000000FF00000000) | ((x>>8) & 0x00000000FF000000) | ((x>>24) & 0x0000000000FF0000) | ((x>>40) & 0x000000000000FF00) | (x<<56); } /////////////////////////////////////////////////////////////////////////////// inline void endian_swap(XUINT64& x) { x = (x>>56) | ((x<<40) & 0x00FF000000000000) | ((x<<24) & 0x0000FF0000000000) | ((x<<8) & 0x000000FF00000000) | ((x>>8) & 0x00000000FF000000) | ((x>>24) & 0x0000000000FF0000) | ((x>>40) & 0x000000000000FF00) | (x<<56); } #endif