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
qv4sequenceobject_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
5#ifndef QV4SEQUENCEWRAPPER_P_H
6#define QV4SEQUENCEWRAPPER_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 <QtCore/qglobal.h>
20#include <QtCore/qvariant.h>
21#include <QtQml/qqml.h>
22
23#include <private/qv4referenceobject_p.h>
24#include <private/qv4value_p.h>
25#include <private/qv4object_p.h>
26
27QT_BEGIN_NAMESPACE
28
29namespace QV4 {
30
31struct Sequence;
33
34struct Q_QML_EXPORT SequencePrototype : public QV4::Object
35{
37 void init();
38
39 static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc);
40 static ReturnedValue method_shift(const FunctionObject *b, const Value *thisObject, const Value *, int);
42 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
44 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
46 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
48 const FunctionObject *b, const Value *thisObject, const Value *, int);
50 const FunctionObject *f, const Value *thisObject, const Value *argv, int argc);
51
52
59
61 static QVariant toVariant(const Sequence *object);
63
70
76};
77
78namespace Heap {
79
81{
82 void init(QMetaType listType, QMetaSequence metaSequence, const void *container);
83 void init(QMetaType listType, QMetaSequence metaSequence, const void *container,
84 Object *object, int propertyIndex, Heap::ReferenceObject::Flags flags);
85
87 void destroy();
88
89 void *storagePointer();
90 const void *storagePointer() const { return m_container; }
91
92 bool isStoredInline() const
93 {
94 if (isReference())
95 return true;
96
97 const QMetaType valueType = valueMetaType();
98 switch (valueType.id()) {
99 case QMetaType::QVariant:
100 case QMetaType::QVariantHash:
101 case QMetaType::QVariantMap:
102 case QMetaType::QVariantList:
103 case QMetaType::QObjectStar:
104 return false;
105 default:
106 break;
107 }
108
109 return !valueType.flags().testFlag(QMetaType::PointerToQObject);
110 }
111
112 bool isReadOnly() const { return m_object && !canWriteBack(); }
113
114 bool setVariant(const QVariant &variant);
115 QVariant toVariant() const;
116
117 QMetaType listType() const { return QMetaType(m_listType); }
118 QMetaType valueMetaType() const { return QMetaType(m_metaSequence->valueMetaType); }
119 QMetaSequence metaSequence() const { return QMetaSequence(m_metaSequence); }
120
121private:
122 friend struct QV4::Sequence;
123 friend struct QV4::SequencePrototype;
125
126 void initTypes(QMetaType listType, QMetaSequence metaSequence);
127 void createElementWrappers(const void *container);
128 void createInlineStorage(const void *container);
129
130 bool loadReference();
131 bool storeReference();
132
133 union {
134 void *m_container; // if stored inline
135 uint m_size; // if stored out of line
136 };
137 const QtPrivate::QMetaTypeInterface *m_listType;
138 const QtMetaContainerPrivate::QMetaSequenceInterface *m_metaSequence;
139};
140
141}
142
159
160}
161
162#define QT_DECLARE_SEQUENTIAL_CONTAINER(LOCAL, FOREIGN, VALUE)
163 struct LOCAL
164 {
165 Q_GADGET
166 QML_ANONYMOUS
167 QML_SEQUENTIAL_CONTAINER(VALUE)
168 QML_FOREIGN(FOREIGN)
169 QML_ADDED_IN_VERSION(2, 0)
170 }
171
172// We use the original QT_COORD_TYPE name because that will match up with relevant other
173// types in plugins.qmltypes (if you use either float or double, that is; otherwise you're
174// on your own).
175#ifdef QT_COORD_TYPE
176QT_DECLARE_SEQUENTIAL_CONTAINER(QStdRealVectorForeign, std::vector<qreal>, QT_COORD_TYPE);
177QT_DECLARE_SEQUENTIAL_CONTAINER(QRealListForeign, QList<qreal>, QT_COORD_TYPE);
178#else
179QT_DECLARE_SEQUENTIAL_CONTAINER(QRealStdVectorForeign, std::vector<qreal>, double);
180QT_DECLARE_SEQUENTIAL_CONTAINER(QRealListForeign, QList<qreal>, double);
181#endif
182
183QT_DECLARE_SEQUENTIAL_CONTAINER(QDoubleStdVectorForeign, std::vector<double>, double);
184QT_DECLARE_SEQUENTIAL_CONTAINER(QFloatStdVectorForeign, std::vector<float>, float);
185QT_DECLARE_SEQUENTIAL_CONTAINER(QIntStdVectorForeign, std::vector<int>, int);
186QT_DECLARE_SEQUENTIAL_CONTAINER(QBoolStdVectorForeign, std::vector<bool>, bool);
187QT_DECLARE_SEQUENTIAL_CONTAINER(QStringStdVectorForeign, std::vector<QString>, QString);
188QT_DECLARE_SEQUENTIAL_CONTAINER(QUrlStdVectorForeign, std::vector<QUrl>, QUrl);
189
190#undef QT_DECLARE_SEQUENTIAL_CONTAINER
191
192QT_END_NAMESPACE
193
194#endif // QV4SEQUENCEWRAPPER_P_H
Definition qjsvalue.h:23
static Heap::Sequence * resolveHeapSequence(const Sequence *sequence, QMetaType typeHint)
static void removeLastInline(Heap::Sequence *p, qsizetype num)
static void * createVariantData(QMetaType type, QVariant *variant)
static void generateWarning(QV4::ExecutionEngine *v4, const QString &description)
static void appendInline(Heap::Sequence *p, const QVariant &item)
void convertAndDo(const QVariant &item, const QMetaType v, Action action)
bool convertToIterable(QMetaType metaType, void *data, QV4::Object *sequence)
static const void * retrieveVariantData(QMetaType type, const QVariant *variant)
static void appendDefaultConstructedInline(Heap::Sequence *p, qsizetype num)
static void replaceInline(Heap::Sequence *p, qsizetype index, const QVariant &item)
static qsizetype sizeInline(const Heap::Sequence *p)
static ReturnedValue doGetIndexed(Heap::Sequence *p, qsizetype index)
#define QT_DECLARE_SEQUENTIAL_CONTAINER(LOCAL, FOREIGN, VALUE)
void init(QMetaType listType, QMetaSequence metaSequence, const void *container)
QVariant toVariant() const
void init(QMetaType listType, QMetaSequence metaSequence, const void *container, Object *object, int propertyIndex, Heap::ReferenceObject::Flags flags)
QMetaType valueMetaType() const
const void * storagePointer() const
QMetaType listType() const
bool setVariant(const QVariant &variant)
QMetaSequence metaSequence() const
PropertyKey next(const Object *o, Property *pd=nullptr, PropertyAttributes *attrs=nullptr) override
~SequenceOwnPropertyKeyIterator() override=default