From e5e1fac136065d7c8afc49ac72cb517f64c87910 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 15 Jun 2017 13:04:36 +0200 Subject: Move endian integers to qendian_p.h The endian integers have more use than just in QJson, and is already used separately by QtDeclarative. This patch moves q_littleendian out of qjson_p.h and matches it with a corresponding q_bigendian, and puts it to use in simplifying endian handling in the ico image handler. Change-Id: I975bb701a089256db8ced3cb53b4bd62cdfb02dd Reviewed-by: Thiago Macieira --- src/corelib/global/qendian_p.h | 141 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) create mode 100644 src/corelib/global/qendian_p.h (limited to 'src/corelib/global/qendian_p.h') diff --git a/src/corelib/global/qendian_p.h b/src/corelib/global/qendian_p.h new file mode 100644 index 0000000000..b279701a31 --- /dev/null +++ b/src/corelib/global/qendian_p.h @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QENDIAN_P_H +#define QENDIAN_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "qendian.h" + +QT_BEGIN_NAMESPACE + +template +class QSpecialInteger +{ + typedef typename S::StorageType T; + T val; +public: + QSpecialInteger() = default; + explicit Q_DECL_CONSTEXPR QSpecialInteger(T i) : val(S::toSpecial(i)) {} + + QSpecialInteger &operator =(T i) { val = S::toSpecial(i); return *this; } + operator T() const { return S::fromSpecial(val); } + + bool operator ==(QSpecialInteger i) const { return val == i.val; } + bool operator !=(QSpecialInteger i) const { return val != i.val; } + + QSpecialInteger &operator +=(T i) + { return (*this = S::fromSpecial(val) + i); } + QSpecialInteger &operator -=(T i) + { return (*this = S::fromSpecial(val) - i); } + QSpecialInteger &operator *=(T i) + { return (*this = S::fromSpecial(val) * i); } + QSpecialInteger &operator >>=(T i) + { return (*this = S::fromSpecial(val) >> i); } + QSpecialInteger &operator <<=(T i) + { return (*this = S::fromSpecial(val) << i); } + QSpecialInteger &operator /=(T i) + { return (*this = S::fromSpecial(val) / i); } + QSpecialInteger &operator %=(T i) + { return (*this = S::fromSpecial(val) % i); } + QSpecialInteger &operator |=(T i) + { return (*this = S::fromSpecial(val) | i); } + QSpecialInteger &operator &=(T i) + { return (*this = S::fromSpecial(val) & i); } + QSpecialInteger &operator ^=(T i) + { return (*this = S::fromSpecial(val) ^ i); } +}; + +template +class QLittleEndianStorageType { +public: + typedef T StorageType; + static Q_DECL_CONSTEXPR T toSpecial(T source) { return qToLittleEndian(source); } + static Q_DECL_CONSTEXPR T fromSpecial(T source) { return qFromLittleEndian(source); } +}; + +template +class QBigEndianStorageType { +public: + typedef T StorageType; + static Q_DECL_CONSTEXPR T toSpecial(T source) { return qToBigEndian(source); } + static Q_DECL_CONSTEXPR T fromSpecial(T source) { return qFromBigEndian(source); } +}; + +template +using QLEInteger = QSpecialInteger>; + +template +using QBEInteger = QSpecialInteger>; + +template +class QTypeInfo > + : public QTypeInfoMerger, T> {}; + +template +class QTypeInfo > + : public QTypeInfoMerger, T> {}; + +typedef QLEInteger qint16_le; +typedef QLEInteger qint32_le; +typedef QLEInteger qint64_le; +typedef QLEInteger quint16_le; +typedef QLEInteger quint32_le; +typedef QLEInteger quint64_le; + +typedef QBEInteger qint16_be; +typedef QBEInteger qint32_be; +typedef QBEInteger qint64_be; +typedef QBEInteger quint16_be; +typedef QBEInteger quint32_be; +typedef QBEInteger quint64_be; + +QT_END_NAMESPACE + +#endif // QENDIAN_P_H -- cgit v1.2.3