|
1 /* |
|
2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) |
|
3 |
|
4 This library is free software; you can redistribute it and/or |
|
5 modify it under the terms of the GNU Library General Public |
|
6 License as published by the Free Software Foundation; either |
|
7 version 2 of the License, or (at your option) any later version. |
|
8 |
|
9 This library is distributed in the hope that it will be useful, |
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 Library General Public License for more details. |
|
13 |
|
14 You should have received a copy of the GNU Library General Public License |
|
15 along with this library; see the file COPYING.LIB. If not, write to |
|
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
17 Boston, MA 02110-1301, USA. |
|
18 */ |
|
19 |
|
20 #ifndef qscriptvalue_h |
|
21 #define qscriptvalue_h |
|
22 |
|
23 #include "qscriptstring.h" |
|
24 #include <QtCore/qlist.h> |
|
25 #include <QtCore/qshareddata.h> |
|
26 |
|
27 class QScriptEngine; |
|
28 class QScriptValuePrivate; |
|
29 |
|
30 class QScriptValue; |
|
31 typedef QList<QScriptValue> QScriptValueList; |
|
32 |
|
33 typedef double qsreal; |
|
34 |
|
35 class QScriptValue { |
|
36 public: |
|
37 enum ResolveFlag { |
|
38 ResolveLocal = 0x00, |
|
39 ResolvePrototype = 0x01, |
|
40 ResolveScope = 0x02, |
|
41 ResolveFull = ResolvePrototype | ResolveScope |
|
42 }; |
|
43 Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag) |
|
44 |
|
45 enum PropertyFlag { |
|
46 ReadOnly = 0x00000001, |
|
47 Undeletable = 0x00000002, |
|
48 SkipInEnumeration = 0x00000004, |
|
49 PropertyGetter = 0x00000008, |
|
50 PropertySetter = 0x00000010, |
|
51 QObjectMember = 0x00000020, |
|
52 KeepExistingFlags = 0x00000800, |
|
53 UserRange = 0xff000000 // Users may use these as they see fit. |
|
54 }; |
|
55 Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) |
|
56 |
|
57 enum SpecialValue { |
|
58 NullValue, |
|
59 UndefinedValue |
|
60 }; |
|
61 |
|
62 QScriptValue(); |
|
63 QScriptValue(bool value); |
|
64 QScriptValue(int value); |
|
65 QScriptValue(uint value); |
|
66 QScriptValue(qsreal value); |
|
67 QScriptValue(const QString& value); |
|
68 QScriptValue(const char* value); |
|
69 QScriptValue(SpecialValue value); |
|
70 QScriptValue(const QScriptValue& other); |
|
71 |
|
72 QScriptValue(QScriptEngine* engine, bool value); |
|
73 QScriptValue(QScriptEngine* engine, int value); |
|
74 QScriptValue(QScriptEngine* engine, uint value); |
|
75 QScriptValue(QScriptEngine* engine, qsreal value); |
|
76 QScriptValue(QScriptEngine* engine, const QString& value); |
|
77 QScriptValue(QScriptEngine* engine, const char* value); |
|
78 QScriptValue(QScriptEngine* engine, SpecialValue value); |
|
79 |
|
80 ~QScriptValue(); |
|
81 |
|
82 QScriptValue& operator=(const QScriptValue& other); |
|
83 |
|
84 QScriptValue prototype() const; |
|
85 void setPrototype(const QScriptValue& prototype); |
|
86 |
|
87 bool equals(const QScriptValue& other) const; |
|
88 bool strictlyEquals(const QScriptValue& other) const; |
|
89 bool instanceOf(const QScriptValue& other) const; |
|
90 |
|
91 QScriptValue property(const QString& name, const ResolveFlags& mode = ResolvePrototype) const; |
|
92 QScriptValue property(const QScriptString& name, const ResolveFlags& mode = ResolvePrototype) const; |
|
93 QScriptValue property(quint32 arrayIndex, const ResolveFlags& mode = ResolvePrototype) const; |
|
94 |
|
95 void setProperty(const QString& name, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags); |
|
96 void setProperty(quint32 arrayIndex, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags); |
|
97 void setProperty(const QScriptString& name, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags); |
|
98 |
|
99 PropertyFlags propertyFlags(const QString& name, const ResolveFlags& mode = ResolvePrototype) const; |
|
100 PropertyFlags propertyFlags(const QScriptString& name, const ResolveFlags& mode = ResolvePrototype) const; |
|
101 |
|
102 QScriptEngine* engine() const; |
|
103 |
|
104 bool isValid() const; |
|
105 bool isBool() const; |
|
106 bool isBoolean() const; |
|
107 bool isNumber() const; |
|
108 bool isFunction() const; |
|
109 bool isNull() const; |
|
110 bool isString() const; |
|
111 bool isUndefined() const; |
|
112 bool isObject() const; |
|
113 bool isError() const; |
|
114 bool isArray() const; |
|
115 |
|
116 QString toString() const; |
|
117 qsreal toNumber() const; |
|
118 bool toBool() const; |
|
119 bool toBoolean() const; |
|
120 qsreal toInteger() const; |
|
121 qint32 toInt32() const; |
|
122 quint32 toUInt32() const; |
|
123 quint16 toUInt16() const; |
|
124 QScriptValue toObject() const; |
|
125 |
|
126 QScriptValue call(const QScriptValue& thisObject = QScriptValue(), |
|
127 const QScriptValueList& args = QScriptValueList()); |
|
128 private: |
|
129 QScriptValue(void*); |
|
130 QScriptValue(QScriptValuePrivate*); |
|
131 |
|
132 QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr; |
|
133 |
|
134 friend class QScriptValuePrivate; |
|
135 }; |
|
136 |
|
137 #endif // qscriptvalue_h |