diff options
Diffstat (limited to 'src/dbus/qdbusargument.h')
-rw-r--r-- | src/dbus/qdbusargument.h | 110 |
1 files changed, 32 insertions, 78 deletions
diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h index cfa66d348e..70f6703d2f 100644 --- a/src/dbus/qdbusargument.h +++ b/src/dbus/qdbusargument.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtDBus 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) 2016 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 QDBUSARGUMENT_H #define QDBUSARGUMENT_H @@ -81,9 +45,9 @@ public: QDBusArgument &operator=(const QDBusArgument &other); ~QDBusArgument(); - void swap(QDBusArgument &other) noexcept { qSwap(d, other.d); } + void swap(QDBusArgument &other) noexcept { qt_ptr_swap(d, other.d); } - // used for marshalling (Qt -> D-BUS) + // used for marshalling (Qt -> D-Bus) QDBusArgument &operator<<(uchar arg); QDBusArgument &operator<<(bool arg); QDBusArgument &operator<<(short arg); @@ -103,16 +67,20 @@ public: void beginStructure(); void endStructure(); - void beginArray(int elementMetaTypeId); + void beginArray(int elementMetaTypeId) + { beginArray(QMetaType(elementMetaTypeId)); } + void beginArray(QMetaType elementMetaType); void endArray(); - void beginMap(int keyMetaTypeId, int valueMetaTypeId); + void beginMap(int keyMetaTypeId, int valueMetaTypeId) + { beginMap(QMetaType(keyMetaTypeId), QMetaType(valueMetaTypeId)); } + void beginMap(QMetaType keyMetaType, QMetaType valueMetaType); void endMap(); void beginMapEntry(); void endMapEntry(); void appendVariant(const QVariant &v); - // used for de-marshalling (D-BUS -> Qt) + // used for de-marshalling (D-Bus -> Qt) QString currentSignature() const; ElementType currentType() const; @@ -153,34 +121,32 @@ protected: Q_DECLARE_SHARED(QDBusArgument) QT_END_NAMESPACE -Q_DECLARE_METATYPE(QDBusArgument) +QT_DECL_METATYPE_EXTERN(QDBusArgument, Q_DBUS_EXPORT) QT_BEGIN_NAMESPACE -// ### Qt6: remove the defaulted T * = nullptr from these two (MSVC6 work-around): -template<typename T> inline T qdbus_cast(const QDBusArgument &arg, T * = nullptr) +template<typename T> inline T qdbus_cast(const QDBusArgument &arg) { T item; arg >> item; return item; } -template<typename T> inline T qdbus_cast(const QVariant &v, T * = nullptr) +template<typename T> inline T qdbus_cast(const QVariant &v) { - int id = v.userType(); - if (id == qMetaTypeId<QDBusArgument>()) + if (v.metaType() == QMetaType::fromType<QDBusArgument>()) return qdbus_cast<T>(qvariant_cast<QDBusArgument>(v)); else return qvariant_cast<T>(v); } // specialize for QVariant, allowing it to be used in place of QDBusVariant -template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg, QVariant *) +template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg) { QDBusVariant item; arg >> item; return item.variant(); } -template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v, QVariant *) +template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v) { return qdbus_cast<QDBusVariant>(v).variant(); } @@ -228,8 +194,7 @@ template<template <typename> class Container, typename T, typename = typename Container<T>::iterator> inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<T> &list) { - int id = qMetaTypeId<T>(); - arg.beginArray(id); + arg.beginArray(QMetaType::fromType<T>()); typename Container<T>::const_iterator it = list.begin(); typename Container<T>::const_iterator end = list.end(); for ( ; it != end; ++it) @@ -256,12 +221,9 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &l inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list) { - int id = qMetaTypeId<QDBusVariant>(); - arg.beginArray(id); - QVariantList::ConstIterator it = list.constBegin(); - QVariantList::ConstIterator end = list.constEnd(); - for ( ; it != end; ++it) - arg << QDBusVariant(*it); + arg.beginArray(QMetaType::fromType<QDBusVariant>()); + for (const QVariant &value : list) + arg << QDBusVariant(value); arg.endArray(); return arg; } @@ -271,9 +233,7 @@ template <template <typename, typename> class Container, typename Key, typename QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true> inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &map) { - int kid = qMetaTypeId<Key>(); - int vid = qMetaTypeId<T>(); - arg.beginMap(kid, vid); + arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>()); auto it = map.begin(); auto end = map.end(); for ( ; it != end; ++it) { @@ -289,9 +249,7 @@ template <template <typename, typename> class Container, typename Key, typename QtPrivate::IfAssociativeIteratorHasFirstAndSecond<typename Container<Key, T>::iterator> = true> inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &map) { - int kid = qMetaTypeId<Key>(); - int vid = qMetaTypeId<T>(); - arg.beginMap(kid, vid); + arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>()); auto it = map.begin(); auto end = map.end(); for ( ; it != end; ++it) { @@ -304,7 +262,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &ma } template <template <typename, typename> class Container, typename Key, typename T, - typename = typename Container<Key, T>::iterator> + QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true> inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key, T> &map) { arg.beginMap(); @@ -323,12 +281,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key, inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map) { - arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>()); - QVariantMap::ConstIterator it = map.constBegin(); - QVariantMap::ConstIterator end = map.constEnd(); - for ( ; it != end; ++it) { + arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>()); + for (const auto &[key, value] : map.asKeyValueRange()) { arg.beginMapEntry(); - arg << it.key() << QDBusVariant(it.value()); + arg << key << QDBusVariant(value); arg.endMapEntry(); } arg.endMap(); @@ -337,12 +293,10 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map) inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map) { - arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>()); - QVariantHash::ConstIterator it = map.constBegin(); - QVariantHash::ConstIterator end = map.constEnd(); - for ( ; it != end; ++it) { + arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>()); + for (const auto &[key, value] : map.asKeyValueRange()) { arg.beginMapEntry(); - arg << it.key() << QDBusVariant(it.value()); + arg << key << QDBusVariant(value); arg.endMapEntry(); } arg.endMap(); @@ -350,7 +304,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map) } template <typename T1, typename T2> -inline QDBusArgument &operator<<(QDBusArgument &arg, const QPair<T1, T2> &pair) +inline QDBusArgument &operator<<(QDBusArgument &arg, const std::pair<T1, T2> &pair) { arg.beginStructure(); arg << pair.first << pair.second; @@ -359,7 +313,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QPair<T1, T2> &pair) } template <typename T1, typename T2> -inline const QDBusArgument &operator>>(const QDBusArgument &arg, QPair<T1, T2> &pair) +inline const QDBusArgument &operator>>(const QDBusArgument &arg, std::pair<T1, T2> &pair) { arg.beginStructure(); arg >> pair.first >> pair.second; |