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