]> git.saurik.com Git - apple/icu.git/blame - icuSources/layout/LESwaps.h
ICU-400.37.tar.gz
[apple/icu.git] / icuSources / layout / LESwaps.h
CommitLineData
b75a7d8f
A
1
2/*
b75a7d8f 3 *
46f4442e 4 * (C) Copyright IBM Corp. 1998-2008 - All Rights Reserved
b75a7d8f
A
5 *
6 */
7
8#ifndef __LESWAPS_H
9#define __LESWAPS_H
10
11#include "LETypes.h"
12
73c04bcf
A
13/**
14 * \file
15 * \brief C++ API: Endian independent access to data for LayoutEngine
16 */
17
b75a7d8f
A
18U_NAMESPACE_BEGIN
19
20/**
21 * A convenience macro which invokes the swapWord member function
22 * from a concise call.
23 *
374ca955 24 * @stable ICU 2.8
b75a7d8f 25 */
46f4442e 26#define SWAPW(value) LESwaps::swapWord((const le_uint16 &) (value))
b75a7d8f
A
27
28/**
29 * A convenience macro which invokes the swapLong member function
30 * from a concise call.
31 *
374ca955 32 * @stable ICU 2.8
b75a7d8f 33 */
46f4442e 34#define SWAPL(value) LESwaps::swapLong((const le_uint32 &) (value))
b75a7d8f
A
35
36/**
37 * This class is used to access data which stored in big endian order
46f4442e 38 * regardless of the conventions of the platform.
b75a7d8f
A
39 *
40 * All methods are static and inline in an attempt to induce the compiler
41 * to do most of the calculations at compile time.
42 *
374ca955 43 * @stable ICU 2.8
b75a7d8f
A
44 */
45class U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
46public:
47
b75a7d8f
A
48 /**
49 * This method does the byte swap required on little endian platforms
50 * to correctly access a (16-bit) word.
51 *
52 * @param value - the word to be byte swapped
53 *
54 * @return the byte swapped word
55 *
374ca955 56 * @stable ICU 2.8
b75a7d8f 57 */
46f4442e 58 static le_uint16 swapWord(const le_uint16 &value)
b75a7d8f 59 {
46f4442e
A
60 const le_uint8 *p = (const le_uint8 *) &value;
61
62 return ((p[0] << 8) + p[1]);
b75a7d8f
A
63 };
64
65 /**
66 * This method does the byte swapping required on little endian platforms
67 * to correctly access a (32-bit) long.
68 *
69 * @param value - the long to be byte swapped
70 *
71 * @return the byte swapped long
72 *
374ca955 73 * @stable ICU 2.8
b75a7d8f 74 */
46f4442e 75 static le_uint32 swapLong(const le_uint32 &value)
b75a7d8f 76 {
46f4442e
A
77 const le_uint8 *p = (const le_uint8 *) &value;
78
79 return ((p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]);
b75a7d8f
A
80 };
81
82private:
83 LESwaps() {} // private - forbid instantiation
84};
85
86U_NAMESPACE_END
87#endif