ICU 4.8.1.1
4.8.1.1
|
00001 /* 00002 * 00003 * (C) Copyright IBM Corp. 1998-2011 - All Rights Reserved 00004 * 00005 */ 00006 00007 #ifndef __LESWAPS_H 00008 #define __LESWAPS_H 00009 00010 #include "LETypes.h" 00011 00017 U_NAMESPACE_BEGIN 00018 00025 #define SWAPW(value) LESwaps::swapWord((le_uint16)(value)) 00026 00033 #define SWAPL(value) LESwaps::swapLong((le_uint32)(value)) 00034 00044 class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ { 00045 public: 00046 00057 static le_uint16 swapWord(le_uint16 value) 00058 { 00059 #if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \ 00060 (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \ 00061 defined(__BIG_ENDIAN__) 00062 // Fastpath when we know that the platform is big-endian. 00063 return value; 00064 #else 00065 // Reads a big-endian value on any platform. 00066 const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); 00067 return (le_uint16)((p[0] << 8) | p[1]); 00068 #endif 00069 }; 00070 00081 static le_uint32 swapLong(le_uint32 value) 00082 { 00083 #if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \ 00084 (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \ 00085 defined(__BIG_ENDIAN__) 00086 // Fastpath when we know that the platform is big-endian. 00087 return value; 00088 #else 00089 // Reads a big-endian value on any platform. 00090 const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); 00091 return (le_uint32)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 00092 #endif 00093 }; 00094 00095 private: 00096 LESwaps() {} // private - forbid instantiation 00097 }; 00098 00099 U_NAMESPACE_END 00100 #endif