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 QBLUETOOTHADDRESS_H |
5 | #define QBLUETOOTHADDRESS_H |
6 | |
7 | #include <QtBluetooth/qtbluetoothglobal.h> |
8 | |
9 | #include <QtCore/QByteArray> |
10 | #include <QtCore/qhashfunctions.h> |
11 | #include <QtCore/QString> |
12 | #include <QtCore/QMetaType> |
13 | #include <QtCore/QDebug> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class QT6_ONLY(Q_BLUETOOTH_EXPORT) QBluetoothAddress |
18 | { |
19 | public: |
20 | constexpr QBluetoothAddress() noexcept {}; |
21 | constexpr explicit QBluetoothAddress(quint64 address) noexcept : m_address(address) {}; |
22 | QT7_ONLY(Q_BLUETOOTH_EXPORT) |
23 | explicit QBluetoothAddress(const QString &address); |
24 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) |
25 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
26 | QBluetoothAddress(const QBluetoothAddress &other) noexcept; |
27 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
28 | ~QBluetoothAddress(); |
29 | |
30 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
31 | QBluetoothAddress &operator=(const QBluetoothAddress &other) noexcept; |
32 | QBluetoothAddress(QBluetoothAddress &&) noexcept = default; |
33 | QBluetoothAddress &operator=(QBluetoothAddress &&) noexcept = default; |
34 | #endif // Qt 6 |
35 | |
36 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
37 | bool isNull() const noexcept; |
38 | |
39 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
40 | void clear() noexcept; |
41 | |
42 | friend bool operator<(const QBluetoothAddress &a, const QBluetoothAddress &b) |
43 | { |
44 | return a.m_address < b.m_address; |
45 | } |
46 | friend bool operator==(const QBluetoothAddress &a, const QBluetoothAddress &b) |
47 | { |
48 | return a.m_address == b.m_address; |
49 | } |
50 | inline friend bool operator!=(const QBluetoothAddress &a, const QBluetoothAddress &b) |
51 | { |
52 | return a.m_address != b.m_address; |
53 | } |
54 | |
55 | QT_BLUETOOTH_INLINE_SINCE(6, 6) |
56 | quint64 toUInt64() const noexcept; |
57 | QT7_ONLY(Q_BLUETOOTH_EXPORT) |
58 | QString toString() const; |
59 | |
60 | private: |
61 | quint64 m_address = { 0 }; |
62 | friend QT7_ONLY(constexpr) size_t qHash(const QBluetoothAddress &key, size_t seed = 0) noexcept |
63 | { return qHash(key: key.m_address, seed); } |
64 | #ifndef QT_NO_DEBUG_STREAM |
65 | friend QDebug operator<<(QDebug d, const QBluetoothAddress &a) |
66 | { |
67 | return streamingOperator(d, address: a); |
68 | } |
69 | QT7_ONLY(Q_BLUETOOTH_EXPORT) |
70 | static QDebug streamingOperator(QDebug, const QBluetoothAddress &address); |
71 | #endif |
72 | }; |
73 | |
74 | #if QT_BLUETOOTH_INLINE_IMPL_SINCE(6, 6) |
75 | #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) |
76 | QBluetoothAddress::QBluetoothAddress(const QBluetoothAddress &) noexcept = default; |
77 | QBluetoothAddress &QBluetoothAddress::operator=(const QBluetoothAddress &) noexcept = default; |
78 | QBluetoothAddress::~QBluetoothAddress() = default; |
79 | #endif |
80 | |
81 | void QBluetoothAddress::clear() noexcept |
82 | { |
83 | m_address = 0; |
84 | } |
85 | |
86 | bool QBluetoothAddress::isNull() const noexcept |
87 | { |
88 | return m_address == 0; |
89 | } |
90 | |
91 | quint64 QBluetoothAddress::toUInt64() const noexcept |
92 | { |
93 | return m_address; |
94 | } |
95 | #endif // QT_BLUETOOTH_INLINE_IMPL_SINCE(6, 6) |
96 | |
97 | QT_END_NAMESPACE |
98 | |
99 | QT_DECL_METATYPE_EXTERN(QBluetoothAddress, Q_BLUETOOTH_EXPORT) |
100 | |
101 | #endif |
102 | |