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

source code of qtconnectivity/src/bluetooth/qbluetoothaddress.h