00001
00002
00003
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 {
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
00063 return value;
00064 #else
00065
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
00087 return value;
00088 #else
00089
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() {}
00097 };
00098
00099 U_NAMESPACE_END
00100 #endif