• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <QtCore/qlist.h>
24 #include <QtCore/qshareddata.h>
25 
26 class QScriptEngine;
27 class QScriptValuePrivate;
28 
29 class QScriptValue;
30 typedef QList<QScriptValue> QScriptValueList;
31 
32 typedef double qsreal;
33 
34 class QScriptValue {
35 public:
36     enum SpecialValue {
37         NullValue,
38         UndefinedValue
39     };
40 
41     QScriptValue();
42     QScriptValue(bool value);
43     QScriptValue(int value);
44     QScriptValue(uint value);
45     QScriptValue(qsreal value);
46     QScriptValue(const QString& value);
47     QScriptValue(const char* value);
48     QScriptValue(SpecialValue value);
49     QScriptValue(const QScriptValue& other);
50 
51     QScriptValue(QScriptEngine* engine, bool value);
52     QScriptValue(QScriptEngine* engine, int value);
53     QScriptValue(QScriptEngine* engine, uint value);
54     QScriptValue(QScriptEngine* engine, qsreal value);
55     QScriptValue(QScriptEngine* engine, const QString& value);
56     QScriptValue(QScriptEngine* engine, const char* value);
57     QScriptValue(QScriptEngine* engine, SpecialValue value);
58 
59     ~QScriptValue();
60 
61     QScriptValue& operator=(const QScriptValue& other);
62     bool equals(const QScriptValue& other) const;
63     bool strictlyEquals(const QScriptValue& other) const;
64 
65     QScriptEngine* engine() const;
66 
67     bool isValid() const;
68     bool isBool() const;
69     bool isBoolean() const;
70     bool isNumber() const;
71     bool isFunction() const;
72     bool isNull() const;
73     bool isString() const;
74     bool isUndefined() const;
75     bool isObject() const;
76     bool isError() const;
77 
78     QString toString() const;
79     qsreal toNumber() const;
80     bool toBool() const;
81     bool toBoolean() const;
82     qsreal toInteger() const;
83     qint32 toInt32() const;
84     quint32 toUInt32() const;
85     quint16 toUInt16() const;
86 
87     QScriptValue call(const QScriptValue& thisObject = QScriptValue(),
88                       const QScriptValueList& args = QScriptValueList());
89 
90 private:
91     QScriptValue(void*);
92     QScriptValue(QScriptValuePrivate*);
93 
94     QExplicitlySharedDataPointer<QScriptValuePrivate> d_ptr;
95 
96     friend class QScriptValuePrivate;
97 };
98 
99 #endif // qscriptvalue_h
100