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
qv4identifierhash_p.h
Go to the documentation of this file.
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// Qt-Security score:significant
4#ifndef QV4IDENTIFIERHASH_P_H
5#define QV4IDENTIFIERHASH_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
18#include <private/qv4global_p.h>
19#include <private/qv4propertykey_p.h>
20
21#include <QtCore/qstring.h>
22
23QT_BEGIN_NAMESPACE
24
25namespace QV4 {
26
30{
31 IdentifierHash() = default;
32 IdentifierHash(ExecutionEngine *engine);
33 IdentifierHash(const IdentifierHash &other);
34 IdentifierHash(IdentifierHash &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
37
38 void swap(IdentifierHash &other) noexcept { qt_ptr_swap(d, other.d); }
40
41 bool isValid() const { return d; }
42 int size() const;
43
44 void add(const QString &str, int value) { addEntry(toIdentifier(str), value); }
45 void add(Heap::String *str, int value) { addEntry(toIdentifier(str), value); }
46
47 int value(const QString &str) const { return lookup(toIdentifier(str)); }
48 int value(Heap::String *str) const { return lookup(toIdentifier(str)); }
49
50 template<typename String>
51 String key(int value) const { return toString<String>(reverseLookup(value)); }
52
53private:
54 void addEntry(PropertyKey i, int value);
55
56 int lookup(PropertyKey identifier) const;
57 PropertyKey reverseLookup(int value) const;
58
59 PropertyKey toIdentifier(const QString &str) const;
60 PropertyKey toIdentifier(Heap::String *str) const;
61
62 template<typename String>
63 String toString(PropertyKey key) const;
64
65 IdentifierHashData *d = nullptr;
66};
67
70
71} // namespace QV4
72
73QT_END_NAMESPACE
74
75#endif // QV4_IDENTIFIERHASH_P_H
Combined button and popup list for selecting options.
Definition qjsvalue.h:24
IdentifierHash(IdentifierHash &&other) noexcept
IdentifierHash(const IdentifierHash &other)
IdentifierHash()=default
String key(int value) const
void add(const QString &str, int value)
int value(const QString &str) const
void swap(IdentifierHash &other) noexcept
IdentifierHash & operator=(const IdentifierHash &other)