]>
Commit | Line | Data |
---|---|---|
b75a7d8f | 1 | /* |
b75a7d8f | 2 | * |
b331163b | 3 | * (C) Copyright IBM Corp. 1998-2014 - All Rights Reserved |
b75a7d8f A |
4 | * |
5 | */ | |
6 | ||
7 | #ifndef __LESWAPS_H | |
8 | #define __LESWAPS_H | |
9 | ||
10 | #include "LETypes.h" | |
11 | ||
73c04bcf A |
12 | /** |
13 | * \file | |
14 | * \brief C++ API: Endian independent access to data for LayoutEngine | |
15 | */ | |
16 | ||
b75a7d8f A |
17 | U_NAMESPACE_BEGIN |
18 | ||
19 | /** | |
20 | * A convenience macro which invokes the swapWord member function | |
21 | * from a concise call. | |
22 | * | |
b331163b | 23 | * @deprecated ICU 54. See {@link icu::LayoutEngine} |
b75a7d8f | 24 | */ |
729e4ab9 | 25 | #define SWAPW(value) LESwaps::swapWord((le_uint16)(value)) |
b75a7d8f A |
26 | |
27 | /** | |
28 | * A convenience macro which invokes the swapLong member function | |
29 | * from a concise call. | |
30 | * | |
b331163b | 31 | * @deprecated ICU 54. See {@link icu::LayoutEngine} |
b75a7d8f | 32 | */ |
729e4ab9 | 33 | #define SWAPL(value) LESwaps::swapLong((le_uint32)(value)) |
b75a7d8f A |
34 | |
35 | /** | |
36 | * This class is used to access data which stored in big endian order | |
46f4442e | 37 | * regardless of the conventions of the platform. |
b75a7d8f A |
38 | * |
39 | * All methods are static and inline in an attempt to induce the compiler | |
40 | * to do most of the calculations at compile time. | |
41 | * | |
b331163b | 42 | * @deprecated ICU 54. See {@link icu::LayoutEngine} |
b75a7d8f A |
43 | */ |
44 | class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ { | |
45 | public: | |
46 | ||
b75a7d8f | 47 | /** |
4388f060 A |
48 | * Reads a big-endian 16-bit word and returns a native-endian value. |
49 | * No-op on a big-endian platform, byte-swaps on a little-endian platform. | |
b75a7d8f A |
50 | * |
51 | * @param value - the word to be byte swapped | |
52 | * | |
53 | * @return the byte swapped word | |
54 | * | |
b331163b | 55 | * @deprecated ICU 54. See {@link icu::LayoutEngine} |
b75a7d8f | 56 | */ |
729e4ab9 | 57 | static le_uint16 swapWord(le_uint16 value) |
b75a7d8f | 58 | { |
4388f060 A |
59 | #if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \ |
60 | (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \ | |
61 | defined(__BIG_ENDIAN__) | |
62 | // Fastpath when we know that the platform is big-endian. | |
63 | return value; | |
64 | #else | |
65 | // Reads a big-endian value on any platform. | |
66 | const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); | |
67 | return (le_uint16)((p[0] << 8) | p[1]); | |
68 | #endif | |
b75a7d8f A |
69 | }; |
70 | ||
71 | /** | |
4388f060 A |
72 | * Reads a big-endian 32-bit word and returns a native-endian value. |
73 | * No-op on a big-endian platform, byte-swaps on a little-endian platform. | |
b75a7d8f A |
74 | * |
75 | * @param value - the long to be byte swapped | |
76 | * | |
77 | * @return the byte swapped long | |
78 | * | |
b331163b | 79 | * @deprecated ICU 54. See {@link icu::LayoutEngine} |
b75a7d8f | 80 | */ |
729e4ab9 | 81 | static le_uint32 swapLong(le_uint32 value) |
b75a7d8f | 82 | { |
4388f060 A |
83 | #if (defined(U_IS_BIG_ENDIAN) && U_IS_BIG_ENDIAN) || \ |
84 | (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \ | |
85 | defined(__BIG_ENDIAN__) | |
86 | // Fastpath when we know that the platform is big-endian. | |
87 | return value; | |
88 | #else | |
89 | // Reads a big-endian value on any platform. | |
90 | const le_uint8 *p = reinterpret_cast<const le_uint8 *>(&value); | |
91 | return (le_uint32)((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); | |
92 | #endif | |
b75a7d8f A |
93 | }; |
94 | ||
95 | private: | |
96 | LESwaps() {} // private - forbid instantiation | |
97 | }; | |
98 | ||
99 | U_NAMESPACE_END | |
100 | #endif |