From e1ae391b679c188f8f9c86dd4af0c26300b14bd6 Mon Sep 17 00:00:00 2001 From: Kent Hansen Date: Fri, 23 Oct 2009 10:21:37 +0200 Subject: add getter functions and comparison operators to QScriptProgram --- src/script/api/qscriptprogram.cpp | 53 +++++++++++++++++++++++++++++++++++++++ src/script/api/qscriptprogram.h | 7 ++++++ 2 files changed, 60 insertions(+) diff --git a/src/script/api/qscriptprogram.cpp b/src/script/api/qscriptprogram.cpp index 96760ba..9f88363 100644 --- a/src/script/api/qscriptprogram.cpp +++ b/src/script/api/qscriptprogram.cpp @@ -134,4 +134,57 @@ bool QScriptProgram::isValid() const return (d && d->engine); } +/*! + Returns the source code of this program. +*/ +QString QScriptProgram::sourceCode() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->executable->source().toString(); +} + +/*! + Returns the filename associated with this program. +*/ +QString QScriptProgram::fileName() const +{ + Q_D(const QScriptProgram); + if (!d) + return QString(); + return d->executable->sourceURL(); +} + +/*! + Returns the line number associated with this program. +*/ +int QScriptProgram::lineNumber() const +{ + Q_D(const QScriptProgram); + if (!d) + return -1; + return d->executable->lineNo(); +} + +/*! + Returns true if this QScriptProgram is equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator==(const QScriptProgram &other) const +{ + return (sourceCode() == other.sourceCode()) + && (fileName() == other.fileName()) + && (lineNumber() == other.lineNumber()); +} + +/*! + Returns true if this QScriptProgram is not equal to \a other; + otherwise returns false. +*/ +bool QScriptProgram::operator!=(const QScriptProgram &other) const +{ + return !operator==(other); +} + QT_END_NAMESPACE diff --git a/src/script/api/qscriptprogram.h b/src/script/api/qscriptprogram.h index 6c2ba47..b6782b8 100644 --- a/src/script/api/qscriptprogram.h +++ b/src/script/api/qscriptprogram.h @@ -62,6 +62,13 @@ public: bool isValid() const; + QString sourceCode() const; + QString fileName() const; + int lineNumber() const; + + bool operator==(const QScriptProgram &other) const; + bool operator!=(const QScriptProgram &other) const; + private: QExplicitlySharedDataPointer d_ptr; Q_DECLARE_PRIVATE(QScriptProgram) -- cgit v0.12