0N/A/*
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A *
0N/A */
0N/A
0N/A
0N/A/*
0N/A *
3171N/A * (C) Copyright IBM Corp. 1998-2010 - All Rights Reserved
0N/A *
0N/A */
0N/A
0N/A#ifndef __LESWAPS_H
0N/A#define __LESWAPS_H
0N/A
0N/A#include "LETypes.h"
0N/A
1693N/A/**
1693N/A * \file
1693N/A * \brief C++ API: Endian independent access to data for LayoutEngine
1693N/A */
1693N/A
1693N/AU_NAMESPACE_BEGIN
0N/A
0N/A/**
0N/A * A convenience macro which invokes the swapWord member function
0N/A * from a concise call.
0N/A *
0N/A * @stable ICU 2.8
0N/A */
0N/A#if defined(U_IS_BIG_ENDIAN)
0N/A #if U_IS_BIG_ENDIAN
0N/A #define SWAPW(value) (value)
0N/A #else
0N/A #define SWAPW(value) LESwaps::swapWord(value)
0N/A #endif
0N/A#else
0N/A #define SWAPW(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapWord(value))
0N/A#endif
0N/A
0N/A/**
0N/A * A convenience macro which invokes the swapLong member function
0N/A * from a concise call.
0N/A *
0N/A * @stable ICU 2.8
0N/A */
0N/A#if defined(U_IS_BIG_ENDIAN)
0N/A #if U_IS_BIG_ENDIAN
0N/A #define SWAPL(value) (value)
0N/A #else
0N/A #define SWAPL(value) LESwaps::swapLong(value)
0N/A #endif
0N/A#else
0N/A #define SWAPL(value) (LESwaps::isBigEndian() ? (value) : LESwaps::swapLong(value))
0N/A#endif
0N/A
0N/A/**
0N/A * This class is used to access data which stored in big endian order
0N/A * regardless of the conventions of the platform. It has been designed
0N/A * to automatically detect the endian-ness of the platform, so that a
0N/A * compilation flag is not needed.
0N/A *
0N/A * All methods are static and inline in an attempt to induce the compiler
0N/A * to do most of the calculations at compile time.
0N/A *
0N/A * @stable ICU 2.8
0N/A */
1693N/Aclass U_LAYOUT_API LESwaps /* not : public UObject because all methods are static */ {
0N/Apublic:
0N/A
0N/A#if !defined(U_IS_BIG_ENDIAN)
0N/A /**
0N/A * This method detects the endian-ness of the platform by
0N/A * casting a pointer to a word to a pointer to a byte. On
0N/A * big endian platforms the FF will be in the byte with the
0N/A * lowest address. On little endian platforms, the FF will
0N/A * be in the byte with the highest address.
0N/A *
0N/A * @return TRUE if the platform is big endian
0N/A *
0N/A * @stable ICU 2.8
0N/A */
0N/A static le_uint8 isBigEndian()
0N/A {
0N/A const le_uint16 word = 0xFF00;
0N/A
0N/A return *((le_uint8 *) &word);
0N/A };
0N/A#endif
0N/A
0N/A /**
0N/A * This method does the byte swap required on little endian platforms
0N/A * to correctly access a (16-bit) word.
0N/A *
0N/A * @param value - the word to be byte swapped
0N/A *
0N/A * @return the byte swapped word
0N/A *
0N/A * @stable ICU 2.8
0N/A */
0N/A static le_uint16 swapWord(le_uint16 value)
0N/A {
0N/A return (((le_uint8) (value >> 8)) | (value << 8));
0N/A };
0N/A
0N/A /**
0N/A * This method does the byte swapping required on little endian platforms
0N/A * to correctly access a (32-bit) long.
0N/A *
0N/A * @param value - the long to be byte swapped
0N/A *
0N/A * @return the byte swapped long
0N/A *
0N/A * @stable ICU 2.8
0N/A */
0N/A static le_uint32 swapLong(le_uint32 value)
0N/A {
0N/A return swapWord((le_uint16) (value >> 16)) | (swapWord((le_uint16) value) << 16);
0N/A };
0N/A
0N/Aprivate:
0N/A LESwaps() {} // private - forbid instantiation
0N/A};
0N/A
1693N/AU_NAMESPACE_END
0N/A#endif