Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

LESwaps.h

Go to the documentation of this file.
00001 
00002 /*
00003  * @(#)LESwaps.h        1.3 00/03/15
00004  *
00005  * (C) Copyright IBM Corp. 1998-2003 - All Rights Reserved
00006  *
00007  */
00008 
00009 #ifndef __LESWAPS_H
00010 #define __LESWAPS_H
00011 
00012 #include "LETypes.h"
00013 
00014 U_NAMESPACE_BEGIN
00015 
00022 #if defined(U_IS_BIG_ENDIAN)
00023         #if U_IS_BIG_ENDIAN
00024                 #define SWAPW(value) (value)
00025         #else
00026                 #define SWAPW(value) LESwaps::swapWord(value)
00027         #endif
00028 #else
00029         #define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))
00030 #endif
00031 
00038 #if defined(U_IS_BIG_ENDIAN)
00039         #if U_IS_BIG_ENDIAN
00040                 #define SWAPL(value) (value)
00041         #else
00042                 #define SWAPL(value) LESwaps::swapLong(value)
00043         #endif
00044 #else
00045         #define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))
00046 #endif
00047 
00059 class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
00060 public:
00061 
00062 #if !defined(U_IS_BIG_ENDIAN)
00063 
00074     static le_uint8 isBigEndian()
00075     {
00076         const le_uint16 word = 0xFF00;
00077 
00078         return *((le_uint8 *) &word);
00079     };
00080 #endif
00081 
00092     static le_uint16 swapWord(le_uint16 value)
00093     {
00094         return (((le_uint8) (value >> 8)) | (value << 8));
00095     };
00096 
00107     static le_uint32 swapLong(le_uint32 value)
00108     {
00109         return swapWord((le_uint16) (value >> 16)) | (swapWord((le_uint16) value) << 16);
00110     };
00111 
00112 private:
00113     LESwaps() {} // private - forbid instantiation
00114 };
00115 
00116 U_NAMESPACE_END
00117 #endif

Generated on Thu Jan 29 13:22:09 2004 for ICU 2.8 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001