Qt 4.8
qscriptvalue.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #ifndef QSCRIPTVALUE_H
25 #define QSCRIPTVALUE_H
26 
27 #include <QtCore/qstring.h>
28 
29 #include <QtCore/qlist.h>
30 #include <QtCore/qsharedpointer.h>
31 
33 
35 
37 
38 class QScriptClass;
39 class QScriptValue;
40 class QScriptEngine;
41 class QScriptString;
42 class QVariant;
43 class QObject;
44 struct QMetaObject;
45 class QDateTime;
46 #ifndef QT_NO_REGEXP
47 class QRegExp;
48 #endif
49 
51 
52 typedef double qsreal;
53 
56 struct QScriptValuePrivatePointerDeleter;
58 {
59 public:
60  enum ResolveFlag {
61  ResolveLocal = 0x00,
62  ResolvePrototype = 0x01,
63  ResolveScope = 0x02,
64  ResolveFull = ResolvePrototype | ResolveScope
65  };
66 
67  Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag)
68 
69  enum PropertyFlag {
70  ReadOnly = 0x00000001,
71  Undeletable = 0x00000002,
72  SkipInEnumeration = 0x00000004,
73 
74  PropertyGetter = 0x00000008,
75  PropertySetter = 0x00000010,
76 
77  QObjectMember = 0x00000020,
78 
79  KeepExistingFlags = 0x00000800,
80 
81  UserRange = 0xff000000 // Users may use these as they see fit.
82  };
84 
85  enum SpecialValue {
87  UndefinedValue
88  };
89 
90 public:
91  QScriptValue();
92  ~QScriptValue();
93  QScriptValue(const QScriptValue &other);
95  QScriptValue(QScriptEngine *engine, bool val);
96  QScriptValue(QScriptEngine *engine, int val);
97  QScriptValue(QScriptEngine *engine, uint val);
98  QScriptValue(QScriptEngine *engine, qsreal val);
99  QScriptValue(QScriptEngine *engine, const QString &val);
100 #ifndef QT_NO_CAST_FROM_ASCII
102 #endif
103 
104  QScriptValue(SpecialValue value);
105  QScriptValue(bool value);
106  QScriptValue(int value);
107  QScriptValue(uint value);
108  QScriptValue(qsreal value);
109  QScriptValue(const QString &value);
110  QScriptValue(const QLatin1String &value);
111 #ifndef QT_NO_CAST_FROM_ASCII
112  QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue(const char *value);
113 #endif
114 
115  QScriptValue &operator=(const QScriptValue &other);
116 
117  QScriptEngine *engine() const;
118 
119  bool isValid() const;
120  bool isBool() const;
121  bool isBoolean() const;
122  bool isNumber() const;
123  bool isFunction() const;
124  bool isNull() const;
125  bool isString() const;
126  bool isUndefined() const;
127  bool isVariant() const;
128  bool isQObject() const;
129  bool isQMetaObject() const;
130  bool isObject() const;
131  bool isDate() const;
132  bool isRegExp() const;
133  bool isArray() const;
134  bool isError() const;
135 
136  QString toString() const;
137  qsreal toNumber() const;
138  bool toBool() const;
139  bool toBoolean() const;
140  qsreal toInteger() const;
141  qint32 toInt32() const;
142  quint32 toUInt32() const;
143  quint16 toUInt16() const;
144  QVariant toVariant() const;
145  QObject *toQObject() const;
146  const QMetaObject *toQMetaObject() const;
147  QScriptValue toObject() const;
148  QDateTime toDateTime() const;
149 #ifndef QT_NO_REGEXP
150  QRegExp toRegExp() const;
151 #endif
152 
153  bool instanceOf(const QScriptValue &other) const;
154 
155  bool lessThan(const QScriptValue &other) const;
156  bool equals(const QScriptValue &other) const;
157  bool strictlyEquals(const QScriptValue &other) const;
158 
159  QScriptValue prototype() const;
160  void setPrototype(const QScriptValue &prototype);
161 
162  QScriptValue scope() const;
163  void setScope(const QScriptValue &scope);
164 
166  const ResolveFlags &mode = ResolvePrototype) const;
167  void setProperty(const QString &name, const QScriptValue &value,
168  const PropertyFlags &flags = KeepExistingFlags);
169 
170  QScriptValue property(quint32 arrayIndex,
171  const ResolveFlags &mode = ResolvePrototype) const;
172  void setProperty(quint32 arrayIndex, const QScriptValue &value,
173  const PropertyFlags &flags = KeepExistingFlags);
174 
176  const ResolveFlags &mode = ResolvePrototype) const;
177  void setProperty(const QScriptString &name, const QScriptValue &value,
178  const PropertyFlags &flags = KeepExistingFlags);
179 
180  QScriptValue::PropertyFlags propertyFlags(
181  const QString &name, const ResolveFlags &mode = ResolvePrototype) const;
182  QScriptValue::PropertyFlags propertyFlags(
183  const QScriptString &name, const ResolveFlags &mode = ResolvePrototype) const;
184 
185  QScriptValue call(const QScriptValue &thisObject = QScriptValue(),
186  const QScriptValueList &args = QScriptValueList());
187  QScriptValue call(const QScriptValue &thisObject,
188  const QScriptValue &arguments);
190  QScriptValue construct(const QScriptValue &arguments);
191 
192  QScriptValue data() const;
193  void setData(const QScriptValue &data);
194 
195  QScriptClass *scriptClass() const;
196  void setScriptClass(QScriptClass *scriptClass);
197 
198  qint64 objectId() const;
199 
200 private:
201  // force compile error, prevent QScriptValue(bool) to be called
202  QScriptValue(void *);
203  // force compile error, prevent QScriptValue(QScriptEngine*, bool) to be called
204  QScriptValue(QScriptEngine *, void *);
205 
207 
208 private:
210 
212 
214 };
215 
218 
220 
222 
223 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QExplicitlySharedDataPointer< QScriptValuePrivate > d_ptr
Definition: qscriptvalue.h:209
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
QList< QScriptValue > QScriptValueList
Definition: qscriptvalue.h:47
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int qint32
Definition: qglobal.h:937
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QScriptClass class provides an interface for defining custom behavior of (a class of) Qt Script o...
Definition: qscriptclass.h:43
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
static bool isNumber(char s)
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
SpecialValue
This enum is used to specify a single-valued type.
Definition: qscriptvalue.h:85
The QScriptString class acts as a handle to "interned" strings in a QScriptEngine.
Definition: qscriptstring.h:38
static bool toBool(Register *reg, int type, bool *ok=0)
static QString toString(Register *reg, int type, bool *ok=0)
The QScriptEngine class provides an environment for evaluating Qt Script code.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
static bool lessThan(const QChar *a, int l, const char *c)
Definition: qurl.cpp:3253
static bool setData(const QByteArray &data, STGMEDIUM *pmedium)
Definition: qmime_win.cpp:141
const char * name
unsigned short quint16
Definition: qglobal.h:936
bool isFunction(JSC::JSValue value)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define QT_ASCII_CAST_WARN_CONSTRUCTOR
Definition: qglobal.h:1145
__int64 qint64
Definition: qglobal.h:942
#define Q_SCRIPT_EXPORT
Definition: qglobal.h:1460
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
ResolveFlag
This enum specifies how to look up a property of an object.
Definition: qscriptvalue.h:60
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
static void construct(QVariant::Private *x, const void *copy)
Definition: qvariant.cpp:75
PropertyFlags
Definition: qmetaobject_p.h:61
unsigned int quint32
Definition: qglobal.h:938
PropertyFlag
This enum describes the attributes of a property.
Definition: qscriptvalue.h:69
const char * property
Definition: qwizard.cpp:138
double qsreal
Definition: qscriptvalue.h:52
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300