Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljsannotation_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLJSANNOTATION_P_H
6#define QQMLJSANNOTATION_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <QtCore/qglobal.h>
19#include <QtCore/qhash.h>
20
21#include <variant>
22
23QT_BEGIN_NAMESPACE
24
25struct QQQmlJSDeprecation
26{
27 QString reason;
28};
29
31{
32 using Value = std::variant<QString, double>;
33
36
37 bool isDeprecation() const;
38 QQQmlJSDeprecation deprecation() const;
39
40 friend bool operator==(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) {
41 return a.name == b.name &&
42 a.bindings == b.bindings;
43 }
44
45 friend bool operator!=(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) {
46 return !(a == b);
47 }
48
49 friend size_t qHash(const QQmlJSAnnotation &annotation, size_t seed = 0)
50 {
51 QtPrivate::QHashCombine combine(seed);
52 seed = combine(seed, annotation.name);
53
54 for (auto it = annotation.bindings.constBegin(); it != annotation.bindings.constEnd(); ++it) {
55 size_t h = combine(seed, it.key());
56 // use + to keep the result independent of the ordering of the keys
57
58 const auto &var = it.value();
59
60 if (var.index() == std::variant_npos)
61 continue;
62
63 if (std::holds_alternative<double>(var))
64 seed += combine(h, std::get<double>(var));
65 else if (std::holds_alternative<QString>(var))
66 seed += combine(h, std::get<QString>(var));
67 else
68 Q_UNREACHABLE();
69 }
70
71 return seed;
72 }
73};
74
75QT_END_NAMESPACE
76
77#endif // QQMLJSANNOTATION_P_H
QQQmlJSDeprecation deprecation() const
friend bool operator!=(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b)
QHash< QString, Value > bindings
friend size_t qHash(const QQmlJSAnnotation &annotation, size_t seed=0)
friend bool operator==(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b)
bool isDeprecation() const