diff options
Diffstat (limited to 'src/corelib/tools/qshareddata.h')
-rw-r--r-- | src/corelib/tools/qshareddata.h | 63 |
1 files changed, 19 insertions, 44 deletions
diff --git a/src/corelib/tools/qshareddata.h b/src/corelib/tools/qshareddata.h index 717e33770e..4c4153a506 100644 --- a/src/corelib/tools/qshareddata.h +++ b/src/corelib/tools/qshareddata.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QSHAREDDATA_H #define QSHAREDDATA_H @@ -85,15 +49,19 @@ public: const T *data() const noexcept { return d; } const T *get() const noexcept { return d; } const T *constData() const noexcept { return d; } - T *take() noexcept { return qExchange(d, nullptr); } + T *take() noexcept { return std::exchange(d, nullptr); } + Q_NODISCARD_CTOR QSharedDataPointer() noexcept : d(nullptr) { } ~QSharedDataPointer() { if (d && !d->ref.deref()) delete d; } + Q_NODISCARD_CTOR explicit QSharedDataPointer(T *data) noexcept : d(data) { if (d) d->ref.ref(); } + Q_NODISCARD_CTOR QSharedDataPointer(T *data, QAdoptSharedDataTag) noexcept : d(data) {} + Q_NODISCARD_CTOR QSharedDataPointer(const QSharedDataPointer &o) noexcept : d(o.d) { if (d) d->ref.ref(); } @@ -102,7 +70,7 @@ public: if (ptr != d) { if (ptr) ptr->ref.ref(); - T *old = qExchange(d, ptr); + T *old = std::exchange(d, ptr); if (old && !old->ref.deref()) delete old; } @@ -118,7 +86,8 @@ public: reset(o); return *this; } - QSharedDataPointer(QSharedDataPointer &&o) noexcept : d(qExchange(o.d, nullptr)) {} + Q_NODISCARD_CTOR + QSharedDataPointer(QSharedDataPointer &&o) noexcept : d(std::exchange(o.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QSharedDataPointer) operator bool () const noexcept { return d != nullptr; } @@ -171,21 +140,26 @@ public: T *data() const noexcept { return d; } T *get() const noexcept { return d; } const T *constData() const noexcept { return d; } - T *take() noexcept { return qExchange(d, nullptr); } + T *take() noexcept { return std::exchange(d, nullptr); } void detach() { if (d && d->ref.loadRelaxed() != 1) detach_helper(); } + Q_NODISCARD_CTOR QExplicitlySharedDataPointer() noexcept : d(nullptr) { } ~QExplicitlySharedDataPointer() { if (d && !d->ref.deref()) delete d; } + Q_NODISCARD_CTOR explicit QExplicitlySharedDataPointer(T *data) noexcept : d(data) { if (d) d->ref.ref(); } + Q_NODISCARD_CTOR QExplicitlySharedDataPointer(T *data, QAdoptSharedDataTag) noexcept : d(data) {} + Q_NODISCARD_CTOR QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer &o) noexcept : d(o.d) { if (d) d->ref.ref(); } template<typename X> + Q_NODISCARD_CTOR QExplicitlySharedDataPointer(const QExplicitlySharedDataPointer<X> &o) noexcept #ifdef QT_ENABLE_QEXPLICITLYSHAREDDATAPOINTER_STATICCAST : d(static_cast<T *>(o.data())) @@ -199,7 +173,7 @@ public: if (ptr != d) { if (ptr) ptr->ref.ref(); - T *old = qExchange(d, ptr); + T *old = std::exchange(d, ptr); if (old && !old->ref.deref()) delete old; } @@ -215,7 +189,8 @@ public: reset(o); return *this; } - QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) noexcept : d(qExchange(o.d, nullptr)) {} + Q_NODISCARD_CTOR + QExplicitlySharedDataPointer(QExplicitlySharedDataPointer &&o) noexcept : d(std::exchange(o.d, nullptr)) {} QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QExplicitlySharedDataPointer) operator bool () const noexcept { return d != nullptr; } |