]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layout/LESwaps.h
4 * (C) Copyright IBM Corp. 1998-2005 - All Rights Reserved
15 * \brief C++ API: Endian independent access to data for LayoutEngine
21 * A convenience macro which invokes the swapWord member function
22 * from a concise call.
26 #if defined(U_IS_BIG_ENDIAN)
28 #define SWAPW(value) (value)
30 #define SWAPW(value) LESwaps::swapWord(value)
33 #define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))
37 * A convenience macro which invokes the swapLong member function
38 * from a concise call.
42 #if defined(U_IS_BIG_ENDIAN)
44 #define SWAPL(value) (value)
46 #define SWAPL(value) LESwaps::swapLong(value)
49 #define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))
53 * This class is used to access data which stored in big endian order
54 * regardless of the conventions of the platform. It has been designed
55 * to automatically detect the endian-ness of the platform, so that a
56 * compilation flag is not needed.
58 * All methods are static and inline in an attempt to induce the compiler
59 * to do most of the calculations at compile time.
63 class U_LAYOUT_API LESwaps
/* not : public UObject because all methods are static */ {
66 #if !defined(U_IS_BIG_ENDIAN)
68 * This method detects the endian-ness of the platform by
69 * casting a pointer to a word to a pointer to a byte. On
70 * big endian platforms the FF will be in the byte with the
71 * lowest address. On little endian platforms, the FF will
72 * be in the byte with the highest address.
74 * @return TRUE if the platform is big endian
78 static le_uint8
isBigEndian()
80 const le_uint16 word
= 0xFF00;
82 return *((le_uint8
*) &word
);
87 * This method does the byte swap required on little endian platforms
88 * to correctly access a (16-bit) word.
90 * @param value - the word to be byte swapped
92 * @return the byte swapped word
96 static le_uint16
swapWord(le_uint16 value
)
98 return (((le_uint8
) (value
>> 8)) | (value
<< 8));
102 * This method does the byte swapping required on little endian platforms
103 * to correctly access a (32-bit) long.
105 * @param value - the long to be byte swapped
107 * @return the byte swapped long
111 static le_uint32
swapLong(le_uint32 value
)
113 return swapWord((le_uint16
) (value
>> 16)) | (swapWord((le_uint16
) value
) << 16);
117 LESwaps() {} // private - forbid instantiation