Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4persistent_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#ifndef QV4PERSISTENT_H
4#define QV4PERSISTENT_H
5
6//
7// W A R N I N G
8// -------------
9//
10// This file is not part of the Qt API. It exists purely as an
11// implementation detail. This header file may change from version to
12// version without notice, or even be removed.
13//
14// We mean it.
15//
16
17#include "qv4value_p.h"
18#include "qv4managed_p.h"
19
21
22namespace QV4 {
23
24struct Q_QML_EXPORT PersistentValueStorage
25{
28
29 Value *allocate();
30 static void free(Value *v)
31 {
32 if (v)
33 freeUnchecked(v);
34 }
35
36 void mark(MarkStack *markStack);
37
38 struct Iterator {
39 Iterator(void *p, int idx);
40 Iterator(const Iterator &o);
41 Iterator & operator=(const Iterator &o);
42 ~Iterator();
43 void *p;
44 int index;
45 Iterator &operator++();
46 bool operator !=(const Iterator &other) {
47 return p != other.p || index != other.index;
48 }
50 };
51 Iterator begin() { return Iterator(firstPage, 0); }
52 Iterator end() { return Iterator(nullptr, 0); }
53
54 void clearFreePageHint();
55
56 static ExecutionEngine *getEngine(const Value *v);
57
59 void *firstPage;
60 void *freePageHint = nullptr;
61private:
62 static void freeUnchecked(Value *v);
63 static void freePage(void *page);
64};
65
66class Q_QML_EXPORT PersistentValue
67{
68public:
69 constexpr PersistentValue() noexcept = default;
71 PersistentValue &operator=(const PersistentValue &other);
72
73 PersistentValue(PersistentValue &&other) noexcept : val(std::exchange(other.val, nullptr)) {}
74 void swap(PersistentValue &other) noexcept { qt_ptr_swap(val, other.val); }
75 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(PersistentValue)
76 ~PersistentValue() { PersistentValueStorage::free(val); }
77
78 PersistentValue &operator=(const WeakValue &other);
79 PersistentValue &operator=(Object *object);
80
84
85 void set(ExecutionEngine *engine, const Value &value);
88
90 return (val ? val->asReturnedValue() : Encode::undefined());
91 }
92 Value *valueRef() const {
93 return val;
94 }
95 Managed *asManaged() const {
96 if (!val)
97 return nullptr;
98 return val->managed();
99 }
100 template<typename T>
101 T *as() const {
102 if (!val)
103 return nullptr;
104 return val->as<T>();
105 }
106
108 if (!val)
109 return nullptr;
110 return PersistentValueStorage::getEngine(val);
111 }
112
113 bool isUndefined() const { return !val || val->isUndefined(); }
114 bool isNullOrUndefined() const { return !val || val->isNullOrUndefined(); }
115 void clear() {
116 PersistentValueStorage::free(val);
117 val = nullptr;
118 }
119 bool isEmpty() { return !val; }
120
121private:
122 Value *val = nullptr;
123};
124
125class Q_QML_EXPORT WeakValue
126{
127public:
129 WeakValue(const WeakValue &other);
131 WeakValue &operator=(const WeakValue &other);
132 ~WeakValue();
133
134 void set(ExecutionEngine *engine, const Value &value);
135
137
139
141 return (val ? val->asReturnedValue() : Encode::undefined());
142 }
143 Value *valueRef() const {
144 return val;
145 }
147 if (!val)
148 return nullptr;
149 return val->managed();
150 }
151 template <typename T>
152 T *as() const {
153 if (!val)
154 return nullptr;
155 return val->as<T>();
156 }
157
159 if (!val)
160 return nullptr;
161 return PersistentValueStorage::getEngine(val);
162 }
163
164 bool isUndefined() const { return !val || val->isUndefined(); }
165 bool isNullOrUndefined() const { return !val || val->isNullOrUndefined(); }
166 void clear() { free(); }
167
168 void markOnce(MarkStack *markStack);
169
170private:
171 Value *val = nullptr;
172
173private:
174 Q_NEVER_INLINE void allocVal(ExecutionEngine *engine);
175
176 void free();
177};
178
179} // namespace QV4
180
182
183#endif
constexpr PersistentValue() noexcept=default
bool isNullOrUndefined() const
ExecutionEngine * engine() const
void swap(PersistentValue &other) noexcept
Value * valueRef() const
Managed * asManaged() const
ReturnedValue value() const
ExecutionEngine * engine() const
Managed * asManaged() const
bool isUndefined() const
ReturnedValue value() const
Value * valueRef() const
bool isNullOrUndefined() const
Combined button and popup list for selecting options.
quint64 ReturnedValue
#define Q_NEVER_INLINE
constexpr bool operator!=(const timespec &t1, const timespec &t2)
constexpr timespec operator*(const timespec &t1, int mul)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLuint index
[2]
GLhandleARB obj
[2]
GLuint GLfloat * val
GLfloat GLfloat p
[1]
constexpr void qt_ptr_swap(T *&lhs, T *&rhs) noexcept
Definition qswap.h:29
QFuture< QSet< QChar > > set
[10]
QByteArray page
[45]
QSharedPointer< T > other(t)
[5]
QJSEngine engine
[0]
static void free(Value *v)
QML_NEARLY_ALWAYS_INLINE ManagedPtr managed() const
Definition qv4value_p.h:75