1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QDBUSEXTRATYPES_H |
5 | #define |
6 | |
7 | // define some useful types for D-BUS |
8 | |
9 | #include <QtDBus/qtdbusglobal.h> |
10 | #include <QtCore/qvariant.h> |
11 | #include <QtCore/qstring.h> |
12 | #include <QtCore/qhashfunctions.h> |
13 | |
14 | #ifndef QT_NO_DBUS |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | class Q_DBUS_EXPORT QDBusObjectPath |
19 | { |
20 | QString m_path; |
21 | public: |
22 | QDBusObjectPath() noexcept : m_path() {} |
23 | // compiler-generated copy/move constructor/assignment operators are ok! |
24 | // compiler-generated destructor is ok! |
25 | |
26 | inline explicit QDBusObjectPath(const char *path); |
27 | inline explicit QDBusObjectPath(QLatin1StringView path); |
28 | inline explicit QDBusObjectPath(const QString &path); |
29 | explicit QDBusObjectPath(QString &&p) : m_path(std::move(p)) { doCheck(); } |
30 | |
31 | void swap(QDBusObjectPath &other) noexcept { m_path.swap(other&: other.m_path); } |
32 | |
33 | inline void setPath(const QString &path); |
34 | |
35 | inline QString path() const |
36 | { return m_path; } |
37 | |
38 | operator QVariant() const; |
39 | |
40 | private: |
41 | void doCheck(); |
42 | }; |
43 | Q_DECLARE_SHARED(QDBusObjectPath) |
44 | |
45 | inline QDBusObjectPath::QDBusObjectPath(const char *objectPath) |
46 | : m_path(QString::fromLatin1(ba: objectPath)) |
47 | { doCheck(); } |
48 | |
49 | inline QDBusObjectPath::QDBusObjectPath(QLatin1StringView objectPath) |
50 | : m_path(objectPath) |
51 | { doCheck(); } |
52 | |
53 | inline QDBusObjectPath::QDBusObjectPath(const QString &objectPath) |
54 | : m_path(objectPath) |
55 | { doCheck(); } |
56 | |
57 | inline void QDBusObjectPath::setPath(const QString &objectPath) |
58 | { m_path = objectPath; doCheck(); } |
59 | |
60 | inline bool operator==(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs) |
61 | { return lhs.path() == rhs.path(); } |
62 | |
63 | inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs) |
64 | { return lhs.path() != rhs.path(); } |
65 | |
66 | inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs) |
67 | { return lhs.path() < rhs.path(); } |
68 | |
69 | inline size_t qHash(const QDBusObjectPath &objectPath, size_t seed = 0) |
70 | { return qHash(key: objectPath.path(), seed); } |
71 | |
72 | |
73 | class Q_DBUS_EXPORT QDBusSignature |
74 | { |
75 | QString m_signature; |
76 | public: |
77 | QDBusSignature() noexcept : m_signature() {} |
78 | // compiler-generated copy/move constructor/assignment operators are ok! |
79 | // compiler-generated destructor is ok! |
80 | |
81 | inline explicit QDBusSignature(const char *signature); |
82 | inline explicit QDBusSignature(QLatin1StringView signature); |
83 | inline explicit QDBusSignature(const QString &signature); |
84 | explicit QDBusSignature(QString &&sig) : m_signature(std::move(sig)) { doCheck(); } |
85 | |
86 | void swap(QDBusSignature &other) noexcept { m_signature.swap(other&: other.m_signature); } |
87 | |
88 | inline void setSignature(const QString &signature); |
89 | |
90 | inline QString signature() const |
91 | { return m_signature; } |
92 | |
93 | private: |
94 | void doCheck(); |
95 | }; |
96 | Q_DECLARE_SHARED(QDBusSignature) |
97 | |
98 | inline QDBusSignature::QDBusSignature(const char *dBusSignature) |
99 | : m_signature(QString::fromLatin1(ba: dBusSignature)) |
100 | { doCheck(); } |
101 | |
102 | inline QDBusSignature::QDBusSignature(QLatin1StringView dBusSignature) |
103 | : m_signature(dBusSignature) |
104 | { doCheck(); } |
105 | |
106 | inline QDBusSignature::QDBusSignature(const QString &dBusSignature) |
107 | : m_signature(dBusSignature) |
108 | { doCheck(); } |
109 | |
110 | inline void QDBusSignature::setSignature(const QString &dBusSignature) |
111 | { m_signature = dBusSignature; doCheck(); } |
112 | |
113 | inline bool operator==(const QDBusSignature &lhs, const QDBusSignature &rhs) |
114 | { return lhs.signature() == rhs.signature(); } |
115 | |
116 | inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs) |
117 | { return lhs.signature() != rhs.signature(); } |
118 | |
119 | inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs) |
120 | { return lhs.signature() < rhs.signature(); } |
121 | |
122 | inline size_t qHash(const QDBusSignature &signature, size_t seed = 0) |
123 | { return qHash(key: signature.signature(), seed); } |
124 | |
125 | class QDBusVariant |
126 | { |
127 | QVariant m_variant; |
128 | public: |
129 | QDBusVariant() noexcept : m_variant() {} |
130 | // compiler-generated copy/move constructor/assignment operators are ok! |
131 | // compiler-generated destructor is ok! |
132 | |
133 | inline explicit QDBusVariant(const QVariant &variant); |
134 | explicit QDBusVariant(QVariant &&v) noexcept : m_variant(std::move(v)) {} |
135 | |
136 | void swap(QDBusVariant &other) noexcept { m_variant.swap(other&: other.m_variant); } |
137 | |
138 | inline void setVariant(const QVariant &variant); |
139 | |
140 | inline QVariant variant() const |
141 | { return m_variant; } |
142 | }; |
143 | Q_DECLARE_SHARED(QDBusVariant) |
144 | |
145 | inline QDBusVariant::QDBusVariant(const QVariant &dBusVariant) |
146 | : m_variant(dBusVariant) { } |
147 | |
148 | inline void QDBusVariant::setVariant(const QVariant &dBusVariant) |
149 | { m_variant = dBusVariant; } |
150 | |
151 | inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2) |
152 | { return v1.variant() == v2.variant(); } |
153 | |
154 | QT_END_NAMESPACE |
155 | |
156 | QT_DECL_METATYPE_EXTERN(QDBusVariant, Q_DBUS_EXPORT) |
157 | QT_DECL_METATYPE_EXTERN(QDBusObjectPath, Q_DBUS_EXPORT) |
158 | QT_DECL_METATYPE_EXTERN(QDBusSignature, Q_DBUS_EXPORT) |
159 | |
160 | #endif // QT_NO_DBUS |
161 | #endif |
162 | |