1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtDBus module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QDBUSEXTRATYPES_H
41#define QDBUSEXTRATYPES_H
42
43// define some useful types for D-BUS
44
45#include <QtDBus/qtdbusglobal.h>
46#include <QtCore/qvariant.h>
47#include <QtCore/qstring.h>
48#include <QtCore/qhashfunctions.h>
49
50#ifndef QT_NO_DBUS
51
52QT_BEGIN_NAMESPACE
53
54class Q_DBUS_EXPORT QDBusObjectPath
55{
56 QString m_path;
57public:
58 QDBusObjectPath() noexcept : m_path() {}
59 // compiler-generated copy/move constructor/assignment operators are ok!
60 // compiler-generated destructor is ok!
61
62 inline explicit QDBusObjectPath(const char *path);
63 inline explicit QDBusObjectPath(QLatin1String path);
64 inline explicit QDBusObjectPath(const QString &path);
65 explicit QDBusObjectPath(QString &&p) : m_path(std::move(p)) { doCheck(); }
66
67 void swap(QDBusObjectPath &other) noexcept { qSwap(m_path, other.m_path); }
68
69 inline void setPath(const QString &path);
70
71 inline QString path() const
72 { return m_path; }
73
74 operator QVariant() const;
75
76private:
77 void doCheck();
78};
79Q_DECLARE_SHARED(QDBusObjectPath)
80
81inline QDBusObjectPath::QDBusObjectPath(const char *objectPath)
82 : m_path(QString::fromLatin1(objectPath))
83{ doCheck(); }
84
85inline QDBusObjectPath::QDBusObjectPath(QLatin1String objectPath)
86 : m_path(objectPath)
87{ doCheck(); }
88
89inline QDBusObjectPath::QDBusObjectPath(const QString &objectPath)
90 : m_path(objectPath)
91{ doCheck(); }
92
93inline void QDBusObjectPath::setPath(const QString &objectPath)
94{ m_path = objectPath; doCheck(); }
95
96inline bool operator==(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
97{ return lhs.path() == rhs.path(); }
98
99inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
100{ return lhs.path() != rhs.path(); }
101
102inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
103{ return lhs.path() < rhs.path(); }
104
105inline size_t qHash(const QDBusObjectPath &objectPath, size_t seed = 0)
106{ return qHash(objectPath.path(), seed); }
107
108
109class Q_DBUS_EXPORT QDBusSignature
110{
111 QString m_signature;
112public:
113 QDBusSignature() noexcept : m_signature() {}
114 // compiler-generated copy/move constructor/assignment operators are ok!
115 // compiler-generated destructor is ok!
116
117 inline explicit QDBusSignature(const char *signature);
118 inline explicit QDBusSignature(QLatin1String signature);
119 inline explicit QDBusSignature(const QString &signature);
120 explicit QDBusSignature(QString &&sig) : m_signature(std::move(sig)) { doCheck(); }
121
122 void swap(QDBusSignature &other) noexcept { qSwap(m_signature, other.m_signature); }
123
124 inline void setSignature(const QString &signature);
125
126 inline QString signature() const
127 { return m_signature; }
128
129private:
130 void doCheck();
131};
132Q_DECLARE_SHARED(QDBusSignature)
133
134inline QDBusSignature::QDBusSignature(const char *dBusSignature)
135 : m_signature(QString::fromLatin1(dBusSignature))
136{ doCheck(); }
137
138inline QDBusSignature::QDBusSignature(QLatin1String dBusSignature)
139 : m_signature(dBusSignature)
140{ doCheck(); }
141
142inline QDBusSignature::QDBusSignature(const QString &dBusSignature)
143 : m_signature(dBusSignature)
144{ doCheck(); }
145
146inline void QDBusSignature::setSignature(const QString &dBusSignature)
147{ m_signature = dBusSignature; doCheck(); }
148
149inline bool operator==(const QDBusSignature &lhs, const QDBusSignature &rhs)
150{ return lhs.signature() == rhs.signature(); }
151
152inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs)
153{ return lhs.signature() != rhs.signature(); }
154
155inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs)
156{ return lhs.signature() < rhs.signature(); }
157
158inline size_t qHash(const QDBusSignature &signature, size_t seed = 0)
159{ return qHash(signature.signature(), seed); }
160
161class QDBusVariant
162{
163 QVariant m_variant;
164public:
165 QDBusVariant() noexcept : m_variant() {}
166 // compiler-generated copy/move constructor/assignment operators are ok!
167 // compiler-generated destructor is ok!
168
169 inline explicit QDBusVariant(const QVariant &variant);
170 explicit QDBusVariant(QVariant &&v) noexcept : m_variant(std::move(v)) {}
171
172 void swap(QDBusVariant &other) noexcept { qSwap(m_variant, other.m_variant); }
173
174 inline void setVariant(const QVariant &variant);
175
176 inline QVariant variant() const
177 { return m_variant; }
178};
179Q_DECLARE_SHARED(QDBusVariant)
180
181inline QDBusVariant::QDBusVariant(const QVariant &dBusVariant)
182 : m_variant(dBusVariant) { }
183
184inline void QDBusVariant::setVariant(const QVariant &dBusVariant)
185{ m_variant = dBusVariant; }
186
187inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2)
188{ return v1.variant() == v2.variant(); }
189
190QT_END_NAMESPACE
191
192Q_DECLARE_METATYPE(QDBusVariant)
193Q_DECLARE_METATYPE(QDBusObjectPath)
194Q_DECLARE_METATYPE(QDBusSignature)
195
196#endif // QT_NO_DBUS
197#endif
198

source code of qtbase/src/dbus/qdbusextratypes.h