1// Copyright (C) 2017 Lorenz Haas
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QMQTTTOPICNAME_H
5#define QMQTTTOPICNAME_H
6
7#include <QtMqtt/qmqttglobal.h>
8
9#include <QtCore/QExplicitlySharedDataPointer>
10#include <QtCore/QMetaType>
11#include <QtCore/QString>
12#include <QtCore/QStringList>
13
14QT_BEGIN_NAMESPACE
15
16class QMqttTopicNamePrivate;
17
18class QMqttTopicName;
19// qHash is a friend, but we can't use default arguments for friends (ยง8.3.6.4)
20Q_MQTT_EXPORT size_t qHash(const QMqttTopicName &name, size_t seed = 0) Q_DECL_NOTHROW;
21
22class Q_MQTT_EXPORT QMqttTopicName
23{
24public:
25 QMqttTopicName(const QString &name = QString());
26 QMqttTopicName(const QLatin1String &name);
27 QMqttTopicName(const QMqttTopicName &name);
28 ~QMqttTopicName();
29 QMqttTopicName &operator=(const QMqttTopicName &name);
30
31#ifdef Q_COMPILER_RVALUE_REFS
32 QMqttTopicName &operator=(QMqttTopicName &&other) noexcept { swap(other); return *this; }
33#endif
34
35 void swap(QMqttTopicName &other) noexcept { d.swap(other&: other.d); }
36
37 QString name() const;
38 void setName(const QString &name);
39
40 Q_REQUIRED_RESULT bool isValid() const;
41 Q_REQUIRED_RESULT int levelCount() const;
42 Q_REQUIRED_RESULT QStringList levels() const;
43
44 friend Q_MQTT_EXPORT bool operator==(const QMqttTopicName &lhs, const QMqttTopicName &rhs) Q_DECL_NOTHROW;
45 friend inline bool operator!=(const QMqttTopicName &lhs, const QMqttTopicName &rhs) Q_DECL_NOTHROW { return !(lhs == rhs); }
46 friend Q_MQTT_EXPORT bool operator<(const QMqttTopicName &lhs, const QMqttTopicName &rhs) Q_DECL_NOTHROW;
47 friend Q_MQTT_EXPORT size_t qHash(const QMqttTopicName &name, size_t seed) Q_DECL_NOTHROW;
48
49private:
50 QExplicitlySharedDataPointer<QMqttTopicNamePrivate> d;
51};
52
53Q_DECLARE_SHARED(QMqttTopicName)
54
55#ifndef QT_NO_DATASTREAM
56Q_MQTT_EXPORT QDataStream &operator<<(QDataStream &, const QMqttTopicName &);
57Q_MQTT_EXPORT QDataStream &operator>>(QDataStream &, QMqttTopicName &);
58#endif
59
60#ifndef QT_NO_DEBUG_STREAM
61Q_MQTT_EXPORT QDebug operator<<(QDebug, const QMqttTopicName &);
62#endif
63
64QT_END_NAMESPACE
65
66Q_DECLARE_METATYPE(QMqttTopicName)
67
68#endif // QMQTTTOPICNAME_H
69

source code of qtmqtt/src/mqtt/qmqtttopicname.h