| 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 | |
| 4 | #ifndef QQMLJSANNOTATION_P_H |
| 5 | #define QQMLJSANNOTATION_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | |
| 17 | #include <QtCore/qglobal.h> |
| 18 | #include <QtCore/qhash.h> |
| 19 | |
| 20 | #include <variant> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | struct QQQmlJSDeprecation |
| 25 | { |
| 26 | QString reason; |
| 27 | }; |
| 28 | |
| 29 | struct QQmlJSAnnotation |
| 30 | { |
| 31 | using Value = std::variant<QString, double>; |
| 32 | |
| 33 | QString name; |
| 34 | QHash<QString, Value> bindings; |
| 35 | |
| 36 | bool isDeprecation() const; |
| 37 | QQQmlJSDeprecation deprecation() const; |
| 38 | |
| 39 | friend bool operator==(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) { |
| 40 | return a.name == b.name && |
| 41 | a.bindings == b.bindings; |
| 42 | } |
| 43 | |
| 44 | friend bool operator!=(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) { |
| 45 | return !(a == b); |
| 46 | } |
| 47 | |
| 48 | friend size_t qHash(const QQmlJSAnnotation &annotation, size_t seed = 0) |
| 49 | { |
| 50 | QtPrivate::QHashCombine combine; |
| 51 | seed = combine(seed, annotation.name); |
| 52 | |
| 53 | for (auto it = annotation.bindings.constBegin(); it != annotation.bindings.constEnd(); ++it) { |
| 54 | size_t h = combine(seed, it.key()); |
| 55 | // use + to keep the result independent of the ordering of the keys |
| 56 | |
| 57 | const auto &var = it.value(); |
| 58 | |
| 59 | if (var.index() == std::variant_npos) |
| 60 | continue; |
| 61 | |
| 62 | if (std::holds_alternative<double>(v: var)) |
| 63 | seed += combine(h, std::get<double>(v: var)); |
| 64 | else if (std::holds_alternative<QString>(v: var)) |
| 65 | seed += combine(h, std::get<QString>(v: var)); |
| 66 | else |
| 67 | Q_UNREACHABLE(); |
| 68 | } |
| 69 | |
| 70 | return seed; |
| 71 | } |
| 72 | }; |
| 73 | |
| 74 | QT_END_NAMESPACE |
| 75 | |
| 76 | #endif // QQMLJSANNOTATION_P_H |
| 77 | |