- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qscriptvalue.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtScript module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
    00010 ** GNU Lesser General Public License Usage
    00011 ** This file may be used under the terms of the GNU Lesser
    00012 ** General Public License version 2.1 as published by the Free Software
    00013 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00014 ** packaging of this file.  Please review the following information to
    00015 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00016 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00017 **
    00018 ** If you have questions regarding the use of this file, please contact
    00019 ** Nokia at qt-info@nokia.com.
    00020 ** $QT_END_LICENSE$
    00021 **
    00022 ****************************************************************************/
    00023
    00024 #ifndef QSCRIPTVALUE_H
    00025 #define QSCRIPTVALUE_H
    00026
    00027 #include <QtCore/qstring.h>
    00028
    00029 #include <QtCore/qlist.h>
    00030 #include <QtCore/qsharedpointer.h>
    00031
    00032 QT_BEGIN_HEADER
    00033
    00034 QT_BEGIN_NAMESPACE
    00035
    00036 QT_MODULE(Script)
    00037
    00038 class QScriptClass;
    00039 class QScriptValue;
    00040 class QScriptEngine;
    00041 class QScriptString;
    00042 class QVariant;
    00043 class QObject;
    00044 struct QMetaObject;
    00045 class QDateTime;
    00046 #ifndef QT_NO_REGEXP
    00047 class QRegExp;
    00048 #endif
    00049
    00050 typedef QList<QScriptValue> QScriptValueList;
    00051
    00052 typedef double qsreal;
    00053
    00054 class QScriptValuePrivate;
    00055 class QScriptEnginePrivate;
    00056 struct QScriptValuePrivatePointerDeleter;
    00057 class Q_SCRIPT_EXPORT QScriptValue
    00058 {
    00059 public:
    00060     enum ResolveFlag {
    00061         ResolveLocal        = 0x00,
    00062         ResolvePrototype    = 0x01,
    00063         ResolveScope        = 0x02,
    00064         ResolveFull         = ResolvePrototype | ResolveScope
    00065     };
    00066
    00067     Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag)
    00068
    00069     enum PropertyFlag {
    00070         ReadOnly            = 0x00000001,
    00071         Undeletable         = 0x00000002,
    00072         SkipInEnumeration   = 0x00000004,
    00073
    00074         PropertyGetter      = 0x00000008,
    00075         PropertySetter      = 0x00000010,
    00076
    00077         QObjectMember       = 0x00000020,
    00078
    00079         KeepExistingFlags   = 0x00000800,
    00080
    00081         UserRange           = 0xff000000            // Users may use these as they see fit.
    00082     };
    00083     Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
    00084
    00085     enum SpecialValue {
    00086         NullValue,
    00087         UndefinedValue
    00088     };
    00089
    00090 public:
    00091     QScriptValue();
    00092     ~QScriptValue();
    00093     QScriptValue(const QScriptValue &other);
    00094     QScriptValue(QScriptEngine *engine, SpecialValue val);
    00095     QScriptValue(QScriptEngine *engine, bool val);
    00096     QScriptValue(QScriptEngine *engine, int val);
    00097     QScriptValue(QScriptEngine *engine, uint val);
    00098     QScriptValue(QScriptEngine *engine, qsreal val);
    00099     QScriptValue(QScriptEngine *engine, const QString &val);
    00100 #ifndef QT_NO_CAST_FROM_ASCII
    00101     QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue(QScriptEngine *engine, const char *val);
    00102 #endif
    00103
    00104     QScriptValue(SpecialValue value);
    00105     QScriptValue(bool value);
    00106     QScriptValue(int value);
    00107     QScriptValue(uint value);
    00108     QScriptValue(qsreal value);
    00109     QScriptValue(const QString &value);
    00110     QScriptValue(const QLatin1String &value);
    00111 #ifndef QT_NO_CAST_FROM_ASCII
    00112     QT_ASCII_CAST_WARN_CONSTRUCTOR QScriptValue(const char *value);
    00113 #endif
    00114
    00115     QScriptValue &operator=(const QScriptValue &other);
    00116
    00117     QScriptEngine *engine() const;
    00118
    00119     bool isValid() const;
    00120     bool isBool() const;
    00121     bool isBoolean() const;
    00122     bool isNumber() const;
    00123     bool isFunction() const;
    00124     bool isNull() const;
    00125     bool isString() const;
    00126     bool isUndefined() const;
    00127     bool isVariant() const;
    00128     bool isQObject() const;
    00129     bool isQMetaObject() const;
    00130     bool isObject() const;
    00131     bool isDate() const;
    00132     bool isRegExp() const;
    00133     bool isArray() const;
    00134     bool isError() const;
    00135
    00136     QString toString() const;
    00137     qsreal toNumber() const;
    00138     bool toBool() const;
    00139     bool toBoolean() const;
    00140     qsreal toInteger() const;
    00141     qint32 toInt32() const;
    00142     quint32 toUInt32() const;
    00143     quint16 toUInt16() const;
    00144     QVariant toVariant() const;
    00145     QObject *toQObject() const;
    00146     const QMetaObject *toQMetaObject() const;
    00147     QScriptValue toObject() const;
    00148     QDateTime toDateTime() const;
    00149 #ifndef QT_NO_REGEXP
    00150     QRegExp toRegExp() const;
    00151 #endif
    00152
    00153     bool instanceOf(const QScriptValue &other) const;
    00154
    00155     bool lessThan(const QScriptValue &other) const;
    00156     bool equals(const QScriptValue &other) const;
    00157     bool strictlyEquals(const QScriptValue &other) const;
    00158
    00159     QScriptValue prototype() const;
    00160     void setPrototype(const QScriptValue &prototype);
    00161
    00162     QScriptValue scope() const;
    00163     void setScope(const QScriptValue &scope);
    00164
    00165     QScriptValue property(const QString &name,
    00166                           const ResolveFlags &mode = ResolvePrototype) const;
    00167     void setProperty(const QString &name, const QScriptValue &value,
    00168                      const PropertyFlags &flags = KeepExistingFlags);
    00169
    00170     QScriptValue property(quint32 arrayIndex,
    00171                           const ResolveFlags &mode = ResolvePrototype) const;
    00172     void setProperty(quint32 arrayIndex, const QScriptValue &value,
    00173                      const PropertyFlags &flags = KeepExistingFlags);
    00174
    00175     QScriptValue property(const QScriptString &name,
    00176                           const ResolveFlags &mode = ResolvePrototype) const;
    00177     void setProperty(const QScriptString &name, const QScriptValue &value,
    00178                      const PropertyFlags &flags = KeepExistingFlags);
    00179
    00180     QScriptValue::PropertyFlags propertyFlags(
    00181         const QString &name, const ResolveFlags &mode = ResolvePrototype) const;
    00182     QScriptValue::PropertyFlags propertyFlags(
    00183         const QScriptString &name, const ResolveFlags &mode = ResolvePrototype) const;
    00184
    00185     QScriptValue call(const QScriptValue &thisObject = QScriptValue(),
    00186                       const QScriptValueList &args = QScriptValueList());
    00187     QScriptValue call(const QScriptValue &thisObject,
    00188                       const QScriptValue &arguments);
    00189     QScriptValue construct(const QScriptValueList &args = QScriptValueList());
    00190     QScriptValue construct(const QScriptValue &arguments);
    00191
    00192     QScriptValue data() const;
    00193     void setData(const QScriptValue &data);
    00194
    00195     QScriptClass *scriptClass() const;
    00196     void setScriptClass(QScriptClass *scriptClass);
    00197
    00198     qint64 objectId() const;
    00199
    00200 private:
    00201     // force compile error, prevent QScriptValue(bool) to be called
    00202     QScriptValue(void *);
    00203     // force compile error, prevent QScriptValue(QScriptEngine*, bool) to be called
    00204     QScriptValue(QScriptEngine *, void *);
    00205
    00206     QScriptValue(QScriptValuePrivate*);
    00207
    00208 private:
    00209     QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr;
    00210
    00211     Q_DECLARE_PRIVATE(QScriptValue)
    00212
    00213     friend class QScriptEnginePrivate;
    00214 };
    00215
    00216 Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::ResolveFlags)
    00217 Q_DECLARE_OPERATORS_FOR_FLAGS(QScriptValue::PropertyFlags)
    00218
    00219 QT_END_NAMESPACE
    00220
    00221 QT_END_HEADER
    00222
    00223 #endif