| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qbuffer.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qbuffer.h" | - | ||||||||||||||||||
| 35 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||
| 36 | #include "private/qiodevice_p.h" | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | /** QBufferPrivate **/ | - | ||||||||||||||||||
| 41 | class QBufferPrivate : public QIODevicePrivate | - | ||||||||||||||||||
| 42 | { | - | ||||||||||||||||||
| 43 | Q_DECLARE_PUBLIC(QBuffer) | - | ||||||||||||||||||
| 44 | - | |||||||||||||||||||
| 45 | public: | - | ||||||||||||||||||
| 46 | QBufferPrivate() | - | ||||||||||||||||||
| 47 | : buf(0) | - | ||||||||||||||||||
| 48 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 49 | , writtenSinceLastEmit(0), signalConnectionCount(0), signalsEmitted(false) | - | ||||||||||||||||||
| 50 | #endif | - | ||||||||||||||||||
| 51 | { } executed 10588 times by 81 tests: end of blockExecuted by:
| 10588 | ||||||||||||||||||
| 52 | ~QBufferPrivate() { } | - | ||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QByteArray *buf; | - | ||||||||||||||||||
| 55 | QByteArray defaultBuf; | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | virtual qint64 peek(char *data, qint64 maxSize) Q_DECL_OVERRIDE; | - | ||||||||||||||||||
| 58 | virtual QByteArray peek(qint64 maxSize) Q_DECL_OVERRIDE; | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 61 | // private slots | - | ||||||||||||||||||
| 62 | void _q_emitSignals(); | - | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | qint64 writtenSinceLastEmit; | - | ||||||||||||||||||
| 65 | int signalConnectionCount; | - | ||||||||||||||||||
| 66 | bool signalsEmitted; | - | ||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||
| 68 | }; | - | ||||||||||||||||||
| 69 | - | |||||||||||||||||||
| 70 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 71 | void QBufferPrivate::_q_emitSignals() | - | ||||||||||||||||||
| 72 | { | - | ||||||||||||||||||
| 73 | Q_Q(QBuffer); | - | ||||||||||||||||||
| 74 | emit q->bytesWritten(writtenSinceLastEmit); | - | ||||||||||||||||||
| 75 | writtenSinceLastEmit = 0; | - | ||||||||||||||||||
| 76 | emit q->readyRead(); | - | ||||||||||||||||||
| 77 | signalsEmitted = false; | - | ||||||||||||||||||
| 78 | } executed 30 times by 1 test: end of blockExecuted by:
| 30 | ||||||||||||||||||
| 79 | #endif | - | ||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | qint64 QBufferPrivate::peek(char *data, qint64 maxSize) | - | ||||||||||||||||||
| 82 | { | - | ||||||||||||||||||
| 83 | qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos); | - | ||||||||||||||||||
| 84 | memcpy(data, buf->constData() + pos, readBytes); | - | ||||||||||||||||||
| 85 | return readBytes; executed 1423 times by 12 tests: return readBytes;Executed by:
| 1423 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | QByteArray QBufferPrivate::peek(qint64 maxSize) | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | qint64 readBytes = qMin(maxSize, static_cast<qint64>(buf->size()) - pos); | - | ||||||||||||||||||
| 91 | if (pos == 0 && maxSize >= buf->size())
| 42-115 | ||||||||||||||||||
| 92 | return *buf; executed 42 times by 3 tests: return *buf;Executed by:
| 42 | ||||||||||||||||||
| 93 | return QByteArray(buf->constData() + pos, readBytes); executed 173 times by 12 tests: return QByteArray(buf->constData() + pos, readBytes);Executed by:
| 173 | ||||||||||||||||||
| 94 | } | - | ||||||||||||||||||
| 95 | - | |||||||||||||||||||
| 96 | /*! | - | ||||||||||||||||||
| 97 | \class QBuffer | - | ||||||||||||||||||
| 98 | \inmodule QtCore | - | ||||||||||||||||||
| 99 | \reentrant | - | ||||||||||||||||||
| 100 | \brief The QBuffer class provides a QIODevice interface for a QByteArray. | - | ||||||||||||||||||
| 101 | - | |||||||||||||||||||
| 102 | \ingroup io | - | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | QBuffer allows you to access a QByteArray using the QIODevice | - | ||||||||||||||||||
| 105 | interface. The QByteArray is treated just as a standard random-accessed | - | ||||||||||||||||||
| 106 | file. Example: | - | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | \snippet buffer/buffer.cpp 0 | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | By default, an internal QByteArray buffer is created for you when | - | ||||||||||||||||||
| 111 | you create a QBuffer. You can access this buffer directly by | - | ||||||||||||||||||
| 112 | calling buffer(). You can also use QBuffer with an existing | - | ||||||||||||||||||
| 113 | QByteArray by calling setBuffer(), or by passing your array to | - | ||||||||||||||||||
| 114 | QBuffer's constructor. | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | Call open() to open the buffer. Then call write() or | - | ||||||||||||||||||
| 117 | putChar() to write to the buffer, and read(), readLine(), | - | ||||||||||||||||||
| 118 | readAll(), or getChar() to read from it. size() returns the | - | ||||||||||||||||||
| 119 | current size of the buffer, and you can seek to arbitrary | - | ||||||||||||||||||
| 120 | positions in the buffer by calling seek(). When you are done with | - | ||||||||||||||||||
| 121 | accessing the buffer, call close(). | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | The following code snippet shows how to write data to a | - | ||||||||||||||||||
| 124 | QByteArray using QDataStream and QBuffer: | - | ||||||||||||||||||
| 125 | - | |||||||||||||||||||
| 126 | \snippet buffer/buffer.cpp 1 | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | Effectively, we convert the application's QPalette into a byte | - | ||||||||||||||||||
| 129 | array. Here's how to read the data from the QByteArray: | - | ||||||||||||||||||
| 130 | - | |||||||||||||||||||
| 131 | \snippet buffer/buffer.cpp 2 | - | ||||||||||||||||||
| 132 | - | |||||||||||||||||||
| 133 | QTextStream and QDataStream also provide convenience constructors | - | ||||||||||||||||||
| 134 | that take a QByteArray and that create a QBuffer behind the | - | ||||||||||||||||||
| 135 | scenes. | - | ||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | QBuffer emits readyRead() when new data has arrived in the | - | ||||||||||||||||||
| 138 | buffer. By connecting to this signal, you can use QBuffer to | - | ||||||||||||||||||
| 139 | store temporary data before processing it. QBuffer also emits | - | ||||||||||||||||||
| 140 | bytesWritten() every time new data has been written to the buffer. | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | \sa QFile, QDataStream, QTextStream, QByteArray | - | ||||||||||||||||||
| 143 | */ | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | #ifdef QT_NO_QOBJECT | - | ||||||||||||||||||
| 146 | QBuffer::QBuffer() | - | ||||||||||||||||||
| 147 | : QIODevice(*new QBufferPrivate) | - | ||||||||||||||||||
| 148 | { | - | ||||||||||||||||||
| 149 | Q_D(QBuffer); | - | ||||||||||||||||||
| 150 | d->buf = &d->defaultBuf; | - | ||||||||||||||||||
| 151 | } | - | ||||||||||||||||||
| 152 | QBuffer::QBuffer(QByteArray *buf) | - | ||||||||||||||||||
| 153 | : QIODevice(*new QBufferPrivate) | - | ||||||||||||||||||
| 154 | { | - | ||||||||||||||||||
| 155 | Q_D(QBuffer); | - | ||||||||||||||||||
| 156 | d->buf = buf ? buf : &d->defaultBuf; | - | ||||||||||||||||||
| 157 | d->defaultBuf.clear(); | - | ||||||||||||||||||
| 158 | } | - | ||||||||||||||||||
| 159 | #else | - | ||||||||||||||||||
| 160 | /*! | - | ||||||||||||||||||
| 161 | Constructs an empty buffer with the given \a parent. You can call | - | ||||||||||||||||||
| 162 | setData() to fill the buffer with data, or you can open it in | - | ||||||||||||||||||
| 163 | write mode and use write(). | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | \sa open() | - | ||||||||||||||||||
| 166 | */ | - | ||||||||||||||||||
| 167 | QBuffer::QBuffer(QObject *parent) | - | ||||||||||||||||||
| 168 | : QIODevice(*new QBufferPrivate, parent) | - | ||||||||||||||||||
| 169 | { | - | ||||||||||||||||||
| 170 | Q_D(QBuffer); | - | ||||||||||||||||||
| 171 | d->buf = &d->defaultBuf; | - | ||||||||||||||||||
| 172 | } executed 1297 times by 41 tests: end of blockExecuted by:
| 1297 | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | /*! | - | ||||||||||||||||||
| 175 | Constructs a QBuffer that uses the QByteArray pointed to by \a | - | ||||||||||||||||||
| 176 | byteArray as its internal buffer, and with the given \a parent. | - | ||||||||||||||||||
| 177 | The caller is responsible for ensuring that \a byteArray remains | - | ||||||||||||||||||
| 178 | valid until the QBuffer is destroyed, or until setBuffer() is | - | ||||||||||||||||||
| 179 | called to change the buffer. QBuffer doesn't take ownership of | - | ||||||||||||||||||
| 180 | the QByteArray. | - | ||||||||||||||||||
| 181 | - | |||||||||||||||||||
| 182 | If you open the buffer in write-only mode or read-write mode and | - | ||||||||||||||||||
| 183 | write something into the QBuffer, \a byteArray will be modified. | - | ||||||||||||||||||
| 184 | - | |||||||||||||||||||
| 185 | Example: | - | ||||||||||||||||||
| 186 | - | |||||||||||||||||||
| 187 | \snippet buffer/buffer.cpp 3 | - | ||||||||||||||||||
| 188 | - | |||||||||||||||||||
| 189 | \sa open(), setBuffer(), setData() | - | ||||||||||||||||||
| 190 | */ | - | ||||||||||||||||||
| 191 | QBuffer::QBuffer(QByteArray *byteArray, QObject *parent) | - | ||||||||||||||||||
| 192 | : QIODevice(*new QBufferPrivate, parent) | - | ||||||||||||||||||
| 193 | { | - | ||||||||||||||||||
| 194 | Q_D(QBuffer); | - | ||||||||||||||||||
| 195 | d->buf = byteArray ? byteArray : &d->defaultBuf;
| 0-9291 | ||||||||||||||||||
| 196 | d->defaultBuf.clear(); | - | ||||||||||||||||||
| 197 | } executed 9291 times by 64 tests: end of blockExecuted by:
| 9291 | ||||||||||||||||||
| 198 | #endif | - | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | /*! | - | ||||||||||||||||||
| 201 | Destroys the buffer. | - | ||||||||||||||||||
| 202 | */ | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | QBuffer::~QBuffer() | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | } | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | /*! | - | ||||||||||||||||||
| 209 | Makes QBuffer uses the QByteArray pointed to by \a | - | ||||||||||||||||||
| 210 | byteArray as its internal buffer. The caller is responsible for | - | ||||||||||||||||||
| 211 | ensuring that \a byteArray remains valid until the QBuffer is | - | ||||||||||||||||||
| 212 | destroyed, or until setBuffer() is called to change the buffer. | - | ||||||||||||||||||
| 213 | QBuffer doesn't take ownership of the QByteArray. | - | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | Does nothing if isOpen() is true. | - | ||||||||||||||||||
| 216 | - | |||||||||||||||||||
| 217 | If you open the buffer in write-only mode or read-write mode and | - | ||||||||||||||||||
| 218 | write something into the QBuffer, \a byteArray will be modified. | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | Example: | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | \snippet buffer/buffer.cpp 4 | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | If \a byteArray is 0, the buffer creates its own internal | - | ||||||||||||||||||
| 225 | QByteArray to work on. This byte array is initially empty. | - | ||||||||||||||||||
| 226 | - | |||||||||||||||||||
| 227 | \sa buffer(), setData(), open() | - | ||||||||||||||||||
| 228 | */ | - | ||||||||||||||||||
| 229 | - | |||||||||||||||||||
| 230 | void QBuffer::setBuffer(QByteArray *byteArray) | - | ||||||||||||||||||
| 231 | { | - | ||||||||||||||||||
| 232 | Q_D(QBuffer); | - | ||||||||||||||||||
| 233 | if (isOpen()) {
| 0-9 | ||||||||||||||||||
| 234 | qWarning("QBuffer::setBuffer: Buffer is open"); | - | ||||||||||||||||||
| 235 | return; never executed: return; | 0 | ||||||||||||||||||
| 236 | } | - | ||||||||||||||||||
| 237 | if (byteArray) {
| 0-9 | ||||||||||||||||||
| 238 | d->buf = byteArray; | - | ||||||||||||||||||
| 239 | } else { executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 240 | d->buf = &d->defaultBuf; | - | ||||||||||||||||||
| 241 | } never executed: end of block | 0 | ||||||||||||||||||
| 242 | d->defaultBuf.clear(); | - | ||||||||||||||||||
| 243 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | /*! | - | ||||||||||||||||||
| 246 | Returns a reference to the QBuffer's internal buffer. You can use | - | ||||||||||||||||||
| 247 | it to modify the QByteArray behind the QBuffer's back. | - | ||||||||||||||||||
| 248 | - | |||||||||||||||||||
| 249 | \sa setBuffer(), data() | - | ||||||||||||||||||
| 250 | */ | - | ||||||||||||||||||
| 251 | - | |||||||||||||||||||
| 252 | QByteArray &QBuffer::buffer() | - | ||||||||||||||||||
| 253 | { | - | ||||||||||||||||||
| 254 | Q_D(QBuffer); | - | ||||||||||||||||||
| 255 | return *d->buf; executed 492 times by 12 tests: return *d->buf;Executed by:
| 492 | ||||||||||||||||||
| 256 | } | - | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | /*! | - | ||||||||||||||||||
| 259 | \overload | - | ||||||||||||||||||
| 260 | - | |||||||||||||||||||
| 261 | This is the same as data(). | - | ||||||||||||||||||
| 262 | */ | - | ||||||||||||||||||
| 263 | - | |||||||||||||||||||
| 264 | const QByteArray &QBuffer::buffer() const | - | ||||||||||||||||||
| 265 | { | - | ||||||||||||||||||
| 266 | Q_D(const QBuffer); | - | ||||||||||||||||||
| 267 | return *d->buf; executed 174 times by 3 tests: return *d->buf;Executed by:
| 174 | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | /*! | - | ||||||||||||||||||
| 272 | Returns the data contained in the buffer. | - | ||||||||||||||||||
| 273 | - | |||||||||||||||||||
| 274 | This is the same as buffer(). | - | ||||||||||||||||||
| 275 | - | |||||||||||||||||||
| 276 | \sa setData(), setBuffer() | - | ||||||||||||||||||
| 277 | */ | - | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | const QByteArray &QBuffer::data() const | - | ||||||||||||||||||
| 280 | { | - | ||||||||||||||||||
| 281 | Q_D(const QBuffer); | - | ||||||||||||||||||
| 282 | return *d->buf; executed 25075 times by 12 tests: return *d->buf;Executed by:
| 25075 | ||||||||||||||||||
| 283 | } | - | ||||||||||||||||||
| 284 | - | |||||||||||||||||||
| 285 | /*! | - | ||||||||||||||||||
| 286 | Sets the contents of the internal buffer to be \a data. This is | - | ||||||||||||||||||
| 287 | the same as assigning \a data to buffer(). | - | ||||||||||||||||||
| 288 | - | |||||||||||||||||||
| 289 | Does nothing if isOpen() is true. | - | ||||||||||||||||||
| 290 | - | |||||||||||||||||||
| 291 | \sa setBuffer() | - | ||||||||||||||||||
| 292 | */ | - | ||||||||||||||||||
| 293 | void QBuffer::setData(const QByteArray &data) | - | ||||||||||||||||||
| 294 | { | - | ||||||||||||||||||
| 295 | Q_D(QBuffer); | - | ||||||||||||||||||
| 296 | if (isOpen()) {
| 0-528 | ||||||||||||||||||
| 297 | qWarning("QBuffer::setData: Buffer is open"); | - | ||||||||||||||||||
| 298 | return; never executed: return; | 0 | ||||||||||||||||||
| 299 | } | - | ||||||||||||||||||
| 300 | *d->buf = data; | - | ||||||||||||||||||
| 301 | } executed 528 times by 29 tests: end of blockExecuted by:
| 528 | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | /*! | - | ||||||||||||||||||
| 304 | \fn void QBuffer::setData(const char *data, int size) | - | ||||||||||||||||||
| 305 | - | |||||||||||||||||||
| 306 | \overload | - | ||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | Sets the contents of the internal buffer to be the first \a size | - | ||||||||||||||||||
| 309 | bytes of \a data. | - | ||||||||||||||||||
| 310 | */ | - | ||||||||||||||||||
| 311 | - | |||||||||||||||||||
| 312 | /*! | - | ||||||||||||||||||
| 313 | \reimp | - | ||||||||||||||||||
| 314 | */ | - | ||||||||||||||||||
| 315 | bool QBuffer::open(OpenMode flags) | - | ||||||||||||||||||
| 316 | { | - | ||||||||||||||||||
| 317 | Q_D(QBuffer); | - | ||||||||||||||||||
| 318 | - | |||||||||||||||||||
| 319 | if ((flags & (Append | Truncate)) != 0)
| 78-10592 | ||||||||||||||||||
| 320 | flags |= WriteOnly; executed 78 times by 5 tests: flags |= WriteOnly;Executed by:
| 78 | ||||||||||||||||||
| 321 | if ((flags & (ReadOnly | WriteOnly)) == 0) {
| 3-10667 | ||||||||||||||||||
| 322 | qWarning("QBuffer::open: Buffer access not specified"); | - | ||||||||||||||||||
| 323 | return false; executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||
| 324 | } | - | ||||||||||||||||||
| 325 | - | |||||||||||||||||||
| 326 | if ((flags & Truncate) == Truncate)
| 52-10615 | ||||||||||||||||||
| 327 | d->buf->resize(0); executed 52 times by 4 tests: d->buf->resize(0);Executed by:
| 52 | ||||||||||||||||||
| 328 | - | |||||||||||||||||||
| 329 | return QIODevice::open(flags | QIODevice::Unbuffered); executed 10667 times by 80 tests: return QIODevice::open(flags | QIODevice::Unbuffered);Executed by:
| 10667 | ||||||||||||||||||
| 330 | } | - | ||||||||||||||||||
| 331 | - | |||||||||||||||||||
| 332 | /*! | - | ||||||||||||||||||
| 333 | \reimp | - | ||||||||||||||||||
| 334 | */ | - | ||||||||||||||||||
| 335 | void QBuffer::close() | - | ||||||||||||||||||
| 336 | { | - | ||||||||||||||||||
| 337 | QIODevice::close(); | - | ||||||||||||||||||
| 338 | } executed 1836 times by 16 tests: end of blockExecuted by:
| 1836 | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | /*! | - | ||||||||||||||||||
| 341 | \reimp | - | ||||||||||||||||||
| 342 | */ | - | ||||||||||||||||||
| 343 | qint64 QBuffer::pos() const | - | ||||||||||||||||||
| 344 | { | - | ||||||||||||||||||
| 345 | return QIODevice::pos(); executed 9742750 times by 80 tests: return QIODevice::pos();Executed by:
| 9742750 | ||||||||||||||||||
| 346 | } | - | ||||||||||||||||||
| 347 | - | |||||||||||||||||||
| 348 | /*! | - | ||||||||||||||||||
| 349 | \reimp | - | ||||||||||||||||||
| 350 | */ | - | ||||||||||||||||||
| 351 | qint64 QBuffer::size() const | - | ||||||||||||||||||
| 352 | { | - | ||||||||||||||||||
| 353 | Q_D(const QBuffer); | - | ||||||||||||||||||
| 354 | return qint64(d->buf->size()); executed 24433 times by 42 tests: return qint64(d->buf->size());Executed by:
| 24433 | ||||||||||||||||||
| 355 | } | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | /*! | - | ||||||||||||||||||
| 358 | \reimp | - | ||||||||||||||||||
| 359 | */ | - | ||||||||||||||||||
| 360 | bool QBuffer::seek(qint64 pos) | - | ||||||||||||||||||
| 361 | { | - | ||||||||||||||||||
| 362 | Q_D(QBuffer); | - | ||||||||||||||||||
| 363 | if (pos > d->buf->size() && isWritable()) {
| 0-45561 | ||||||||||||||||||
| 364 | if (seek(d->buf->size())) {
| 0-3 | ||||||||||||||||||
| 365 | const qint64 gapSize = pos - d->buf->size(); | - | ||||||||||||||||||
| 366 | if (write(QByteArray(gapSize, 0)) != gapSize) {
| 0-3 | ||||||||||||||||||
| 367 | qWarning("QBuffer::seek: Unable to fill gap"); | - | ||||||||||||||||||
| 368 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 369 | } | - | ||||||||||||||||||
| 370 | } else { executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 371 | return false; never executed: return false; | 0 | ||||||||||||||||||
| 372 | } | - | ||||||||||||||||||
| 373 | } else if (pos > d->buf->size() || pos < 0) {
| 0-45561 | ||||||||||||||||||
| 374 | qWarning("QBuffer::seek: Invalid pos: %d", int(pos)); | - | ||||||||||||||||||
| 375 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 376 | } | - | ||||||||||||||||||
| 377 | return QIODevice::seek(pos); executed 45562 times by 29 tests: return QIODevice::seek(pos);Executed by:
| 45562 | ||||||||||||||||||
| 378 | } | - | ||||||||||||||||||
| 379 | - | |||||||||||||||||||
| 380 | /*! | - | ||||||||||||||||||
| 381 | \reimp | - | ||||||||||||||||||
| 382 | */ | - | ||||||||||||||||||
| 383 | bool QBuffer::atEnd() const | - | ||||||||||||||||||
| 384 | { | - | ||||||||||||||||||
| 385 | return QIODevice::atEnd(); executed 4798 times by 32 tests: return QIODevice::atEnd();Executed by:
| 4798 | ||||||||||||||||||
| 386 | } | - | ||||||||||||||||||
| 387 | - | |||||||||||||||||||
| 388 | /*! | - | ||||||||||||||||||
| 389 | \reimp | - | ||||||||||||||||||
| 390 | */ | - | ||||||||||||||||||
| 391 | bool QBuffer::canReadLine() const | - | ||||||||||||||||||
| 392 | { | - | ||||||||||||||||||
| 393 | Q_D(const QBuffer); | - | ||||||||||||||||||
| 394 | if (!isOpen())
| 4-59 | ||||||||||||||||||
| 395 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||
| 396 | - | |||||||||||||||||||
| 397 | return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine(); executed 59 times by 3 tests: return d->buf->indexOf('\n', int(pos())) != -1 || QIODevice::canReadLine();Executed by:
| 0-59 | ||||||||||||||||||
| 398 | } | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | /*! | - | ||||||||||||||||||
| 401 | \reimp | - | ||||||||||||||||||
| 402 | */ | - | ||||||||||||||||||
| 403 | qint64 QBuffer::readData(char *data, qint64 len) | - | ||||||||||||||||||
| 404 | { | - | ||||||||||||||||||
| 405 | Q_D(QBuffer); | - | ||||||||||||||||||
| 406 | if ((len = qMin(len, qint64(d->buf->size()) - pos())) <= 0)
| 1348-4641005 | ||||||||||||||||||
| 407 | return qint64(0); executed 1348 times by 20 tests: return qint64(0);Executed by:
| 1348 | ||||||||||||||||||
| 408 | memcpy(data, d->buf->constData() + pos(), len); | - | ||||||||||||||||||
| 409 | return len; executed 4641005 times by 72 tests: return len;Executed by:
| 4641005 | ||||||||||||||||||
| 410 | } | - | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | /*! | - | ||||||||||||||||||
| 413 | \reimp | - | ||||||||||||||||||
| 414 | */ | - | ||||||||||||||||||
| 415 | qint64 QBuffer::writeData(const char *data, qint64 len) | - | ||||||||||||||||||
| 416 | { | - | ||||||||||||||||||
| 417 | Q_D(QBuffer); | - | ||||||||||||||||||
| 418 | int extraBytes = pos() + len - d->buf->size(); | - | ||||||||||||||||||
| 419 | if (extraBytes > 0) { // overflow
| 8300-211904 | ||||||||||||||||||
| 420 | int newSize = d->buf->size() + extraBytes; | - | ||||||||||||||||||
| 421 | d->buf->resize(newSize); | - | ||||||||||||||||||
| 422 | if (d->buf->size() != newSize) { // could not resize
| 0-211904 | ||||||||||||||||||
| 423 | qWarning("QBuffer::writeData: Memory allocation error"); | - | ||||||||||||||||||
| 424 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
| 425 | } | - | ||||||||||||||||||
| 426 | } executed 211904 times by 69 tests: end of blockExecuted by:
| 211904 | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | memcpy(d->buf->data() + pos(), data, int(len)); | - | ||||||||||||||||||
| 429 | - | |||||||||||||||||||
| 430 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 431 | d->writtenSinceLastEmit += len; | - | ||||||||||||||||||
| 432 | if (d->signalConnectionCount && !d->signalsEmitted && !signalsBlocked()) {
| 0-220164 | ||||||||||||||||||
| 433 | d->signalsEmitted = true; | - | ||||||||||||||||||
| 434 | QMetaObject::invokeMethod(this, "_q_emitSignals", Qt::QueuedConnection); | - | ||||||||||||||||||
| 435 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||
| 436 | #endif | - | ||||||||||||||||||
| 437 | return len; executed 220204 times by 69 tests: return len;Executed by:
| 220204 | ||||||||||||||||||
| 438 | } | - | ||||||||||||||||||
| 439 | - | |||||||||||||||||||
| 440 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 441 | /*! | - | ||||||||||||||||||
| 442 | \reimp | - | ||||||||||||||||||
| 443 | \internal | - | ||||||||||||||||||
| 444 | */ | - | ||||||||||||||||||
| 445 | void QBuffer::connectNotify(const QMetaMethod &signal) | - | ||||||||||||||||||
| 446 | { | - | ||||||||||||||||||
| 447 | static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead); | - | ||||||||||||||||||
| 448 | static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten); | - | ||||||||||||||||||
| 449 | if (signal == readyReadSignal || signal == bytesWrittenSignal)
| 4-1349 | ||||||||||||||||||
| 450 | d_func()->signalConnectionCount++; executed 44 times by 3 tests: d_func()->signalConnectionCount++;Executed by:
| 44 | ||||||||||||||||||
| 451 | } executed 1389 times by 11 tests: end of blockExecuted by:
| 1389 | ||||||||||||||||||
| 452 | - | |||||||||||||||||||
| 453 | /*! | - | ||||||||||||||||||
| 454 | \reimp | - | ||||||||||||||||||
| 455 | \internal | - | ||||||||||||||||||
| 456 | */ | - | ||||||||||||||||||
| 457 | void QBuffer::disconnectNotify(const QMetaMethod &signal) | - | ||||||||||||||||||
| 458 | { | - | ||||||||||||||||||
| 459 | if (signal.isValid()) {
| 0-472 | ||||||||||||||||||
| 460 | static const QMetaMethod readyReadSignal = QMetaMethod::fromSignal(&QBuffer::readyRead); | - | ||||||||||||||||||
| 461 | static const QMetaMethod bytesWrittenSignal = QMetaMethod::fromSignal(&QBuffer::bytesWritten); | - | ||||||||||||||||||
| 462 | if (signal == readyReadSignal || signal == bytesWrittenSignal)
| 0-463 | ||||||||||||||||||
| 463 | d_func()->signalConnectionCount--; executed 9 times by 2 tests: d_func()->signalConnectionCount--;Executed by:
| 9 | ||||||||||||||||||
| 464 | } else { executed 472 times by 3 tests: end of blockExecuted by:
| 472 | ||||||||||||||||||
| 465 | d_func()->signalConnectionCount = 0; | - | ||||||||||||||||||
| 466 | } never executed: end of block | 0 | ||||||||||||||||||
| 467 | } | - | ||||||||||||||||||
| 468 | #endif | - | ||||||||||||||||||
| 469 | - | |||||||||||||||||||
| 470 | QT_END_NAMESPACE | - | ||||||||||||||||||
| 471 | - | |||||||||||||||||||
| 472 | #ifndef QT_NO_QOBJECT | - | ||||||||||||||||||
| 473 | # include "moc_qbuffer.cpp" | - | ||||||||||||||||||
| 474 | #endif | - | ||||||||||||||||||
| 475 | - | |||||||||||||||||||
| Source code | Switch to Preprocessed file |