1/* 2 Copyright (C) 2010 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#include "config.h" 21 22#include "qscriptprogram.h" 23 24#include "qscriptprogram_p.h" 25 26/*! 27 \internal 28 29 \class QScriptProgram 30 31 \brief The QScriptProgram class encapsulates a Qt Script program. 32 33 \ingroup script 34 35 QScriptProgram retains the compiled representation of the script if 36 possible. Thus, QScriptProgram can be used to evaluate the same 37 script multiple times more efficiently. 38 39 \code 40 QScriptEngine engine; 41 QScriptProgram program("1 + 2"); 42 QScriptValue result = engine.evaluate(program); 43 \endcode 44*/ 45 46/*! 47 Constructs a null QScriptProgram. 48*/ 49QScriptProgram::QScriptProgram() 50 : d_ptr(new QScriptProgramPrivate) 51{} 52 53/*! 54 Constructs a new QScriptProgram with the given \a sourceCode, \a 55 fileName and \a firstLineNumber. 56*/ 57QScriptProgram::QScriptProgram(const QString& sourceCode, 58 const QString fileName, 59 int firstLineNumber) 60 : d_ptr(new QScriptProgramPrivate(sourceCode, fileName, firstLineNumber)) 61{} 62 63/*! 64 Destroys this QScriptProgram. 65*/ 66QScriptProgram::~QScriptProgram() 67{} 68 69/*! 70 Constructs a new QScriptProgram that is a copy of \a other. 71*/ 72QScriptProgram::QScriptProgram(const QScriptProgram& other) 73{ 74 d_ptr = other.d_ptr; 75} 76 77/*! 78 Assigns the \a other value to this QScriptProgram. 79*/ 80QScriptProgram& QScriptProgram::operator=(const QScriptProgram& other) 81{ 82 d_ptr = other.d_ptr; 83 return *this; 84} 85 86/*! 87 Returns true if this QScriptProgram is null; otherwise 88 returns false. 89*/ 90bool QScriptProgram::isNull() const 91{ 92 return d_ptr->isNull(); 93} 94 95/*! 96 Returns the source code of this program. 97*/ 98QString QScriptProgram::sourceCode() const 99{ 100 return d_ptr->sourceCode(); 101} 102 103/*! 104 Returns the filename associated with this program. 105*/ 106QString QScriptProgram::fileName() const 107{ 108 return d_ptr->fileName(); 109} 110 111/*! 112 Returns the line number associated with this program. 113*/ 114int QScriptProgram::firstLineNumber() const 115{ 116 return d_ptr->firstLineNumber(); 117} 118 119/*! 120 Returns true if this QScriptProgram is equal to \a other; 121 otherwise returns false. 122*/ 123bool QScriptProgram::operator==(const QScriptProgram& other) const 124{ 125 return d_ptr == other.d_ptr || *d_ptr == *other.d_ptr; 126} 127 128/*! 129 Returns true if this QScriptProgram is not equal to \a other; 130 otherwise returns false. 131*/ 132bool QScriptProgram::operator!=(const QScriptProgram& other) const 133{ 134 return d_ptr != other.d_ptr && *d_ptr != *other.d_ptr; 135} 136 137