io/qdatastream.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
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 "qdatastream.h" -
43#include "qdatastream_p.h" -
44 -
45#if !defined(QT_NO_DATASTREAM) || defined(QT_BOOTSTRAPPED) -
46#include "qbuffer.h" -
47#include "qstring.h" -
48#include <stdio.h> -
49#include <ctype.h> -
50#include <stdlib.h> -
51#include "qendian.h" -
52 -
53QT_BEGIN_NAMESPACE -
54 -
55/*! -
56 \class QDataStream -
57 \inmodule QtCore -
58 \reentrant -
59 \brief The QDataStream class provides serialization of binary data -
60 to a QIODevice. -
61 -
62 \ingroup io -
63 -
64 -
65 A data stream is a binary stream of encoded information which is -
66 100% independent of the host computer's operating system, CPU or -
67 byte order. For example, a data stream that is written by a PC -
68 under Windows can be read by a Sun SPARC running Solaris. -
69 -
70 You can also use a data stream to read/write \l{raw}{raw -
71 unencoded binary data}. If you want a "parsing" input stream, see -
72 QTextStream. -
73 -
74 The QDataStream class implements the serialization of C++'s basic -
75 data types, like \c char, \c short, \c int, \c{char *}, etc. -
76 Serialization of more complex data is accomplished by breaking up -
77 the data into primitive units. -
78 -
79 A data stream cooperates closely with a QIODevice. A QIODevice -
80 represents an input/output medium one can read data from and write -
81 data to. The QFile class is an example of an I/O device. -
82 -
83 Example (write binary data to a stream): -
84 -
85 \snippet code/src_corelib_io_qdatastream.cpp 0 -
86 -
87 Example (read binary data from a stream): -
88 -
89 \snippet code/src_corelib_io_qdatastream.cpp 1 -
90 -
91 Each item written to the stream is written in a predefined binary -
92 format that varies depending on the item's type. Supported Qt -
93 types include QBrush, QColor, QDateTime, QFont, QPixmap, QString, -
94 QVariant and many others. For the complete list of all Qt types -
95 supporting data streaming see \l{Serializing Qt Data Types}. -
96 -
97 For integers it is best to always cast to a Qt integer type for -
98 writing, and to read back into the same Qt integer type. This -
99 ensures that you get integers of the size you want and insulates -
100 you from compiler and platform differences. -
101 -
102 To take one example, a \c{char *} string is written as a 32-bit -
103 integer equal to the length of the string including the '\\0' byte, -
104 followed by all the characters of the string including the -
105 '\\0' byte. When reading a \c{char *} string, 4 bytes are read to -
106 create the 32-bit length value, then that many characters for the -
107 \c {char *} string including the '\\0' terminator are read. -
108 -
109 The initial I/O device is usually set in the constructor, but can be -
110 changed with setDevice(). If you've reached the end of the data -
111 (or if there is no I/O device set) atEnd() will return true. -
112 -
113 \section1 Versioning -
114 -
115 QDataStream's binary format has evolved since Qt 1.0, and is -
116 likely to continue evolving to reflect changes done in Qt. When -
117 inputting or outputting complex types, it's very important to -
118 make sure that the same version of the stream (version()) is used -
119 for reading and writing. If you need both forward and backward -
120 compatibility, you can hardcode the version number in the -
121 application: -
122 -
123 \snippet code/src_corelib_io_qdatastream.cpp 2 -
124 -
125 If you are producing a new binary data format, such as a file -
126 format for documents created by your application, you could use a -
127 QDataStream to write the data in a portable format. Typically, you -
128 would write a brief header containing a magic string and a version -
129 number to give yourself room for future expansion. For example: -
130 -
131 \snippet code/src_corelib_io_qdatastream.cpp 3 -
132 -
133 Then read it in with: -
134 -
135 \snippet code/src_corelib_io_qdatastream.cpp 4 -
136 -
137 You can select which byte order to use when serializing data. The -
138 default setting is big endian (MSB first). Changing it to little -
139 endian breaks the portability (unless the reader also changes to -
140 little endian). We recommend keeping this setting unless you have -
141 special requirements. -
142 -
143 \target raw -
144 \section1 Reading and writing raw binary data -
145 -
146 You may wish to read/write your own raw binary data to/from the -
147 data stream directly. Data may be read from the stream into a -
148 preallocated \c{char *} using readRawData(). Similarly data can be -
149 written to the stream using writeRawData(). Note that any -
150 encoding/decoding of the data must be done by you. -
151 -
152 A similar pair of functions is readBytes() and writeBytes(). These -
153 differ from their \e raw counterparts as follows: readBytes() -
154 reads a quint32 which is taken to be the length of the data to be -
155 read, then that number of bytes is read into the preallocated -
156 \c{char *}; writeBytes() writes a quint32 containing the length of the -
157 data, followed by the data. Note that any encoding/decoding of -
158 the data (apart from the length quint32) must be done by you. -
159 -
160 \section1 Reading and writing Qt collection classes -
161 -
162 The Qt container classes can also be serialized to a QDataStream. -
163 These include QList, QLinkedList, QVector, QSet, QHash, and QMap. -
164 The stream operators are declared as non-members of the classes. -
165 -
166 \target Serializing Qt Classes -
167 \section1 Reading and writing other Qt classes. -
168 -
169 In addition to the overloaded stream operators documented here, -
170 any Qt classes that you might want to serialize to a QDataStream -
171 will have appropriate stream operators declared as non-member of -
172 the class: -
173 -
174 \code -
175 QDataStream &operator<<(QDataStream &, const QXxx &); -
176 QDataStream &operator>>(QDataStream &, QXxx &); -
177 \endcode -
178 -
179 For example, here are the stream operators declared as non-members -
180 of the QImage class: -
181 -
182 \code -
183 QDataStream & operator<< (QDataStream& stream, const QImage& image); -
184 QDataStream & operator>> (QDataStream& stream, QImage& image); -
185 \endcode -
186 -
187 To see if your favorite Qt class has similar stream operators -
188 defined, check the \b {Related Non-Members} section of the -
189 class's documentation page. -
190 -
191 \sa QTextStream, QVariant -
192*/ -
193 -
194/*! -
195 \enum QDataStream::ByteOrder -
196 -
197 The byte order used for reading/writing the data. -
198 -
199 \value BigEndian Most significant byte first (the default) -
200 \value LittleEndian Least significant byte first -
201*/ -
202 -
203/*! -
204 \enum QDataStream::FloatingPointPrecision -
205 -
206 The precision of floating point numbers used for reading/writing the data. This will only have -
207 an effect if the version of the data stream is Qt_4_6 or higher. -
208 -
209 \warning The floating point precision must be set to the same value on the object that writes -
210 and the object that reads the data stream. -
211 -
212 \value SinglePrecision All floating point numbers in the data stream have 32-bit precision. -
213 \value DoublePrecision All floating point numbers in the data stream have 64-bit precision. -
214 -
215 \sa setFloatingPointPrecision(), floatingPointPrecision() -
216*/ -
217 -
218/*! -
219 \enum QDataStream::Status -
220 -
221 This enum describes the current status of the data stream. -
222 -
223 \value Ok The data stream is operating normally. -
224 \value ReadPastEnd The data stream has read past the end of the -
225 data in the underlying device. -
226 \value ReadCorruptData The data stream has read corrupt data. -
227 \value WriteFailed The data stream cannot write to the underlying device. -
228*/ -
229 -
230/***************************************************************************** -
231 QDataStream member functions -
232 *****************************************************************************/ -
233 -
234#undef CHECK_STREAM_PRECOND -
235#ifndef QT_NO_DEBUG -
236#define CHECK_STREAM_PRECOND(retVal) \ -
237 if (!dev) { \ -
238 qWarning("QDataStream: No device"); \ -
239 return retVal; \ -
240 } -
241#else -
242#define CHECK_STREAM_PRECOND(retVal) \ -
243 if (!dev) { \ -
244 return retVal; \ -
245 } -
246#endif -
247 -
248#define CHECK_STREAM_WRITE_PRECOND(retVal) \ -
249 CHECK_STREAM_PRECOND(retVal) \ -
250 if (q_status != Ok) \ -
251 return retVal; -
252 -
253enum { -
254 DefaultStreamVersion = QDataStream::Qt_5_0 -
255}; -
256 -
257/*! -
258 Constructs a data stream that has no I/O device. -
259 -
260 \sa setDevice() -
261*/ -
262 -
263QDataStream::QDataStream() -
264{ -
265 dev = 0;
executed (the execution status of this line is deduced): dev = 0;
-
266 owndev = false;
executed (the execution status of this line is deduced): owndev = false;
-
267 byteorder = BigEndian;
executed (the execution status of this line is deduced): byteorder = BigEndian;
-
268 ver = DefaultStreamVersion;
executed (the execution status of this line is deduced): ver = DefaultStreamVersion;
-
269 noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
executed (the execution status of this line is deduced): noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
-
270 q_status = Ok;
executed (the execution status of this line is deduced): q_status = Ok;
-
271}
executed: }
Execution Count:275
275
272 -
273/*! -
274 Constructs a data stream that uses the I/O device \a d. -
275 -
276 \warning If you use QSocket or QSocketDevice as the I/O device \a d -
277 for reading data, you must make sure that enough data is available -
278 on the socket for the operation to successfully proceed; -
279 QDataStream does not have any means to handle or recover from -
280 short-reads. -
281 -
282 \sa setDevice(), device() -
283*/ -
284 -
285QDataStream::QDataStream(QIODevice *d) -
286{ -
287 dev = d; // set device
executed (the execution status of this line is deduced): dev = d;
-
288 owndev = false;
executed (the execution status of this line is deduced): owndev = false;
-
289 byteorder = BigEndian; // default byte order
executed (the execution status of this line is deduced): byteorder = BigEndian;
-
290 ver = DefaultStreamVersion;
executed (the execution status of this line is deduced): ver = DefaultStreamVersion;
-
291 noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
executed (the execution status of this line is deduced): noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
-
292 q_status = Ok;
executed (the execution status of this line is deduced): q_status = Ok;
-
293}
executed: }
Execution Count:3342
3342
294 -
295/*! -
296 \fn QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode mode) -
297 -
298 Constructs a data stream that operates on a byte array, \a a. The -
299 \a mode describes how the device is to be used. -
300 -
301 Alternatively, you can use QDataStream(const QByteArray &) if you -
302 just want to read from a byte array. -
303 -
304 Since QByteArray is not a QIODevice subclass, internally a QBuffer -
305 is created to wrap the byte array. -
306*/ -
307 -
308QDataStream::QDataStream(QByteArray *a, QIODevice::OpenMode flags) -
309{ -
310 QBuffer *buf = new QBuffer(a);
executed (the execution status of this line is deduced): QBuffer *buf = new QBuffer(a);
-
311#ifndef QT_NO_QOBJECT -
312 buf->blockSignals(true);
executed (the execution status of this line is deduced): buf->blockSignals(true);
-
313#endif -
314 buf->open(flags);
executed (the execution status of this line is deduced): buf->open(flags);
-
315 dev = buf;
executed (the execution status of this line is deduced): dev = buf;
-
316 owndev = true;
executed (the execution status of this line is deduced): owndev = true;
-
317 byteorder = BigEndian;
executed (the execution status of this line is deduced): byteorder = BigEndian;
-
318 ver = DefaultStreamVersion;
executed (the execution status of this line is deduced): ver = DefaultStreamVersion;
-
319 noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
executed (the execution status of this line is deduced): noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
-
320 q_status = Ok;
executed (the execution status of this line is deduced): q_status = Ok;
-
321}
executed: }
Execution Count:3168
3168
322 -
323/*! -
324 Constructs a read-only data stream that operates on byte array \a a. -
325 Use QDataStream(QByteArray*, int) if you want to write to a byte -
326 array. -
327 -
328 Since QByteArray is not a QIODevice subclass, internally a QBuffer -
329 is created to wrap the byte array. -
330*/ -
331QDataStream::QDataStream(const QByteArray &a) -
332{ -
333 QBuffer *buf = new QBuffer;
executed (the execution status of this line is deduced): QBuffer *buf = new QBuffer;
-
334#ifndef QT_NO_QOBJECT -
335 buf->blockSignals(true);
executed (the execution status of this line is deduced): buf->blockSignals(true);
-
336#endif -
337 buf->setData(a);
executed (the execution status of this line is deduced): buf->setData(a);
-
338 buf->open(QIODevice::ReadOnly);
executed (the execution status of this line is deduced): buf->open(QIODevice::ReadOnly);
-
339 dev = buf;
executed (the execution status of this line is deduced): dev = buf;
-
340 owndev = true;
executed (the execution status of this line is deduced): owndev = true;
-
341 byteorder = BigEndian;
executed (the execution status of this line is deduced): byteorder = BigEndian;
-
342 ver = DefaultStreamVersion;
executed (the execution status of this line is deduced): ver = DefaultStreamVersion;
-
343 noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
executed (the execution status of this line is deduced): noswap = QSysInfo::ByteOrder == QSysInfo::BigEndian;
-
344 q_status = Ok;
executed (the execution status of this line is deduced): q_status = Ok;
-
345}
executed: }
Execution Count:33
33
346 -
347/*! -
348 Destroys the data stream. -
349 -
350 The destructor will not affect the current I/O device, unless it is -
351 an internal I/O device (e.g. a QBuffer) processing a QByteArray -
352 passed in the \e constructor, in which case the internal I/O device -
353 is destroyed. -
354*/ -
355 -
356QDataStream::~QDataStream() -
357{ -
358 if (owndev)
evaluated: owndev
TRUEFALSE
yes
Evaluation Count:3201
yes
Evaluation Count:3617
3201-3617
359 delete dev;
executed: delete dev;
Execution Count:3201
3201
360}
executed: }
Execution Count:6818
6818
361 -
362 -
363/*! -
364 \fn QIODevice *QDataStream::device() const -
365 -
366 Returns the I/O device currently set, or 0 if no -
367 device is currently set. -
368 -
369 \sa setDevice() -
370*/ -
371 -
372/*! -
373 void QDataStream::setDevice(QIODevice *d) -
374 -
375 Sets the I/O device to \a d, which can be 0 -
376 to unset to current I/O device. -
377 -
378 \sa device() -
379*/ -
380 -
381void QDataStream::setDevice(QIODevice *d) -
382{ -
383 if (owndev) {
partially evaluated: owndev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:67
0-67
384 delete dev;
never executed (the execution status of this line is deduced): delete dev;
-
385 owndev = false;
never executed (the execution status of this line is deduced): owndev = false;
-
386 }
never executed: }
0
387 dev = d;
executed (the execution status of this line is deduced): dev = d;
-
388}
executed: }
Execution Count:67
67
389 -
390/*! -
391 \obsolete -
392 Unsets the I/O device. -
393 Use setDevice(0) instead. -
394*/ -
395 -
396void QDataStream::unsetDevice() -
397{ -
398 setDevice(0);
executed (the execution status of this line is deduced): setDevice(0);
-
399}
executed: }
Execution Count:20
20
400 -
401 -
402/*! -
403 \fn bool QDataStream::atEnd() const -
404 -
405 Returns true if the I/O device has reached the end position (end of -
406 the stream or file) or if there is no I/O device set; otherwise -
407 returns false. -
408 -
409 \sa QIODevice::atEnd() -
410*/ -
411 -
412bool QDataStream::atEnd() const -
413{ -
414 return dev ? dev->atEnd() : true;
executed: return dev ? dev->atEnd() : true;
Execution Count:1406
1406
415} -
416 -
417/*! -
418 Returns the floating point precision of the data stream. -
419 -
420 \since 4.6 -
421 -
422 \sa FloatingPointPrecision, setFloatingPointPrecision() -
423*/ -
424QDataStream::FloatingPointPrecision QDataStream::floatingPointPrecision() const -
425{ -
426 return d == 0 ? QDataStream::DoublePrecision : d->floatingPointPrecision;
executed: return d == 0 ? QDataStream::DoublePrecision : d->floatingPointPrecision;
Execution Count:9593
9593
427} -
428 -
429/*! -
430 Sets the floating point precision of the data stream to \a precision. If the floating point precision is -
431 DoublePrecision and the version of the data stream is Qt_4_6 or higher, all floating point -
432 numbers will be written and read with 64-bit precision. If the floating point precision is -
433 SinglePrecision and the version is Qt_4_6 or higher, all floating point numbers will be written -
434 and read with 32-bit precision. -
435 -
436 For versions prior to Qt_4_6, the precision of floating point numbers in the data stream depends -
437 on the stream operator called. -
438 -
439 The default is DoublePrecision. -
440 -
441 \warning This property must be set to the same value on the object that writes and the object -
442 that reads the data stream. -
443 -
444 \since 4.6 -
445*/ -
446void QDataStream::setFloatingPointPrecision(QDataStream::FloatingPointPrecision precision) -
447{ -
448 if (d == 0)
partially evaluated: d == 0
TRUEFALSE
yes
Evaluation Count:58
no
Evaluation Count:0
0-58
449 d.reset(new QDataStreamPrivate());
executed: d.reset(new QDataStreamPrivate());
Execution Count:58
58
450 d->floatingPointPrecision = precision;
executed (the execution status of this line is deduced): d->floatingPointPrecision = precision;
-
451}
executed: }
Execution Count:58
58
452 -
453/*! -
454 Returns the status of the data stream. -
455 -
456 \sa Status, setStatus(), resetStatus() -
457*/ -
458 -
459QDataStream::Status QDataStream::status() const -
460{ -
461 return q_status;
executed: return q_status;
Execution Count:14753
14753
462} -
463 -
464/*! -
465 Resets the status of the data stream. -
466 -
467 \sa Status, status(), setStatus() -
468*/ -
469void QDataStream::resetStatus() -
470{ -
471 q_status = Ok;
executed (the execution status of this line is deduced): q_status = Ok;
-
472}
executed: }
Execution Count:465
465
473 -
474/*! -
475 Sets the status of the data stream to the \a status given. -
476 -
477 Subsequent calls to setStatus() are ignored until resetStatus() -
478 is called. -
479 -
480 \sa Status, status(), resetStatus() -
481*/ -
482void QDataStream::setStatus(Status status) -
483{ -
484 if (q_status == Ok)
evaluated: q_status == Ok
TRUEFALSE
yes
Evaluation Count:336
yes
Evaluation Count:125
125-336
485 q_status = status;
executed: q_status = status;
Execution Count:336
336
486}
executed: }
Execution Count:461
461
487 -
488/*! -
489 \fn int QDataStream::byteOrder() const -
490 -
491 Returns the current byte order setting -- either BigEndian or -
492 LittleEndian. -
493 -
494 \sa setByteOrder() -
495*/ -
496 -
497/*! -
498 Sets the serialization byte order to \a bo. -
499 -
500 The \a bo parameter can be QDataStream::BigEndian or -
501 QDataStream::LittleEndian. -
502 -
503 The default setting is big endian. We recommend leaving this -
504 setting unless you have special requirements. -
505 -
506 \sa byteOrder() -
507*/ -
508 -
509void QDataStream::setByteOrder(ByteOrder bo) -
510{ -
511 byteorder = bo;
executed (the execution status of this line is deduced): byteorder = bo;
-
512 if (QSysInfo::ByteOrder == QSysInfo::BigEndian)
partially evaluated: QSysInfo::ByteOrder == QSysInfo::BigEndian
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:875
0-875
513 noswap = (byteorder == BigEndian);
never executed: noswap = (byteorder == BigEndian);
0
514 else -
515 noswap = (byteorder == LittleEndian);
executed: noswap = (byteorder == LittleEndian);
Execution Count:875
875
516} -
517 -
518 -
519/*! -
520 \enum QDataStream::Version -
521 -
522 This enum provides symbolic synonyms for the data serialization -
523 format version numbers. -
524 -
525 \value Qt_1_0 Version 1 (Qt 1.x) -
526 \value Qt_2_0 Version 2 (Qt 2.0) -
527 \value Qt_2_1 Version 3 (Qt 2.1, 2.2, 2.3) -
528 \value Qt_3_0 Version 4 (Qt 3.0) -
529 \value Qt_3_1 Version 5 (Qt 3.1, 3.2) -
530 \value Qt_3_3 Version 6 (Qt 3.3) -
531 \value Qt_4_0 Version 7 (Qt 4.0, Qt 4.1) -
532 \value Qt_4_1 Version 7 (Qt 4.0, Qt 4.1) -
533 \value Qt_4_2 Version 8 (Qt 4.2) -
534 \value Qt_4_3 Version 9 (Qt 4.3) -
535 \value Qt_4_4 Version 10 (Qt 4.4) -
536 \value Qt_4_5 Version 11 (Qt 4.5) -
537 \value Qt_4_6 Version 12 (Qt 4.6, Qt 4.7, Qt 4.8) -
538 \value Qt_4_7 Same as Qt_4_6. -
539 \value Qt_4_8 Same as Qt_4_6. -
540 \value Qt_4_9 Same as Qt_4_6. -
541 \value Qt_5_0 Version 13 (Qt 5.0) -
542 -
543 \sa setVersion(), version() -
544*/ -
545 -
546/*! -
547 \fn int QDataStream::version() const -
548 -
549 Returns the version number of the data serialization format. -
550 -
551 \sa setVersion(), Version -
552*/ -
553 -
554/*! -
555 \fn void QDataStream::setVersion(int v) -
556 -
557 Sets the version number of the data serialization format to \a v. -
558 -
559 You don't \e have to set a version if you are using the current -
560 version of Qt, but for your own custom binary formats we -
561 recommend that you do; see \l{Versioning} in the Detailed -
562 Description. -
563 -
564 To accommodate new functionality, the datastream serialization -
565 format of some Qt classes has changed in some versions of Qt. If -
566 you want to read data that was created by an earlier version of -
567 Qt, or write data that can be read by a program that was compiled -
568 with an earlier version of Qt, use this function to modify the -
569 serialization format used by QDataStream. -
570 -
571 \table -
572 \header \li Qt Version \li QDataStream Version -
573 \row \li Qt 4.6 \li 12 -
574 \row \li Qt 4.5 \li 11 -
575 \row \li Qt 4.4 \li 10 -
576 \row \li Qt 4.3 \li 9 -
577 \row \li Qt 4.2 \li 8 -
578 \row \li Qt 4.0, 4.1 \li 7 -
579 \row \li Qt 3.3 \li 6 -
580 \row \li Qt 3.1, 3.2 \li 5 -
581 \row \li Qt 3.0 \li 4 -
582 \row \li Qt 2.1, 2.2, 2.3 \li 3 -
583 \row \li Qt 2.0 \li 2 -
584 \row \li Qt 1.x \li 1 -
585 \endtable -
586 -
587 The \l Version enum provides symbolic constants for the different -
588 versions of Qt. For example: -
589 -
590 \snippet code/src_corelib_io_qdatastream.cpp 5 -
591 -
592 \sa version(), Version -
593*/ -
594 -
595/***************************************************************************** -
596 QDataStream read functions -
597 *****************************************************************************/ -
598 -
599/*! -
600 \fn QDataStream &QDataStream::operator>>(quint8 &i) -
601 \overload -
602 -
603 Reads an unsigned byte from the stream into \a i, and returns a -
604 reference to the stream. -
605*/ -
606 -
607/*! -
608 Reads a signed byte from the stream into \a i, and returns a -
609 reference to the stream. -
610*/ -
611 -
612QDataStream &QDataStream::operator>>(qint8 &i) -
613{ -
614 i = 0;
executed (the execution status of this line is deduced): i = 0;
-
615 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:17825
0-17825
616 char c;
executed (the execution status of this line is deduced): char c;
-
617 if (!dev->getChar(&c))
evaluated: !dev->getChar(&c)
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:17797
28-17797
618 setStatus(ReadPastEnd);
executed: setStatus(ReadPastEnd);
Execution Count:28
28
619 else -
620 i = qint8(c);
executed: i = qint8(c);
Execution Count:17797
17797
621 return *this;
executed: return *this;
Execution Count:17825
17825
622} -
623 -
624 -
625/*! -
626 \fn QDataStream &QDataStream::operator>>(quint16 &i) -
627 \overload -
628 -
629 Reads an unsigned 16-bit integer from the stream into \a i, and -
630 returns a reference to the stream. -
631*/ -
632 -
633/*! -
634 \overload -
635 -
636 Reads a signed 16-bit integer from the stream into \a i, and -
637 returns a reference to the stream. -
638*/ -
639 -
640QDataStream &QDataStream::operator>>(qint16 &i) -
641{ -
642 i = 0;
executed (the execution status of this line is deduced): i = 0;
-
643 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6818
0-6818
644 if (dev->read((char *)&i, 2) != 2) {
evaluated: dev->read((char *)&i, 2) != 2
TRUEFALSE
yes
Evaluation Count:58
yes
Evaluation Count:6760
58-6760
645 i = 0;
executed (the execution status of this line is deduced): i = 0;
-
646 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
647 } else {
executed: }
Execution Count:58
58
648 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:5464
yes
Evaluation Count:1296
1296-5464
649 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
650 }
executed: }
Execution Count:5464
5464
651 }
executed: }
Execution Count:6760
6760
652 return *this;
executed: return *this;
Execution Count:6818
6818
653} -
654 -
655 -
656/*! -
657 \fn QDataStream &QDataStream::operator>>(quint32 &i) -
658 \overload -
659 -
660 Reads an unsigned 32-bit integer from the stream into \a i, and -
661 returns a reference to the stream. -
662*/ -
663 -
664/*! -
665 \overload -
666 -
667 Reads a signed 32-bit integer from the stream into \a i, and -
668 returns a reference to the stream. -
669*/ -
670 -
671QDataStream &QDataStream::operator>>(qint32 &i) -
672{ -
673 i = 0;
executed (the execution status of this line is deduced): i = 0;
-
674 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:52588
0-52588
675 if (dev->read((char *)&i, 4) != 4) {
evaluated: dev->read((char *)&i, 4) != 4
TRUEFALSE
yes
Evaluation Count:185
yes
Evaluation Count:52403
185-52403
676 i = 0;
executed (the execution status of this line is deduced): i = 0;
-
677 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
678 } else {
executed: }
Execution Count:185
185
679 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:48860
yes
Evaluation Count:3543
3543-48860
680 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
681 }
executed: }
Execution Count:48860
48860
682 }
executed: }
Execution Count:52403
52403
683 return *this;
executed: return *this;
Execution Count:52588
52588
684} -
685 -
686/*! -
687 \fn QDataStream &QDataStream::operator>>(quint64 &i) -
688 \overload -
689 -
690 Reads an unsigned 64-bit integer from the stream, into \a i, and -
691 returns a reference to the stream. -
692*/ -
693 -
694/*! -
695 \overload -
696 -
697 Reads a signed 64-bit integer from the stream into \a i, and -
698 returns a reference to the stream. -
699*/ -
700 -
701QDataStream &QDataStream::operator>>(qint64 &i) -
702{ -
703 i = qint64(0);
executed (the execution status of this line is deduced): i = qint64(0);
-
704 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:600
0-600
705 if (version() < 6) {
partially evaluated: version() < 6
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:600
0-600
706 quint32 i1, i2;
never executed (the execution status of this line is deduced): quint32 i1, i2;
-
707 *this >> i2 >> i1;
never executed (the execution status of this line is deduced): *this >> i2 >> i1;
-
708 i = ((quint64)i1 << 32) + i2;
never executed (the execution status of this line is deduced): i = ((quint64)i1 << 32) + i2;
-
709 } else {
never executed: }
0
710 if (dev->read((char *)&i, 8) != 8) {
evaluated: dev->read((char *)&i, 8) != 8
TRUEFALSE
yes
Evaluation Count:50
yes
Evaluation Count:550
50-550
711 i = qint64(0);
executed (the execution status of this line is deduced): i = qint64(0);
-
712 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
713 } else {
executed: }
Execution Count:50
50
714 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:538
yes
Evaluation Count:12
12-538
715 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
716 }
executed: }
Execution Count:538
538
717 }
executed: }
Execution Count:550
550
718 } -
719 return *this;
executed: return *this;
Execution Count:600
600
720} -
721 -
722/*! -
723 Reads a boolean value from the stream into \a i. Returns a -
724 reference to the stream. -
725*/ -
726QDataStream &QDataStream::operator>>(bool &i) -
727{ -
728 qint8 v;
executed (the execution status of this line is deduced): qint8 v;
-
729 *this >> v;
executed (the execution status of this line is deduced): *this >> v;
-
730 i = !!v;
executed (the execution status of this line is deduced): i = !!v;
-
731 return *this;
executed: return *this;
Execution Count:1260
1260
732} -
733 -
734/*! -
735 \overload -
736 -
737 Reads a floating point number from the stream into \a f, -
738 using the standard IEEE 754 format. Returns a reference to the -
739 stream. -
740 -
741 \sa setFloatingPointPrecision() -
742*/ -
743 -
744QDataStream &QDataStream::operator>>(float &f) -
745{ -
746 if (version() >= QDataStream::Qt_4_6
partially evaluated: version() >= QDataStream::Qt_4_6
TRUEFALSE
yes
Evaluation Count:38
no
Evaluation Count:0
0-38
747 && floatingPointPrecision() == QDataStream::DoublePrecision) {
evaluated: floatingPointPrecision() == QDataStream::DoublePrecision
TRUEFALSE
yes
Evaluation Count:12
yes
Evaluation Count:26
12-26
748 double d;
executed (the execution status of this line is deduced): double d;
-
749 *this >> d;
executed (the execution status of this line is deduced): *this >> d;
-
750 f = d;
executed (the execution status of this line is deduced): f = d;
-
751 return *this;
executed: return *this;
Execution Count:12
12
752 } -
753 -
754 f = 0.0f;
executed (the execution status of this line is deduced): f = 0.0f;
-
755 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:26
0-26
756 if (dev->read((char *)&f, 4) != 4) {
evaluated: dev->read((char *)&f, 4) != 4
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:16
10-16
757 f = 0.0f;
executed (the execution status of this line is deduced): f = 0.0f;
-
758 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
759 } else {
executed: }
Execution Count:10
10
760 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:6
6-10
761 union {
executed (the execution status of this line is deduced): union {
-
762 float val1;
executed (the execution status of this line is deduced): float val1;
-
763 quint32 val2;
executed (the execution status of this line is deduced): quint32 val2;
-
764 } x;
executed (the execution status of this line is deduced): } x;
-
765 x.val2 = qbswap(*reinterpret_cast<quint32 *>(&f));
executed (the execution status of this line is deduced): x.val2 = qbswap(*reinterpret_cast<quint32 *>(&f));
-
766 f = x.val1;
executed (the execution status of this line is deduced): f = x.val1;
-
767 }
executed: }
Execution Count:10
10
768 }
executed: }
Execution Count:16
16
769 return *this;
executed: return *this;
Execution Count:26
26
770} -
771 -
772/*! -
773 \overload -
774 -
775 Reads a floating point number from the stream into \a f, -
776 using the standard IEEE 754 format. Returns a reference to the -
777 stream. -
778 -
779 \sa setFloatingPointPrecision() -
780*/ -
781 -
782QDataStream &QDataStream::operator>>(double &f) -
783{ -
784 if (version() >= QDataStream::Qt_4_6
evaluated: version() >= QDataStream::Qt_4_6
TRUEFALSE
yes
Evaluation Count:4812
yes
Evaluation Count:3220
3220-4812
785 && floatingPointPrecision() == QDataStream::SinglePrecision) {
evaluated: floatingPointPrecision() == QDataStream::SinglePrecision
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4811
1-4811
786 float d;
executed (the execution status of this line is deduced): float d;
-
787 *this >> d;
executed (the execution status of this line is deduced): *this >> d;
-
788 f = d;
executed (the execution status of this line is deduced): f = d;
-
789 return *this;
executed: return *this;
Execution Count:1
1
790 } -
791 -
792 f = 0.0;
executed (the execution status of this line is deduced): f = 0.0;
-
793 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8031
0-8031
794 if (dev->read((char *)&f, 8) != 8) {
evaluated: dev->read((char *)&f, 8) != 8
TRUEFALSE
yes
Evaluation Count:46
yes
Evaluation Count:7985
46-7985
795 f = 0.0;
executed (the execution status of this line is deduced): f = 0.0;
-
796 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
797 } else {
executed: }
Execution Count:46
46
798 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:7978
yes
Evaluation Count:7
7-7978
799 union {
executed (the execution status of this line is deduced): union {
-
800 double val1;
executed (the execution status of this line is deduced): double val1;
-
801 quint64 val2;
executed (the execution status of this line is deduced): quint64 val2;
-
802 } x;
executed (the execution status of this line is deduced): } x;
-
803 x.val2 = qbswap(*reinterpret_cast<quint64 *>(&f));
executed (the execution status of this line is deduced): x.val2 = qbswap(*reinterpret_cast<quint64 *>(&f));
-
804 f = x.val1;
executed (the execution status of this line is deduced): f = x.val1;
-
805 }
executed: }
Execution Count:7978
7978
806 }
executed: }
Execution Count:7985
7985
807 return *this;
executed: return *this;
Execution Count:8031
8031
808} -
809 -
810 -
811/*! -
812 \overload -
813 -
814 Reads the '\\0'-terminated string \a s from the stream and returns -
815 a reference to the stream. -
816 -
817 Space for the string is allocated using \c new -- the caller must -
818 destroy it with \c{delete[]}. -
819*/ -
820 -
821QDataStream &QDataStream::operator>>(char *&s) -
822{ -
823 uint len = 0;
executed (the execution status of this line is deduced): uint len = 0;
-
824 return readBytes(s, len);
executed: return readBytes(s, len);
Execution Count:28
28
825} -
826 -
827 -
828/*! -
829 Reads the buffer \a s from the stream and returns a reference to -
830 the stream. -
831 -
832 The buffer \a s is allocated using \c new. Destroy it with the \c -
833 delete[] operator. -
834 -
835 The \a l parameter is set to the length of the buffer. If the -
836 string read is empty, \a l is set to 0 and \a s is set to -
837 a null pointer. -
838 -
839 The serialization format is a quint32 length specifier first, -
840 then \a l bytes of data. -
841 -
842 \sa readRawData(), writeBytes() -
843*/ -
844 -
845QDataStream &QDataStream::readBytes(char *&s, uint &l) -
846{ -
847 s = 0;
executed (the execution status of this line is deduced): s = 0;
-
848 l = 0;
executed (the execution status of this line is deduced): l = 0;
-
849 CHECK_STREAM_PRECOND(*this)
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:56
0-56
850 -
851 quint32 len;
executed (the execution status of this line is deduced): quint32 len;
-
852 *this >> len;
executed (the execution status of this line is deduced): *this >> len;
-
853 if (len == 0)
evaluated: len == 0
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:46
10-46
854 return *this;
executed: return *this;
Execution Count:10
10
855 -
856 const quint32 Step = 1024 * 1024;
executed (the execution status of this line is deduced): const quint32 Step = 1024 * 1024;
-
857 quint32 allocated = 0;
executed (the execution status of this line is deduced): quint32 allocated = 0;
-
858 char *prevBuf = 0;
executed (the execution status of this line is deduced): char *prevBuf = 0;
-
859 char *curBuf = 0;
executed (the execution status of this line is deduced): char *curBuf = 0;
-
860 -
861 do { -
862 int blockSize = qMin(Step, len - allocated);
executed (the execution status of this line is deduced): int blockSize = qMin(Step, len - allocated);
-
863 prevBuf = curBuf;
executed (the execution status of this line is deduced): prevBuf = curBuf;
-
864 curBuf = new char[allocated + blockSize + 1];
executed (the execution status of this line is deduced): curBuf = new char[allocated + blockSize + 1];
-
865 if (prevBuf) {
evaluated: prevBuf
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:46
28-46
866 memcpy(curBuf, prevBuf, allocated);
executed (the execution status of this line is deduced): memcpy(curBuf, prevBuf, allocated);
-
867 delete [] prevBuf;
executed (the execution status of this line is deduced): delete [] prevBuf;
-
868 }
executed: }
Execution Count:28
28
869 if (dev->read(curBuf + allocated, blockSize) != blockSize) {
evaluated: dev->read(curBuf + allocated, blockSize) != blockSize
TRUEFALSE
yes
Evaluation Count:24
yes
Evaluation Count:50
24-50
870 delete [] curBuf;
executed (the execution status of this line is deduced): delete [] curBuf;
-
871 setStatus(ReadPastEnd);
executed (the execution status of this line is deduced): setStatus(ReadPastEnd);
-
872 return *this;
executed: return *this;
Execution Count:24
24
873 } -
874 allocated += blockSize;
executed (the execution status of this line is deduced): allocated += blockSize;
-
875 } while (allocated < len);
executed: }
Execution Count:50
evaluated: allocated < len
TRUEFALSE
yes
Evaluation Count:28
yes
Evaluation Count:22
22-50
876 -
877 s = curBuf;
executed (the execution status of this line is deduced): s = curBuf;
-
878 s[len] = '\0';
executed (the execution status of this line is deduced): s[len] = '\0';
-
879 l = (uint)len;
executed (the execution status of this line is deduced): l = (uint)len;
-
880 return *this;
executed: return *this;
Execution Count:22
22
881} -
882 -
883/*! -
884 Reads at most \a len bytes from the stream into \a s and returns the number of -
885 bytes read. If an error occurs, this function returns -1. -
886 -
887 The buffer \a s must be preallocated. The data is \e not encoded. -
888 -
889 \sa readBytes(), QIODevice::read(), writeRawData() -
890*/ -
891 -
892int QDataStream::readRawData(char *s, int len) -
893{ -
894 CHECK_STREAM_PRECOND(-1)
never executed: return -1;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15407
0-15407
895 return dev->read(s, len);
executed: return dev->read(s, len);
Execution Count:15407
15407
896} -
897 -
898 -
899/***************************************************************************** -
900 QDataStream write functions -
901 *****************************************************************************/ -
902 -
903 -
904/*! -
905 \fn QDataStream &QDataStream::operator<<(quint8 i) -
906 \overload -
907 -
908 Writes an unsigned byte, \a i, to the stream and returns a -
909 reference to the stream. -
910*/ -
911 -
912/*! -
913 Writes a signed byte, \a i, to the stream and returns a reference -
914 to the stream. -
915*/ -
916 -
917QDataStream &QDataStream::operator<<(qint8 i) -
918{ -
919 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:2
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16668
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16666
0-16668
920 if (!dev->putChar(i))
evaluated: !dev->putChar(i)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:16664
2-16664
921 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:2
2
922 return *this;
executed: return *this;
Execution Count:16666
16666
923} -
924 -
925 -
926/*! -
927 \fn QDataStream &QDataStream::operator<<(quint16 i) -
928 \overload -
929 -
930 Writes an unsigned 16-bit integer, \a i, to the stream and returns -
931 a reference to the stream. -
932*/ -
933 -
934/*! -
935 \overload -
936 -
937 Writes a signed 16-bit integer, \a i, to the stream and returns a -
938 reference to the stream. -
939*/ -
940 -
941QDataStream &QDataStream::operator<<(qint16 i) -
942{ -
943 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:2
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:5757
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:5755
0-5757
944 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:5627
yes
Evaluation Count:128
128-5627
945 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
946 }
executed: }
Execution Count:5627
5627
947 if (dev->write((char *)&i, sizeof(qint16)) != sizeof(qint16))
evaluated: dev->write((char *)&i, sizeof(qint16)) != sizeof(qint16)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:5753
2-5753
948 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:2
2
949 return *this;
executed: return *this;
Execution Count:5755
5755
950} -
951 -
952/*! -
953 \overload -
954 -
955 Writes a signed 32-bit integer, \a i, to the stream and returns a -
956 reference to the stream. -
957*/ -
958 -
959QDataStream &QDataStream::operator<<(qint32 i) -
960{ -
961 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:3
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:53180
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:53177
0-53180
962 if (!noswap) {
evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:52825
yes
Evaluation Count:352
352-52825
963 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
964 }
executed: }
Execution Count:52825
52825
965 if (dev->write((char *)&i, sizeof(qint32)) != sizeof(qint32))
evaluated: dev->write((char *)&i, sizeof(qint32)) != sizeof(qint32)
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:53174
3-53174
966 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:3
3
967 return *this;
executed: return *this;
Execution Count:53177
53177
968} -
969 -
970/*! -
971 \fn QDataStream &QDataStream::operator<<(quint64 i) -
972 \overload -
973 -
974 Writes an unsigned 64-bit integer, \a i, to the stream and returns a -
975 reference to the stream. -
976*/ -
977 -
978/*! -
979 \overload -
980 -
981 Writes a signed 64-bit integer, \a i, to the stream and returns a -
982 reference to the stream. -
983*/ -
984 -
985QDataStream &QDataStream::operator<<(qint64 i) -
986{ -
987 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:2
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:536
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:534
0-536
988 if (version() < 6) {
partially evaluated: version() < 6
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:534
0-534
989 quint32 i1 = i & 0xffffffff;
never executed (the execution status of this line is deduced): quint32 i1 = i & 0xffffffff;
-
990 quint32 i2 = i >> 32;
never executed (the execution status of this line is deduced): quint32 i2 = i >> 32;
-
991 *this << i2 << i1;
never executed (the execution status of this line is deduced): *this << i2 << i1;
-
992 } else {
never executed: }
0
993 if (!noswap) {
partially evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:534
no
Evaluation Count:0
0-534
994 i = qbswap(i);
executed (the execution status of this line is deduced): i = qbswap(i);
-
995 }
executed: }
Execution Count:534
534
996 if (dev->write((char *)&i, sizeof(qint64)) != sizeof(qint64))
evaluated: dev->write((char *)&i, sizeof(qint64)) != sizeof(qint64)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:532
2-532
997 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:2
2
998 }
executed: }
Execution Count:534
534
999 return *this;
executed: return *this;
Execution Count:534
534
1000} -
1001 -
1002/*! -
1003 \fn QDataStream &QDataStream::operator<<(quint32 i) -
1004 \overload -
1005 -
1006 Writes an unsigned integer, \a i, to the stream as a 32-bit -
1007 unsigned integer (quint32). Returns a reference to the stream. -
1008*/ -
1009 -
1010/*! -
1011 Writes a boolean value, \a i, to the stream. Returns a reference -
1012 to the stream. -
1013*/ -
1014 -
1015QDataStream &QDataStream::operator<<(bool i) -
1016{ -
1017 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:1
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:1966
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1965
0-1966
1018 if (!dev->putChar(qint8(i)))
evaluated: !dev->putChar(qint8(i))
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:1964
1-1964
1019 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:1
1
1020 return *this;
executed: return *this;
Execution Count:1965
1965
1021} -
1022 -
1023/*! -
1024 \overload -
1025 -
1026 Writes a floating point number, \a f, to the stream using -
1027 the standard IEEE 754 format. Returns a reference to the stream. -
1028 -
1029 \sa setFloatingPointPrecision() -
1030*/ -
1031 -
1032QDataStream &QDataStream::operator<<(float f) -
1033{ -
1034 if (version() >= QDataStream::Qt_4_6
partially evaluated: version() >= QDataStream::Qt_4_6
TRUEFALSE
yes
Evaluation Count:14
no
Evaluation Count:0
0-14
1035 && floatingPointPrecision() == QDataStream::DoublePrecision) {
evaluated: floatingPointPrecision() == QDataStream::DoublePrecision
TRUEFALSE
yes
Evaluation Count:10
yes
Evaluation Count:4
4-10
1036 *this << double(f);
executed (the execution status of this line is deduced): *this << double(f);
-
1037 return *this;
executed: return *this;
Execution Count:10
10
1038 } -
1039 -
1040 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
partially evaluated: q_status != Ok
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1041 float g = f; // fixes float-on-stack problem
executed (the execution status of this line is deduced): float g = f;
-
1042 if (!noswap) {
partially evaluated: !noswap
TRUEFALSE
yes
Evaluation Count:4
no
Evaluation Count:0
0-4
1043 union {
executed (the execution status of this line is deduced): union {
-
1044 float val1;
executed (the execution status of this line is deduced): float val1;
-
1045 quint32 val2;
executed (the execution status of this line is deduced): quint32 val2;
-
1046 } x;
executed (the execution status of this line is deduced): } x;
-
1047 x.val1 = g;
executed (the execution status of this line is deduced): x.val1 = g;
-
1048 x.val2 = qbswap(x.val2);
executed (the execution status of this line is deduced): x.val2 = qbswap(x.val2);
-
1049 -
1050 if (dev->write((char *)&x.val2, sizeof(float)) != sizeof(float))
partially evaluated: dev->write((char *)&x.val2, sizeof(float)) != sizeof(float)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1051 q_status = WriteFailed;
never executed: q_status = WriteFailed;
0
1052 return *this;
executed: return *this;
Execution Count:4
4
1053 } -
1054 -
1055 if (dev->write((char *)&g, sizeof(float)) != sizeof(float))
never evaluated: dev->write((char *)&g, sizeof(float)) != sizeof(float)
0
1056 q_status = WriteFailed;
never executed: q_status = WriteFailed;
0
1057 return *this;
never executed: return *this;
0
1058} -
1059 -
1060 -
1061/*! -
1062 \overload -
1063 -
1064 Writes a floating point number, \a f, to the stream using -
1065 the standard IEEE 754 format. Returns a reference to the stream. -
1066 -
1067 \sa setFloatingPointPrecision() -
1068*/ -
1069 -
1070QDataStream &QDataStream::operator<<(double f) -
1071{ -
1072 if (version() >= QDataStream::Qt_4_6
evaluated: version() >= QDataStream::Qt_4_6
TRUEFALSE
yes
Evaluation Count:4728
yes
Evaluation Count:3607
3607-4728
1073 && floatingPointPrecision() == QDataStream::SinglePrecision) {
evaluated: floatingPointPrecision() == QDataStream::SinglePrecision
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:4727
1-4727
1074 *this << float(f);
executed (the execution status of this line is deduced): *this << float(f);
-
1075 return *this;
executed: return *this;
Execution Count:1
1
1076 } -
1077 -
1078 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
executed: return *this;
Execution Count:2
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8334
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8332
0-8334
1079 if (noswap) {
partially evaluated: noswap
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8332
0-8332
1080 if (dev->write((char *)&f, sizeof(double)) != sizeof(double))
never evaluated: dev->write((char *)&f, sizeof(double)) != sizeof(double)
0
1081 q_status = WriteFailed;
never executed: q_status = WriteFailed;
0
1082 } else {
never executed: }
0
1083 union {
executed (the execution status of this line is deduced): union {
-
1084 double val1;
executed (the execution status of this line is deduced): double val1;
-
1085 quint64 val2;
executed (the execution status of this line is deduced): quint64 val2;
-
1086 } x;
executed (the execution status of this line is deduced): } x;
-
1087 x.val1 = f;
executed (the execution status of this line is deduced): x.val1 = f;
-
1088 x.val2 = qbswap(x.val2);
executed (the execution status of this line is deduced): x.val2 = qbswap(x.val2);
-
1089 if (dev->write((char *)&x.val2, sizeof(double)) != sizeof(double))
evaluated: dev->write((char *)&x.val2, sizeof(double)) != sizeof(double)
TRUEFALSE
yes
Evaluation Count:2
yes
Evaluation Count:8330
2-8330
1090 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:2
2
1091 }
executed: }
Execution Count:8332
8332
1092 return *this;
executed: return *this;
Execution Count:8332
8332
1093} -
1094 -
1095 -
1096/*! -
1097 \overload -
1098 -
1099 Writes the '\\0'-terminated string \a s to the stream and returns a -
1100 reference to the stream. -
1101 -
1102 The string is serialized using writeBytes(). -
1103*/ -
1104 -
1105QDataStream &QDataStream::operator<<(const char *s) -
1106{ -
1107 if (!s) {
partially evaluated: !s
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:4
0-4
1108 *this << (quint32)0;
never executed (the execution status of this line is deduced): *this << (quint32)0;
-
1109 return *this;
never executed: return *this;
0
1110 } -
1111 uint len = qstrlen(s) + 1; // also write null terminator
executed (the execution status of this line is deduced): uint len = qstrlen(s) + 1;
-
1112 *this << (quint32)len; // write length specifier
executed (the execution status of this line is deduced): *this << (quint32)len;
-
1113 writeRawData(s, len);
executed (the execution status of this line is deduced): writeRawData(s, len);
-
1114 return *this;
executed: return *this;
Execution Count:4
4
1115} -
1116 -
1117 -
1118/*! -
1119 Writes the length specifier \a len and the buffer \a s to the -
1120 stream and returns a reference to the stream. -
1121 -
1122 The \a len is serialized as a quint32, followed by \a len bytes -
1123 from \a s. Note that the data is \e not encoded. -
1124 -
1125 \sa writeRawData(), readBytes() -
1126*/ -
1127 -
1128QDataStream &QDataStream::writeBytes(const char *s, uint len) -
1129{ -
1130 CHECK_STREAM_WRITE_PRECOND(*this)
never executed: return *this;
never executed: return *this;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15342
partially evaluated: q_status != Ok
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:15342
0-15342
1131 *this << (quint32)len; // write length specifier
executed (the execution status of this line is deduced): *this << (quint32)len;
-
1132 if (len)
evaluated: len
TRUEFALSE
yes
Evaluation Count:15121
yes
Evaluation Count:221
221-15121
1133 writeRawData(s, len);
executed: writeRawData(s, len);
Execution Count:15121
15121
1134 return *this;
executed: return *this;
Execution Count:15342
15342
1135} -
1136 -
1137 -
1138/*! -
1139 Writes \a len bytes from \a s to the stream. Returns the -
1140 number of bytes actually written, or -1 on error. -
1141 The data is \e not encoded. -
1142 -
1143 \sa writeBytes(), QIODevice::write(), readRawData() -
1144*/ -
1145 -
1146int QDataStream::writeRawData(const char *s, int len) -
1147{ -
1148 CHECK_STREAM_WRITE_PRECOND(-1)
never executed: return -1;
executed: return -1;
Execution Count:3
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:16514
evaluated: q_status != Ok
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:16511
0-16514
1149 int ret = dev->write(s, len);
executed (the execution status of this line is deduced): int ret = dev->write(s, len);
-
1150 if (ret != len)
evaluated: ret != len
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:16510
1-16510
1151 q_status = WriteFailed;
executed: q_status = WriteFailed;
Execution Count:1
1
1152 return ret;
executed: return ret;
Execution Count:16511
16511
1153} -
1154 -
1155/*! -
1156 \since 4.1 -
1157 -
1158 Skips \a len bytes from the device. Returns the number of bytes -
1159 actually skipped, or -1 on error. -
1160 -
1161 This is equivalent to calling readRawData() on a buffer of length -
1162 \a len and ignoring the buffer. -
1163 -
1164 \sa QIODevice::seek() -
1165*/ -
1166int QDataStream::skipRawData(int len) -
1167{ -
1168 CHECK_STREAM_PRECOND(-1)
never executed: return -1;
partially evaluated: !dev
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:6
0-6
1169 -
1170 if (dev->isSequential()) {
evaluated: dev->isSequential()
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:3
3
1171 char buf[4096];
executed (the execution status of this line is deduced): char buf[4096];
-
1172 int sumRead = 0;
executed (the execution status of this line is deduced): int sumRead = 0;
-
1173 -
1174 while (len > 0) {
evaluated: len > 0
TRUEFALSE
yes
Evaluation Count:9
yes
Evaluation Count:3
3-9
1175 int blockSize = qMin(len, (int)sizeof(buf));
executed (the execution status of this line is deduced): int blockSize = qMin(len, (int)sizeof(buf));
-
1176 int n = dev->read(buf, blockSize);
executed (the execution status of this line is deduced): int n = dev->read(buf, blockSize);
-
1177 if (n == -1)
partially evaluated: n == -1
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
1178 return -1;
never executed: return -1;
0
1179 if (n == 0)
partially evaluated: n == 0
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
1180 return sumRead;
never executed: return sumRead;
0
1181 -
1182 sumRead += n;
executed (the execution status of this line is deduced): sumRead += n;
-
1183 len -= blockSize;
executed (the execution status of this line is deduced): len -= blockSize;
-
1184 }
executed: }
Execution Count:9
9
1185 return sumRead;
executed: return sumRead;
Execution Count:3
3
1186 } else { -
1187 qint64 pos = dev->pos();
executed (the execution status of this line is deduced): qint64 pos = dev->pos();
-
1188 qint64 size = dev->size();
executed (the execution status of this line is deduced): qint64 size = dev->size();
-
1189 if (pos + len > size)
evaluated: pos + len > size
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:2
1-2
1190 len = size - pos;
executed: len = size - pos;
Execution Count:1
1
1191 if (!dev->seek(pos + len))
partially evaluated: !dev->seek(pos + len)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:3
0-3
1192 return -1;
never executed: return -1;
0
1193 return len;
executed: return len;
Execution Count:3
3
1194 } -
1195} -
1196 -
1197QT_END_NAMESPACE -
1198 -
1199#endif // QT_NO_DATASTREAM -
1200 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial