⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qscriptvalue.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the QtScript module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "qscriptvalue.h"#ifndef QT_NO_SCRIPT#include "qscriptvalue_p.h"#include "qscriptengine_p.h"#include "qscriptvalueimpl_p.h"#include "qscriptcontext_p.h"#include "qscriptmember_p.h"#include "qscriptobject_p.h"#include <QtCore/QDateTime>#include <QtCore/QRegExp>/*!  \since 4.3  \class QScriptValue  \brief The QScriptValue class acts as a container for the Qt Script data types.  \ingroup script  \mainclass  QScriptValue supports the types defined in the \l{ECMA-262}  standard: The primitive types, which are Undefined, Null, Boolean,  Number, and String; and the Object type. Additionally, Qt Script  has built-in support for QVariant, QObject and QMetaObject.  For the object-based types (including Date and RegExp), use the  newT() functions in QScriptEngine (e.g. QScriptEngine::newObject())  to create a QScriptValue of the desired type. For the primitive types,  use one of the QScriptValue constructor overloads.  The methods named isT() (e.g. isBoolean(), isUndefined()) can be  used to test if a value is of a certain type. The methods named  toT() (e.g. toBoolean(), toString()) can be used to convert a  QScriptValue to another type. You can also use the generic  qscriptvalue_cast() function.  Object values have zero or more properties which are themselves  QScriptValues. Use setProperty() to set a property of an object, and  call property() to retrieve the value of a property.  Note that a QScriptValue for which isObject() is true only carries a  reference to an actual object; copying the QScriptValue will only  copy the object reference, not the object itself. If you want to  clone an object (i.e. copy an object's properties to another  object), you can do so with the help of a \c{for-in} statement in  script code, or QScriptValueIterator in C++.  Object values have an internal \c{prototype} property, which can be  accessed with prototype() and setPrototype(). Properties added to a  prototype are shared by all objects having that prototype; this is  referred to as prototype-based inheritance. For more information,  see the \l{QtScript} documentation.  Function objects (objects for which isFunction() returns true) can  be invoked by calling call(). Constructor functions can be used to  construct new objects by calling construct().  Use equals(), strictlyEquals() and lessThan() to compare a QScriptValue  to another.  \sa QScriptEngine, QScriptValueIterator*//*!    \enum QScriptValue::SpecialValue    This enum is used to specify a single-valued type.    \value UndefinedValue An undefined value.    \value NullValue A null value.*//*!    \enum QScriptValue::PropertyFlag    This enum describes the attributes of a property.    \value ReadOnly The property is read-only. Attempts by Qt Script code to write to the property will be ignored.    \value Undeletable Attempts by Qt Script code to \c{delete} the property will be ignored.    \value SkipInEnumeration The property is not to be enumerated by a \c{for-in} enumeration.    \value PropertyGetter The property is defined by a function which will be called to get the property value.    \value PropertySetter The property is defined by a function which will be called to set the property value.    \value QObjectMember This flag is used to indicate that an existing property is a QObject member (a property or method).    \value KeepExistingFlags This value is used to indicate to setProperty() that the property's flags should be left unchanged. If the property doesn't exist, the default flags (0) will be used.    \value UserRange Flags in this range are not used by Qt Script, and can be used for custom purposes.*//*!    \enum QScriptValue::ResolveFlag    This enum specifies how to look up a property of an object.    \value ResolveLocal Only check the object's own properties.    \value ResolvePrototype Check the object's own properties first, then search the prototype chain. This is the default.    \value ResolveScope Check the object's own properties first, then search the scope chain.    \value ResolveFull Check the object's own properties first, then search the prototype chain, and finally search the scope chain.*//*!  Constructs an invalid QScriptValue.*/QScriptValue::QScriptValue()    : d_ptr(0){}/*!  Destroys this QScriptValue.*/QScriptValue::~QScriptValue(){    if (d_ptr && !d_ptr->ref.deref()) {        if (isValid()) {            QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr);        } else {            // the engine has already been deleted            delete d_ptr;        }        d_ptr = 0;    }}/*!  Constructs a new QScriptValue that is a copy of \a other.  Note that if \a other is an object (i.e., isObject() would return  true), then only a reference to the underlying object is copied into  the new script value (i.e., the object itself is not copied).*/QScriptValue::QScriptValue(const QScriptValue &other)    : d_ptr(other.d_ptr){    if (d_ptr)        d_ptr->ref.ref();}/*!  Constructs a new QScriptValue with the special \a value and  registers it with the script \a engine.*/QScriptValue::QScriptValue(QScriptEngine *engine, QScriptValue::SpecialValue value){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    if (value == NullValue)        eng_p->newNull(&v);    else if (value == UndefinedValue)        eng_p->newUndefined(&v);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, bool value)  Constructs a new QScriptValue with the boolean \a value and  registers it with the script \a engine.*/QScriptValue::QScriptValue(QScriptEngine *engine, bool val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newBoolean(&v, val);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, int value)  Constructs a new QScriptValue with the integer \a value and  registers it with the script \a engine.*/QScriptValue::QScriptValue(QScriptEngine *engine, int val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newNumber(&v, val);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, uint value)  Constructs a new QScriptValue with the unsigned integer \a value and  registers it with the script \a engine. */QScriptValue::QScriptValue(QScriptEngine *engine, uint val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newNumber(&v, val);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, qsreal value)  Constructs a new QScriptValue with the qsreal \a value and  registers it with the script \a engine.*/QScriptValue::QScriptValue(QScriptEngine *engine, qsreal val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newNumber(&v, val);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, const QString &value)  Constructs a new QScriptValue with the string \a value and  registers it with the script \a engine.*/QScriptValue::QScriptValue(QScriptEngine *engine, const QString &val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newString(&v, val);    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}/*!  \fn QScriptValue::QScriptValue(QScriptEngine *engine, const char *value)  Constructs a new QScriptValue with the string \a value and  registers it with the script \a engine.*/#ifndef QT_NO_CAST_FROM_ASCIIQScriptValue::QScriptValue(QScriptEngine *engine, const char *val){    QScriptValueImpl v;    QScriptEnginePrivate *eng_p = QScriptEnginePrivate::get(engine);    eng_p->newString(&v, QString::fromAscii(val));    d_ptr = eng_p->registerValue(v);    d_ptr->ref.ref();}#endif/*!  Assigns the \a other value to this QScriptValue.  Note that if \a other is an object (isObject() returns true),  only a reference to the underlying object will be assigned;  the object itself will not be copied.*/QScriptValue &QScriptValue::operator=(const QScriptValue &other){    if (d_ptr == other.d_ptr)        return *this;    if (d_ptr && !d_ptr->ref.deref()) {        if (isValid()) {            QScriptEnginePrivate::get(engine())->unregisterValue(d_ptr);        } else {            // the engine has already been deleted            delete d_ptr;        }    }    d_ptr = other.d_ptr;    if (d_ptr)        d_ptr->ref.ref();    return *this;}/*!  Returns true if this QScriptValue is an object of the Error class;  otherwise returns false.  \sa QScriptContext::throwError()*/bool QScriptValue::isError() const{    return QScriptValuePrivate::valueOf(*this).isError();}/*!  Returns true if this QScriptValue is an object of the Array class;  otherwise returns false.  \sa QScriptEngine::newArray()*/bool QScriptValue::isArray() const{    return QScriptValuePrivate::valueOf(*this).isArray();}/*!  Returns true if this QScriptValue is an object of the Date class;  otherwise returns false.  \sa QScriptEngine::newDate()*/bool QScriptValue::isDate() const{    return QScriptValuePrivate::valueOf(*this).isDate();}/*!  Returns true if this QScriptValue is an object of the RegExp class;  otherwise returns false.  \sa QScriptEngine::newRegExp()*/bool QScriptValue::isRegExp() const{    return QScriptValuePrivate::valueOf(*this).isRegExp();}/*!  If this QScriptValue is an object, returns the internal prototype

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -