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