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 for (auto it = association.begin(), end = association.end(); it != end; ++it) {
81 QV4::ScopedString key(scope, scope.engine->newString(it.key()));
82 QV4::ScopedValue val(scope, scope.engine->fromVariant(*it));
83 self->put(key, val);
84 }
85 }
86
87 QV4::ReturnedValue getElement(const QString &id, bool *hasProperty);
88
89 VariantAssociationObject *detached();
90
91 // The alignment calculation needs to be out of the
92 // `alignas` due to a GCC 8.3 bug (that at the time of
93 // writing is used on the QNX 7.1 platform).
94 // See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94929
95 static constexpr auto alignment = std::max(alignof(QVariantMap), alignof(QVariantHash));
96 alignas(alignment)
97 std::byte m_variantAssociation[std::max(sizeof(QVariantMap), sizeof(QVariantHash))];
98
99 AssociationType m_type;
100};
101
102} // namespace Heap
103
123
124} // namespace QV4
125
126QT_END_NAMESPACE
127
128#endif // QV4VARIANTASSOCIATIONOBJECT_P_H_
DECLARE_HEAP_OBJECT(QmlContext, ExecutionContext)
VariantAssociationObject * createDetached(QV4::ExecutionEngine *engine, const Association &association)
Definition qjsvalue.h:23
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)