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