ICU 56.1: LESwaps.h Source File

ICU 56.1 56.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

LESwaps.h
Go to the documentation of this file.
1 /*
2 *
3 * (C) Copyright IBM Corp. 1998-2014 - All Rights Reserved
4 *
5 */
6
7 #ifndef __LESWAPS_H
8 #define __LESWAPS_H
9
10 #include "LETypes.h"
11
17 U_NAMESPACE_BEGIN
18
25 #define SWAPW(value) LESwaps::swapWord((le_uint16)(value))
26
33 #define SWAPL(value) LESwaps::swapLong((le_uint32)(value))
34
44 class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
45 public:
46
57 static le_uint16 swapWord(le_uint16 value)
58 {
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
69 };
70
81 static le_uint32 swapLong(le_uint32 value)
82 {
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
93 };
94
95 private:
96 LESwaps() {} // private - forbid instantiation
97 };
98
99 U_NAMESPACE_END
100 #endif
le_uint32
uint32_t le_uint32
A type used for unsigned, 32-bit integers.
Definition: LETypes.h:41
le_uint16
uint16_t le_uint16
A type used for unsigned, 16-bit integers.
Definition: LETypes.h:55
U_LAYOUT_API
#define U_LAYOUT_API
Set to export library symbols from inside the layout engine library, and to import them from outside...
Definition: utypes.h:359
icu::LESwaps
This class is used to access data which stored in big endian order regardless of the conventions of t...
Definition: LESwaps.h:44
LETypes.h
C API: Basic definitions for the ICU LayoutEngine.
icu::LESwaps::swapWord
static le_uint16 swapWord(le_uint16 value)
Reads a big-endian 16-bit word and returns a native-endian value.
Definition: LESwaps.h:57
U_NAMESPACE_BEGIN
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
icu::LESwaps::swapLong
static le_uint32 swapLong(le_uint32 value)
Reads a big-endian 32-bit word and returns a native-endian value.
Definition: LESwaps.h:81
le_uint8
uint8_t le_uint8
A type used for unsigned, 8-bit integers.
Definition: LETypes.h:69
U_NAMESPACE_END
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130