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
qv4variantassociationobject_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 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
5#ifndef QV4VARIANTASSOCIATIONOBJECT_P_H_
6#define QV4VARIANTASSOCIATIONOBJECT_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
19#include <private/qv4object_p.h>
20#include <private/qv4referenceobject_p.h>
21#include <private/qv4value_p.h>
22
23#include <QtCore/QVariantMap>
24#include <QtCore/QVariantHash>
25
26QT_BEGIN_NAMESPACE
27
28namespace QV4 {
29
42
43namespace Heap {
44
45#define VariantAssociationObjectMembers(class, Member)
46 Member(class, Pointer, ArrayObject *, propertyIndexMapping);
47
49{
50 DECLARE_MARKOBJECTS(VariantAssociationObject)
51
52 enum class AssociationType: quint8
53 {
54 VariantMap,
55 VariantHash
56 };
57
58 void init(
59 const QVariantMap &variantMap, QV4::Heap::Object *container, int property,
60 Heap::ReferenceObject::Flags flags);
61
62 void init(
63 const QVariantHash &variantHash, QV4::Heap::Object *container, int property,
64 Heap::ReferenceObject::Flags flags);
65
66 void destroy();
67
68 void *storagePointer() { return &m_variantAssociation; }
69
70 QVariant toVariant();
71 bool setVariant(const QVariant &variant);
72
73 template<typename Association>
74 void createElementWrappers(const Association &association)
75 {
76 Q_ASSERT(!object());
77
78 QV4::Scope scope(internalClass->engine);
79 QV4::ScopedObject self(scope, this);
80 QV4::ScopedString key(scope);
81 QV4::ScopedValue val(scope);
82 for (auto it = association.begin(), end = association.end(); it != end; ++it) {
83 key = scope.engine->newString(it.key());
84 val = scope.engine->fromVariant(*it);
85 self->put(key, val);
86 }
87 }
88
89 QV4::ReturnedValue getElement(const QString &id, bool *hasProperty);
90
91 VariantAssociationObject *detached();
92
93 // The alignment calculation needs to be out of the
94 // `alignas` due to a GCC 8.3 bug (that at the time of
95 // writing is used on the QNX 7.1 platform).
96 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94929
97 static constexpr auto alignment = std::max(alignof(QVariantMap), alignof(QVariantHash));
98 alignas(alignment)
99 std::byte m_variantAssociation[std::max(sizeof(QVariantMap), sizeof(QVariantHash))];
100
101 AssociationType m_type;
102};
103
104} // namespace Heap
105
125
126} // namespace QV4
127
128QT_END_NAMESPACE
129
130#endif // QV4VARIANTASSOCIATIONOBJECT_P_H_
Combined button and popup list for selecting options.
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
VariantAssociationObject * createDetached(QV4::ExecutionEngine *engine, const Association &association)
Definition qjsvalue.h:24
Return visitVariantAssociation(const QV4::Heap::VariantAssociationObject *association, Callable &&callable)
Return visitVariantAssociation(QV4::Heap::VariantAssociationObject *association, MapCallable &&mapCallable, HashCallable &&hashCallable)
Return visitVariantAssociation(QV4::Heap::VariantAssociationObject *association, Callable &&callable)