LESwaps.h

Go to the documentation of this file.
00001 
00002 /*
00003  *
00004  * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
00005  *
00006  */
00007 
00008 #ifndef __LESWAPS_H
00009 #define __LESWAPS_H
00010 
00011 #include "LETypes.h"
00012 
00018 U_NAMESPACE_BEGIN
00019 
00026 #if defined(U_IS_BIG_ENDIAN)
00027     #if U_IS_BIG_ENDIAN
00028         #define SWAPW(value) (value)
00029     #else
00030         #define SWAPW(value) LESwaps::swapWord(value)
00031     #endif
00032 #else
00033     #define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))
00034 #endif
00035 
00042 #if defined(U_IS_BIG_ENDIAN)
00043     #if U_IS_BIG_ENDIAN
00044         #define SWAPL(value) (value)
00045     #else
00046         #define SWAPL(value) LESwaps::swapLong(value)
00047     #endif
00048 #else
00049     #define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))
00050 #endif
00051 
00063 class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
00064 public:
00065 
00066 #if !defined(U_IS_BIG_ENDIAN)
00067 
00078     static le_uint8 isBigEndian()
00079     {
00080         const le_uint16 word = 0xFF00;
00081 
00082         return *((le_uint8 *) &word);
00083     };
00084 #endif
00085 
00096     static le_uint16 swapWord(le_uint16 value)
00097     {
00098         return (((le_uint8) (value >> 8)) | (value << 8));
00099     };
00100 
00111     static le_uint32 swapLong(le_uint32 value)
00112     {
00113         return swapWord((le_uint16) (value >> 16)) | (swapWord((le_uint16) value) << 16);
00114     };
00115 
00116 private:
00117     LESwaps() {} // private - forbid instantiation
00118 };
00119 
00120 U_NAMESPACE_END
00121 #endif

Generated on Mon Aug 13 07:17:24 2007 for ICU 3.6 by  doxygen 1.5.2