1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtScript module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QSCRIPTVALUE_H
41#define QSCRIPTVALUE_H
42
43#include <QtCore/qstring.h>
44
45#include <QtCore/qlist.h>
46#include <QtCore/qsharedpointer.h>
47#include <QtScript/qtscriptglobal.h>
48
49QT_BEGIN_NAMESPACE
50
51
52class QScriptClass;
53class QScriptValue;
54class QScriptEngine;
55class QScriptString;
56class QVariant;
57class QObject;
58struct QMetaObject;
59class QDateTime;
60#ifndef QT_NO_REGEXP
61class QRegExp;
62#endif
63
64typedef QList<QScriptValue> QScriptValueList;
65
66typedef double qsreal;
67
68class QScriptValuePrivate;
69class QScriptEnginePrivate;
70struct QScriptValuePrivatePointerDeleter;
71class Q_SCRIPT_EXPORT QScriptValue
72{
73public:
74 enum ResolveFlag {
75 ResolveLocal = 0x00,
76 ResolvePrototype = 0x01,
77 ResolveScope = 0x02,
78 ResolveFull = ResolvePrototype | ResolveScope
79 };
80
81 Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag)
82
83 enum PropertyFlag {
84 ReadOnly = 0x00000001,
85 Undeletable = 0x00000002,
86 SkipInEnumeration = 0x00000004,
87
88 PropertyGetter = 0x00000008,
89 PropertySetter = 0x00000010,
90
91 QObjectMember = 0x00000020,
92
93 KeepExistingFlags = 0x00000800,
94
95 UserRange = 0xff000000 // Users may use these as they see fit.
96 };
97 Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
98
99 enum SpecialValue {
100 NullValue,
101 UndefinedValue
102 };
103
104public:
105 QScriptValue();
106 ~QScriptValue();
107 QScriptValue(const QScriptValue &other);
108 QScriptValue(QScriptEngine *engine, SpecialValue val);
109 QScriptValue(QScriptEngine *engine, bool val);
110 QScriptValue(QScriptEngine *engine, int val);
111 QScriptValue(QScriptEngine *engine, uint val);
112 QScriptValue(QScriptEngine *engine, qsreal val);
113 QScriptValue(QScriptEngine *engine, const QString &val);
114#ifndef QT_NO_CAST_FROM_ASCII
115 QT_ASCII_CAST_WARN QScriptValue(QScriptEngine *engine, const char *val);
116#endif
117
118 QScriptValue(SpecialValue value);
119 QScriptValue(bool value);
120 QScriptValue(int value);
121 QScriptValue(uint value);
122 QScriptValue(qsreal value);
123 QScriptValue(const QString &value);
124 QScriptValue(const QLatin1String &value);
125#ifndef QT_NO_CAST_FROM_ASCII
126 QT_ASCII_CAST_WARN QScriptValue(const char *value);
127#endif
128
129 QScriptValue &operator=(const QScriptValue &other);
130
131 QScriptEngine *engine() const;
132
133 bool isValid() const;
134 bool isBool() const;
135 bool isBoolean() const;
136 bool isNumber() const;
137 bool isFunction() const;
138 bool isNull() const;
139 bool isString() const;
140 bool isUndefined() const;
141 bool isVariant() const;
142 bool isQObject() const;
143 bool isQMetaObject() const;
144 bool isObject() const;
145 bool isDate() const;
146 bool isRegExp() const;
147 bool isArray() const;
148 bool isError() const;
149
150 QString toString() const;
151 qsreal toNumber() const;
152 bool toBool() const;
153 bool toBoolean() const;
154 qsreal toInteger() const;
155 qint32 toInt32() const;
156 quint32 toUInt32() const;
157 quint16 toUInt16() const;
158 QVariant toVariant() const;
159 QObject *toQObject() const;
160 const QMetaObject *toQMetaObject() const;
161 QScriptValue toObject() const;
162 QDateTime toDateTime() const;
163#ifndef QT_NO_REGEXP
164 QRegExp toRegExp() const;
165#endif
166
167 bool instanceOf(const QScriptValue &other) const;
168
169 bool lessThan(const QScriptValue &other) const;
170 bool equals(const QScriptValue &other) const;
171 bool strictlyEquals(const QScriptValue &other) const;
172
173 QScriptValue prototype() const;
174 void setPrototype(const QScriptValue &prototype);
175
176 QScriptValue scope() const;
177 void setScope(const QScriptValue &scope);
178
179 QScriptValue property(const QString &name,
180 const ResolveFlags &mode = ResolvePrototype) const;
181 void setProperty(const QString &name, const QScriptValue &value,
182 const PropertyFlags &flags = KeepExistingFlags);
183
184 QScriptValue property(quint32 arrayIndex,
185 const ResolveFlags &mode = ResolvePrototype) const;
186 void setProperty(quint32 arrayIndex, const QScriptValue &value,
187 const PropertyFlags &flags = KeepExistingFlags);
188
189 QScriptValue property(const QScriptString &name,
190 const ResolveFlags &mode = ResolvePrototype) const;
191 void setProperty(const QScriptString &name, const QScriptValue &value,
192 const PropertyFlags &flags = KeepExistingFlags);
193
194 QScriptValue::PropertyFlags propertyFlags(
195 const QString &name, const ResolveFlags &mode = ResolvePrototype) const;
196 QScriptValue::PropertyFlags propertyFlags(
197 const QScriptString &name, const ResolveFlags &mode = ResolvePrototype) const;
198
199 QScriptValue call(const QScriptValue &thisObject = QScriptValue(),
200 const QScriptValueList &args = QScriptValueList());
201 QScriptValue call(const QScriptValue &thisObject,
202 const QScriptValue &arguments);
203 QScriptValue construct(const QScriptValueList &args = QScriptValueList());
204 QScriptValue construct(const QScriptValue &arguments);
205
206 QScriptValue data() const;
207 void setData(const QScriptValue &data);
208
209 QScriptClass *scriptClass() const;
210 void setScriptClass(QScriptClass *scriptClass);
211
212 qint64 objectId() const;
213
214private:
215 // force compile error, prevent QScriptValue(bool) to be called
216 QScriptValue(void *);
217 // force compile error, prevent QScriptValue(QScriptEngine*, bool) to be called
218 QScriptValue(QScriptEngine *, void *);
219
220 QScriptValue(QScriptValuePrivate*);
221
222private:
223 QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr;
224
225 Q_DECLARE_PRIVATE(QScriptValue)
226
227 friend class QScriptEnginePrivate;
228};
229
230Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::ResolveFlags)
231Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::PropertyFlags)
232
233QT_END_NAMESPACE
234
235#endif
236

source code of qtscript/src/script/api/qscriptvalue.h