[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the QtScript module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL-ONLY$
|
---|
| 10 | ** GNU Lesser General Public License Usage
|
---|
| 11 | ** This file may be used under the terms of the GNU Lesser
|
---|
| 12 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 13 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 14 | ** packaging of this file. Please review the following information to
|
---|
| 15 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 16 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 17 | **
|
---|
| 18 | ** If you have questions regarding the use of this file, please contact
|
---|
| 19 | ** Nokia at [email protected].
|
---|
| 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 |
|
---|
| 32 | QT_BEGIN_HEADER
|
---|
| 33 |
|
---|
| 34 | QT_BEGIN_NAMESPACE
|
---|
| 35 |
|
---|
| 36 | QT_MODULE(Script)
|
---|
| 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 |
|
---|
| 50 | typedef QList<QScriptValue> QScriptValueList;
|
---|
| 51 |
|
---|
| 52 | typedef double qsreal;
|
---|
| 53 |
|
---|
| 54 | class QScriptValuePrivate;
|
---|
| 55 | class QScriptEnginePrivate;
|
---|
| 56 | struct QScriptValuePrivatePointerDeleter;
|
---|
| 57 | class Q_SCRIPT_EXPORT QScriptValue
|
---|
| 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 | };
|
---|
| 83 | Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
|
---|
| 84 |
|
---|
| 85 | enum SpecialValue {
|
---|
| 86 | NullValue,
|
---|
| 87 | UndefinedValue
|
---|
| 88 | };
|
---|
| 89 |
|
---|
| 90 | public:
|
---|
| 91 | QScriptValue();
|
---|
| 92 | ~QScriptValue();
|
---|
| 93 | QScriptValue(const QScriptValue &other);
|
---|
| 94 | QScriptValue(QScriptEngine *engine, SpecialValue val);
|
---|
| 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
|
---|
| 101 | QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue(QScriptEngine *engine, const char *val);
|
---|
| 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 |
|
---|
| 165 | QScriptValue property(const QString &name,
|
---|
| 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 |
|
---|
| 175 | QScriptValue property(const QScriptString &name,
|
---|
| 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);
|
---|
| 189 | QScriptValue construct(const QScriptValueList &args = QScriptValueList());
|
---|
| 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 |
|
---|
| 206 | QScriptValue(QScriptValuePrivate*);
|
---|
| 207 |
|
---|
| 208 | private:
|
---|
| 209 | QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr;
|
---|
| 210 |
|
---|
| 211 | Q_DECLARE_PRIVATE(QScriptValue)
|
---|
| 212 |
|
---|
| 213 | friend class QScriptEnginePrivate;
|
---|
| 214 | };
|
---|
| 215 |
|
---|
| 216 | Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::ResolveFlags)
|
---|
| 217 | Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::PropertyFlags)
|
---|
| 218 |
|
---|
| 219 | QT_END_NAMESPACE
|
---|
| 220 |
|
---|
| 221 | QT_END_HEADER
|
---|
| 222 |
|
---|
| 223 | #endif
|
---|