1 | // Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
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 QT3DCORE_QNODEID_H |
5 | #define QT3DCORE_QNODEID_H |
6 | |
7 | #include <Qt3DCore/qt3dcore_global.h> |
8 | #include <QtCore/QDebug> |
9 | #include <QtCore/QHashFunctions> |
10 | |
11 | QT_BEGIN_NAMESPACE |
12 | |
13 | namespace Qt3DCore { |
14 | |
15 | class QNodeId |
16 | { |
17 | constexpr explicit QNodeId(quint64 i) noexcept |
18 | : m_id(i) |
19 | {} |
20 | public: |
21 | constexpr QNodeId() noexcept |
22 | : m_id(0) |
23 | {} |
24 | |
25 | Q_3DCORESHARED_EXPORT static QNodeId createId() noexcept; |
26 | |
27 | constexpr bool isNull() const noexcept |
28 | { |
29 | return m_id == 0; |
30 | } |
31 | |
32 | constexpr bool operator ==(QNodeId other) const noexcept |
33 | { |
34 | return other.m_id == m_id; |
35 | } |
36 | |
37 | constexpr bool operator !=(QNodeId other) const noexcept |
38 | { |
39 | return !operator ==(other); |
40 | } |
41 | |
42 | constexpr bool operator <(QNodeId other) const noexcept |
43 | { |
44 | return m_id < other.m_id; |
45 | } |
46 | |
47 | constexpr bool operator >(QNodeId other) const noexcept |
48 | { |
49 | return m_id > other.m_id; |
50 | } |
51 | |
52 | constexpr quint64 id() const noexcept |
53 | { |
54 | return m_id; |
55 | } |
56 | |
57 | constexpr operator bool() const noexcept |
58 | { |
59 | return m_id != 0; |
60 | } |
61 | |
62 | private: |
63 | quint64 m_id; |
64 | }; |
65 | QT3D_DECLARE_TYPEINFO(Qt3DCore, QNodeId, Q_PRIMITIVE_TYPE) |
66 | |
67 | using QNodeIdVector = QList<QNodeId>; |
68 | |
69 | #ifndef QT_NO_DEBUG_STREAM |
70 | Q_3DCORESHARED_EXPORT QDebug operator<<(QDebug d, QNodeId id); |
71 | #endif |
72 | |
73 | //! [nodeid-qhash] |
74 | inline constexpr size_t qHash(QNodeId id, size_t seed = 0) noexcept |
75 | { |
76 | using QT_PREPEND_NAMESPACE(qHash); |
77 | return qHash(key: id.id(), seed); |
78 | } |
79 | |
80 | } // Qt3DCore |
81 | |
82 | QT_END_NAMESPACE |
83 | |
84 | Q_DECLARE_METATYPE(Qt3DCore::QNodeId) // LCOV_EXCL_LINE |
85 | |
86 | |
87 | #endif // QT3DCORE_QNODEID_H |
88 | |