source: branches/4.5.1/src/scripttools/debugging/qscriptscriptdata.cpp@ 559

Last change on this file since 559 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtSCriptTools module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qscriptscriptdata_p.h"
43
44#include <QtCore/qdatastream.h>
45#include <QtCore/qstring.h>
46#include <QtCore/qstringlist.h>
47
48QT_BEGIN_NAMESPACE
49
50/*!
51 \since 4.5
52 \class QScriptScriptData
53 \internal
54
55 \brief The QScriptScriptData class holds data associated with a script.
56*/
57
58class QScriptScriptDataPrivate
59{
60public:
61 QScriptScriptDataPrivate();
62 ~QScriptScriptDataPrivate();
63
64 QString contents;
65 QString fileName;
66 int baseLineNumber;
67 QDateTime timeStamp;
68
69 QBasicAtomicInt ref;
70};
71
72QScriptScriptDataPrivate::QScriptScriptDataPrivate()
73{
74 ref = 0;
75}
76
77QScriptScriptDataPrivate::~QScriptScriptDataPrivate()
78{
79}
80
81QScriptScriptData::QScriptScriptData()
82 : d_ptr(0)
83{
84}
85
86QScriptScriptData::QScriptScriptData(const QString &contents, const QString &fileName,
87 int baseLineNumber, const QDateTime &timeStamp)
88 : d_ptr(new QScriptScriptDataPrivate)
89{
90 d_ptr->contents = contents;
91 d_ptr->fileName = fileName;
92 d_ptr->baseLineNumber = baseLineNumber;
93 if (timeStamp.isValid())
94 d_ptr->timeStamp = timeStamp;
95 else
96 d_ptr->timeStamp = QDateTime::currentDateTime();
97 d_ptr->ref.ref();
98}
99
100QScriptScriptData::QScriptScriptData(const QScriptScriptData &other)
101 : d_ptr(other.d_ptr)
102{
103 if (d_ptr)
104 d_ptr->ref.ref();
105}
106
107QScriptScriptData::~QScriptScriptData()
108{
109 if (d_ptr && !d_ptr->ref.deref()) {
110 delete d_ptr;
111 d_ptr = 0;
112 }
113}
114
115QScriptScriptData &QScriptScriptData::operator=(const QScriptScriptData &other)
116{
117 if (d_ptr == other.d_ptr)
118 return *this;
119 if (d_ptr && !d_ptr->ref.deref())
120 delete d_ptr;
121 d_ptr = other.d_ptr;
122 if (d_ptr)
123 d_ptr->ref.ref();
124 return *this;
125}
126
127QString QScriptScriptData::contents() const
128{
129 Q_D(const QScriptScriptData);
130 if (!d)
131 return QString();
132 return d->contents;
133}
134
135QStringList QScriptScriptData::lines(int startLineNumber, int count) const
136{
137 Q_D(const QScriptScriptData);
138 if (!d)
139 return QStringList();
140 QStringList allLines = d->contents.split(QLatin1Char('\n'));
141 return allLines.mid(qMax(0, startLineNumber - d->baseLineNumber), count);
142}
143
144QString QScriptScriptData::fileName() const
145{
146 Q_D(const QScriptScriptData);
147 if (!d)
148 return QString();
149 return d->fileName;
150}
151
152int QScriptScriptData::baseLineNumber() const
153{
154 Q_D(const QScriptScriptData);
155 if (!d)
156 return -1;
157 return d->baseLineNumber;
158}
159
160QDateTime QScriptScriptData::timeStamp() const
161{
162 Q_D(const QScriptScriptData);
163 if (!d)
164 return QDateTime();
165 return d->timeStamp;
166}
167
168bool QScriptScriptData::isValid() const
169{
170 Q_D(const QScriptScriptData);
171 return (d != 0);
172}
173
174bool QScriptScriptData::operator==(const QScriptScriptData &other) const
175{
176 Q_D(const QScriptScriptData);
177 const QScriptScriptDataPrivate *od = other.d_func();
178 if (d == od)
179 return true;
180 if (!d || !od)
181 return false;
182 return ((d->contents == od->contents)
183 && (d->fileName == od->fileName)
184 && (d->baseLineNumber == od->baseLineNumber));
185}
186
187bool QScriptScriptData::operator!=(const QScriptScriptData &other) const
188{
189 return !(*this == other);
190}
191
192QDataStream &operator<<(QDataStream &out, const QScriptScriptData &data)
193{
194 const QScriptScriptDataPrivate *d = data.d_ptr;
195 if (d) {
196 out << d->contents;
197 out << d->fileName;
198 out << qint32(d->baseLineNumber);
199 } else {
200 out << QString();
201 out << QString();
202 out << qint32(0);
203 }
204 return out;
205}
206
207QDataStream &operator>>(QDataStream &in, QScriptScriptData &data)
208{
209 if (!data.d_ptr) {
210 data.d_ptr = new QScriptScriptDataPrivate();
211 data.d_ptr->ref.ref();
212 }
213 QScriptScriptDataPrivate *d = data.d_ptr;
214 in >> d->contents;
215 in >> d->fileName;
216 qint32 ln;
217 in >> ln;
218 d->baseLineNumber = ln;
219 return in;
220}
221
222QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.