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