]>
git.saurik.com Git - apple/icu.git/blob - icuSources/layout/LESwaps.h
4 * (C) Copyright IBM Corp. 1998-2008 - 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 #define SWAPW(value) LESwaps::swapWord((const le_uint16 &) (value))
29 * A convenience macro which invokes the swapLong member function
30 * from a concise call.
34 #define SWAPL(value) LESwaps::swapLong((const le_uint32 &) (value))
37 * This class is used to access data which stored in big endian order
38 * regardless of the conventions of the platform.
40 * All methods are static and inline in an attempt to induce the compiler
41 * to do most of the calculations at compile time.
45 class U_LAYOUT_API LESwaps
/* not : public UObject because all methods are static */ {
49 * This method does the byte swap required on little endian platforms
50 * to correctly access a (16-bit) word.
52 * @param value - the word to be byte swapped
54 * @return the byte swapped word
58 static le_uint16
swapWord(const le_uint16
&value
)
60 const le_uint8
*p
= (const le_uint8
*) &value
;
62 return ((p
[0] << 8) + p
[1]);
66 * This method does the byte swapping required on little endian platforms
67 * to correctly access a (32-bit) long.
69 * @param value - the long to be byte swapped
71 * @return the byte swapped long
75 static le_uint32
swapLong(const le_uint32
&value
)
77 const le_uint8
*p
= (const le_uint8
*) &value
;
79 return ((p
[0] << 24) + (p
[1] << 16) + (p
[2] << 8) + p
[3]);
83 LESwaps() {} // private - forbid instantiation