diff options
author | Kent Hansen <khansen@trolltech.com> | 2009-10-23 08:21:37 (GMT) |
---|---|---|
committer | Kent Hansen <khansen@trolltech.com> | 2009-10-23 08:21:37 (GMT) |
commit | e1ae391b679c188f8f9c86dd4af0c26300b14bd6 (patch) | |
tree | ee814fedda0f2daae0b7a05784ad6c3ace79b236 /src/script | |
parent | 980291d7d79022c31f900f67e0422da1a8abb0a0 (diff) | |
download | Qt-e1ae391b679c188f8f9c86dd4af0c26300b14bd6.zip Qt-e1ae391b679c188f8f9c86dd4af0c26300b14bd6.tar.gz Qt-e1ae391b679c188f8f9c86dd4af0c26300b14bd6.tar.bz2 |
add getter functions and comparison operators to QScriptProgram
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/api/qscriptprogram.cpp | 53 | ||||
-rw-r--r-- | src/script/api/qscriptprogram.h | 7 |
2 files changed, 60 insertions, 0 deletions
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<QScriptProgramPrivate> d_ptr; Q_DECLARE_PRIVATE(QScriptProgram) |