Home | History | Annotate | Download | only in api
      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 class QDateTime;
     30 
     31 class QScriptValue;
     32 typedef QList<QScriptValue> QScriptValueList;
     33 
     34 typedef double qsreal;
     35 
     36 class QScriptValue {
     37 public:
     38     enum ResolveFlag {
     39         ResolveLocal        = 0x00,
     40         ResolvePrototype    = 0x01,
     41         ResolveScope        = 0x02,
     42         ResolveFull         = ResolvePrototype | ResolveScope
     43     };
     44     Q_DECLARE_FLAGS(ResolveFlags, ResolveFlag)
     45 
     46     enum PropertyFlag {
     47         ReadOnly            = 0x00000001,
     48         Undeletable         = 0x00000002,
     49         SkipInEnumeration   = 0x00000004,
     50         PropertyGetter      = 0x00000008,
     51         PropertySetter      = 0x00000010,
     52         QObjectMember       = 0x00000020,
     53         KeepExistingFlags   = 0x00000800,
     54         UserRange           = 0xff000000 // Users may use these as they see fit.
     55     };
     56     Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag)
     57 
     58     enum SpecialValue {
     59         NullValue,
     60         UndefinedValue
     61     };
     62 
     63     QScriptValue();
     64     QScriptValue(bool value);
     65     QScriptValue(int value);
     66     QScriptValue(uint value);
     67     QScriptValue(qsreal value);
     68     QScriptValue(const QString& value);
     69     QScriptValue(const char* value);
     70     QScriptValue(SpecialValue value);
     71     QScriptValue(const QScriptValue& other);
     72 
     73     QScriptValue(QScriptEngine* engine, bool value);
     74     QScriptValue(QScriptEngine* engine, int value);
     75     QScriptValue(QScriptEngine* engine, uint value);
     76     QScriptValue(QScriptEngine* engine, qsreal value);
     77     QScriptValue(QScriptEngine* engine, const QString& value);
     78     QScriptValue(QScriptEngine* engine, const char* value);
     79     QScriptValue(QScriptEngine* engine, SpecialValue value);
     80 
     81     ~QScriptValue();
     82 
     83     QScriptValue& operator=(const QScriptValue& other);
     84 
     85     QScriptValue prototype() const;
     86     void setPrototype(const QScriptValue& prototype);
     87 
     88     bool equals(const QScriptValue& other) const;
     89     bool strictlyEquals(const QScriptValue& other) const;
     90     bool instanceOf(const QScriptValue& other) const;
     91 
     92     QScriptValue property(const QString& name, const ResolveFlags& mode = ResolvePrototype) const;
     93     QScriptValue property(const QScriptString& name, const ResolveFlags& mode = ResolvePrototype) const;
     94     QScriptValue property(quint32 arrayIndex, const ResolveFlags& mode = ResolvePrototype) const;
     95 
     96     void setProperty(const QString& name, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags);
     97     void setProperty(quint32 arrayIndex, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags);
     98     void setProperty(const QScriptString& name, const QScriptValue& value, const PropertyFlags& flags = KeepExistingFlags);
     99 
    100     PropertyFlags propertyFlags(const QString& name, const ResolveFlags& mode = ResolvePrototype) const;
    101     PropertyFlags propertyFlags(const QScriptString& name, const ResolveFlags& mode = ResolvePrototype) const;
    102 
    103     QScriptEngine* engine() const;
    104 
    105     bool isValid() const;
    106     bool isBool() const;
    107     bool isBoolean() const;
    108     bool isNumber() const;
    109     bool isFunction() const;
    110     bool isNull() const;
    111     bool isString() const;
    112     bool isUndefined() const;
    113     bool isObject() const;
    114     bool isError() const;
    115     bool isArray() const;
    116     bool isDate() const;
    117 
    118     QString toString() const;
    119     qsreal toNumber() const;
    120     bool toBool() const;
    121     bool toBoolean() const;
    122     qsreal toInteger() const;
    123     qint32 toInt32() const;
    124     quint32 toUInt32() const;
    125     quint16 toUInt16() const;
    126     QScriptValue toObject() const;
    127     QDateTime toDateTime() const;
    128 
    129     QScriptValue call(const QScriptValue& thisObject = QScriptValue(),
    130                       const QScriptValueList& args = QScriptValueList());
    131 private:
    132     QScriptValue(void*);
    133     QScriptValue(QScriptValuePrivate*);
    134 
    135     QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr;
    136 
    137     friend class QScriptValuePrivate;
    138 };
    139 
    140 #endif // qscriptvalue_h
    141