ICU 4.8.1 4.8.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) || (defined(BYTE_ORDER) && defined(BIG_ENDIAN)) || defined(__BIG_ENDIAN__) 00060 // Fastpath when we know that the platform is big-endian. 00061 return value; 00062 #else 00063 // Reads a big-endian value on any platform. 00064 const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); 00065 return (le_uint16)((p[0] << 8) | p[1]); 00066 #endif 00067 }; 00068 00079 static le_uint32 swapLong(le_uint32 value) 00080 { 00081 #if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || (defined(BYTE_ORDER) && defined(BIG_ENDIAN)) || defined(__BIG_ENDIAN__) 00082 // Fastpath when we know that the platform is big-endian. 00083 return value; 00084 #else 00085 // Reads a big-endian value on any platform. 00086 const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); 00087 return (le_uint32)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 00088 #endif 00089 }; 00090 00091 private: 00092 LESwaps() {} // private - forbid instantiation 00093 }; 00094 00095 U_NAMESPACE_END 00096 #endif