/**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQml 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 QFLAGPOINTER_P_H #define QFLAGPOINTER_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 QT_BEGIN_NAMESPACE template class QFlagPointer { public: inline QFlagPointer(); inline QFlagPointer(T *); inline QFlagPointer(const QFlagPointer &o); inline bool isNull() const; inline bool flag() const; inline void setFlag(); inline void clearFlag(); inline void setFlagValue(bool); inline bool flag2() const; inline void setFlag2(); inline void clearFlag2(); inline void setFlag2Value(bool); inline QFlagPointer &operator=(const QFlagPointer &o); inline QFlagPointer &operator=(T *); inline T *operator->() const; inline T *operator*() const; inline T *data() const; private: quintptr ptr_value; static const quintptr FlagBit = 0x1; static const quintptr Flag2Bit = 0x2; static const quintptr FlagsMask = FlagBit | Flag2Bit; }; template class QBiPointer { public: inline QBiPointer(); inline QBiPointer(T *); inline QBiPointer(T2 *); inline QBiPointer(const QBiPointer &o); inline bool isNull() const; inline bool isT1() const; inline bool isT2() const; inline bool flag() const; inline void setFlag(); inline void clearFlag(); inline void setFlagValue(bool); inline QBiPointer &operator=(const QBiPointer &o); inline QBiPointer &operator=(T *); inline QBiPointer &operator=(T2 *); inline T *asT1() const; inline T2 *asT2() const; private: quintptr ptr_value; static const quintptr FlagBit = 0x1; static const quintptr Flag2Bit = 0x2; static const quintptr FlagsMask = FlagBit | Flag2Bit; }; template QFlagPointer::QFlagPointer() : ptr_value(0) { } template QFlagPointer::QFlagPointer(T *v) : ptr_value(quintptr(v)) { Q_ASSERT((ptr_value & FlagsMask) == 0); } template QFlagPointer::QFlagPointer(const QFlagPointer &o) : ptr_value(o.ptr_value) { } template bool QFlagPointer::isNull() const { return 0 == (ptr_value & (~FlagsMask)); } template bool QFlagPointer::flag() const { return ptr_value & FlagBit; } template void QFlagPointer::setFlag() { ptr_value |= FlagBit; } template void QFlagPointer::clearFlag() { ptr_value &= ~FlagBit; } template void QFlagPointer::setFlagValue(bool v) { if (v) setFlag(); else clearFlag(); } template bool QFlagPointer::flag2() const { return ptr_value & Flag2Bit; } template void QFlagPointer::setFlag2() { ptr_value|= Flag2Bit; } template void QFlagPointer::clearFlag2() { ptr_value &= ~Flag2Bit; } template void QFlagPointer::setFlag2Value(bool v) { if (v) setFlag2(); else clearFlag2(); } template QFlagPointer &QFlagPointer::operator=(const QFlagPointer &o) { ptr_value = o.ptr_value; return *this; } template QFlagPointer &QFlagPointer::operator=(T *o) { Q_ASSERT((quintptr(o) & FlagsMask) == 0); ptr_value = quintptr(o) | (ptr_value & FlagsMask); return *this; } template T *QFlagPointer::operator->() const { return (T *)(ptr_value & ~FlagsMask); } template T *QFlagPointer::operator*() const { return (T *)(ptr_value & ~FlagsMask); } template T *QFlagPointer::data() const { return (T *)(ptr_value & ~FlagsMask); } template QBiPointer::QBiPointer() : ptr_value(0) { } template QBiPointer::QBiPointer(T *v) : ptr_value(quintptr(v)) { Q_ASSERT((quintptr(v) & FlagsMask) == 0); } template QBiPointer::QBiPointer(T2 *v) : ptr_value(quintptr(v) | Flag2Bit) { Q_ASSERT((quintptr(v) & FlagsMask) == 0); } template QBiPointer::QBiPointer(const QBiPointer &o) : ptr_value(o.ptr_value) { } template bool QBiPointer::isNull() const { return 0 == (ptr_value & (~FlagsMask)); } template bool QBiPointer::isT1() const { return !(ptr_value & Flag2Bit); } template bool QBiPointer::isT2() const { return ptr_value & Flag2Bit; } template bool QBiPointer::flag() const { return ptr_value & FlagBit; } template void QBiPointer::setFlag() { ptr_value |= FlagBit; } template void QBiPointer::clearFlag() { ptr_value &= ~FlagBit; } template void QBiPointer::setFlagValue(bool v) { if (v) setFlag(); else clearFlag(); } template QBiPointer &QBiPointer::operator=(const QBiPointer &o) { ptr_value = o.ptr_value; return *this; } template QBiPointer &QBiPointer::operator=(T *o) { Q_ASSERT((quintptr(o) & FlagsMask) == 0); ptr_value = quintptr(o) | (ptr_value & FlagBit); return *this; } template QBiPointer &QBiPointer::operator=(T2 *o) { Q_ASSERT((quintptr(o) & FlagsMask) == 0); ptr_value = quintptr(o) | (ptr_value & FlagBit) | Flag2Bit; return *this; } template T *QBiPointer::asT1() const { Q_ASSERT(isT1()); return (T *)(ptr_value & ~FlagsMask); } template T2 *QBiPointer::asT2() const { Q_ASSERT(isT2()); return (T2 *)(ptr_value & ~FlagsMask); } QT_END_NAMESPACE #endif // QFLAGPOINTER_P_H