qnoncontiguousbytedevice.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qnoncontiguousbytedevice.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0)-
4{-
5}-
6-
7QNonContiguousByteDevice::~QNonContiguousByteDevice()-
8{-
9}-
10-
11-
12QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice()-
13{-
14 buffer = b;-
15 byteArray = QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), buffer->size() - buffer->pos());-
16 arrayImpl = new QNonContiguousByteDeviceByteArrayImpl(&byteArray);-
17 arrayImpl->setParent(this);-
18 connect(arrayImpl, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "139""145"), qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "139""145"));-
19 connect(arrayImpl, qFlagLocation("2""readProgress(qint64,qint64)" "\0" __FILE__ ":" "140""146"), qFlagLocation("2""readProgress(qint64,qint64)" "\0" __FILE__ ":" "140""146"));-
20}-
21-
22QNonContiguousByteDeviceBufferImpl::~QNonContiguousByteDeviceBufferImpl()-
23{-
24}-
25-
26const char* QNonContiguousByteDeviceBufferImpl::readPointer(qint64 maximumLength, qint64 &len)-
27{-
28 return arrayImpl->readPointer(maximumLength, len);-
29}-
30-
31bool QNonContiguousByteDeviceBufferImpl::advanceReadPointer(qint64 amount)-
32{-
33 return arrayImpl->advanceReadPointer(amount);-
34}-
35-
36bool QNonContiguousByteDeviceBufferImpl::atEnd() const-
37{-
38 return
executed 1051 times by 3 tests: return arrayImpl->atEnd();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
arrayImpl->atEnd();
executed 1051 times by 3 tests: return arrayImpl->atEnd();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1051
39}-
40-
41bool QNonContiguousByteDeviceBufferImpl::reset()-
42{-
43 return arrayImpl->reset();-
44}-
45-
46qint64 QNonContiguousByteDeviceBufferImpl::size() const-
47{-
48 return
executed 1100 times by 3 tests: return arrayImpl->size();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
arrayImpl->size();
executed 1100 times by 3 tests: return arrayImpl->size();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
1100
49}-
50-
51QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0)-
52{-
53 byteArray = ba;-
54}-
55-
56QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl()-
57{-
58}-
59-
60const char* QNonContiguousByteDeviceByteArrayImpl::readPointer(qint64 maximumLength, qint64 &len)-
61{-
62 if (atEnd()) {-
63 len = -1;-
64 return 0;-
65 }-
66-
67 if (maximumLength != -1)-
68 len = qMin(maximumLength, size() - currentPosition);-
69 else-
70 len = size() - currentPosition;-
71-
72 return byteArray->constData() + currentPosition;-
73}-
74-
75bool QNonContiguousByteDeviceByteArrayImpl::advanceReadPointer(qint64 amount)-
76{-
77 currentPosition += amount;-
78 readProgress(currentPosition, size());-
79 return true;-
80}-
81-
82bool QNonContiguousByteDeviceByteArrayImpl::atEnd() const-
83{-
84 return
executed 2361 times by 4 tests: return currentPosition >= size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
currentPosition >= size();
executed 2361 times by 4 tests: return currentPosition >= size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
2361
85}-
86-
87bool QNonContiguousByteDeviceByteArrayImpl::reset()-
88{-
89 currentPosition = 0;-
90 return true;-
91}-
92-
93qint64 QNonContiguousByteDeviceByteArrayImpl::size() const-
94{-
95 return
executed 6023 times by 4 tests: return byteArray->size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
byteArray->size();
executed 6023 times by 4 tests: return byteArray->size();
Executed by:
  • tst_QHttpNetworkConnection
  • tst_QNetworkReply
  • tst_QXmlInputSource
  • tst_Spdy
6023
96}-
97-
98qint64 QNonContiguousByteDeviceByteArrayImpl::pos() const-
99{-
100 return
executed 4 times by 1 test: return currentPosition;
Executed by:
  • tst_QHttpNetworkConnection
currentPosition;
executed 4 times by 1 test: return currentPosition;
Executed by:
  • tst_QHttpNetworkConnection
4
101}-
102-
103QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb)-
104 : QNonContiguousByteDevice(), currentPosition(0)-
105{-
106 ringBuffer = rb;-
107}-
108-
109QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl()-
110{-
111}-
112-
113const char* QNonContiguousByteDeviceRingBufferImpl::readPointer(qint64 maximumLength, qint64 &len)-
114{-
115 if (atEnd()) {-
116 len = -1;-
117 return 0;-
118 }-
119-
120 const char *returnValue = ringBuffer->readPointerAtPosition(currentPosition, len);-
121-
122 if (maximumLength != -1)-
123 len = qMin(len, maximumLength);-
124-
125 return returnValue;-
126}-
127-
128bool QNonContiguousByteDeviceRingBufferImpl::advanceReadPointer(qint64 amount)-
129{-
130 currentPosition += amount;-
131 readProgress(currentPosition, size());-
132 return true;-
133}-
134-
135bool QNonContiguousByteDeviceRingBufferImpl::atEnd() const-
136{-
137 return
executed 1126 times by 1 test: return currentPosition >= size();
Executed by:
  • tst_QNetworkReply
currentPosition >= size();
executed 1126 times by 1 test: return currentPosition >= size();
Executed by:
  • tst_QNetworkReply
1126
138}-
139-
140qint64 QNonContiguousByteDeviceRingBufferImpl::pos() const-
141{-
142 return
executed 716 times by 1 test: return currentPosition;
Executed by:
  • tst_QNetworkReply
currentPosition;
executed 716 times by 1 test: return currentPosition;
Executed by:
  • tst_QNetworkReply
716
143}-
144-
145bool QNonContiguousByteDeviceRingBufferImpl::reset()-
146{-
147 currentPosition = 0;-
148 return true;-
149}-
150-
151qint64 QNonContiguousByteDeviceRingBufferImpl::size() const-
152{-
153 return
executed 2293 times by 1 test: return ringBuffer->size();
Executed by:
  • tst_QNetworkReply
ringBuffer->size();
executed 2293 times by 1 test: return ringBuffer->size();
Executed by:
  • tst_QNetworkReply
2293
154}-
155-
156QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d)-
157 : QNonContiguousByteDevice(),-
158 currentReadBuffer(0), currentReadBufferSize(16*1024),-
159 currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0),-
160 eof(false)-
161{-
162 device = d;-
163 initialPosition = d->pos();-
164 connect(device, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "285""291"), this, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "285""291"), Qt::QueuedConnection);-
165 connect(device, qFlagLocation("2""readChannelFinished()" "\0" __FILE__ ":" "286""292"), this, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "286""292"), Qt::QueuedConnection);-
166}-
167-
168QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl()-
169{-
170 delete currentReadBuffer;-
171}-
172-
173const char* QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len)-
174{-
175 if (eof == true) {-
176 len = -1;-
177 return 0;-
178 }-
179-
180 if (currentReadBuffer == 0)-
181 currentReadBuffer = new QByteArray(currentReadBufferSize, '\0');-
182-
183 if (maximumLength == -1)-
184 maximumLength = currentReadBufferSize;-
185-
186 if (currentReadBufferAmount - currentReadBufferPosition > 0) {-
187 len = currentReadBufferAmount - currentReadBufferPosition;-
188 return currentReadBuffer->data() + currentReadBufferPosition;-
189 }-
190-
191 qint64 haveRead = device->read(currentReadBuffer->data(), qMin(maximumLength, currentReadBufferSize));-
192-
193 if ((haveRead == -1) || (haveRead == 0 && device->atEnd() && !device->isSequential())) {-
194 eof = true;-
195 len = -1;-
196-
197 if (size() == -1)-
198 readProgress(totalAdvancements, totalAdvancements);-
199 return 0;-
200 }-
201-
202 currentReadBufferAmount = haveRead;-
203 currentReadBufferPosition = 0;-
204-
205 len = haveRead;-
206 return currentReadBuffer->data();-
207}-
208-
209bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount)-
210{-
211 totalAdvancements += amount;-
212-
213-
214 currentReadBufferPosition += amount;-
215-
216 if (size() == -1)-
217 readProgress(totalAdvancements, totalAdvancements);-
218 else-
219 readProgress(totalAdvancements, size());-
220-
221-
222 if (currentReadBufferPosition > currentReadBufferAmount) {-
223 qint64 i = currentReadBufferPosition - currentReadBufferAmount;-
224 while (i > 0) {-
225 if (device->getChar(0) == false) {-
226 readProgress(totalAdvancements - i, size());-
227 return false;-
228 }-
229 i--;-
230 }-
231-
232 currentReadBufferPosition = 0;-
233 currentReadBufferAmount = 0;-
234 }-
235-
236-
237 return true;-
238}-
239-
240bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const-
241{-
242 return
executed 1580 times by 2 tests: return eof == true;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
eof == true;
executed 1580 times by 2 tests: return eof == true;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
1580
243}-
244-
245bool QNonContiguousByteDeviceIoDeviceImpl::reset()-
246{-
247 bool reset = (initialPosition == 0) ? device->reset() : device->seek(initialPosition);-
248 if (reset) {-
249 eof = false;-
250 totalAdvancements = 0;-
251 if (currentReadBuffer) {-
252 delete currentReadBuffer;-
253 currentReadBuffer = 0;-
254 }-
255 currentReadBufferAmount = 0;-
256 currentReadBufferPosition = 0;-
257 return true;-
258 }-
259-
260 return false;-
261}-
262-
263qint64 QNonContiguousByteDeviceIoDeviceImpl::size() const-
264{-
265-
266-
267 if (device->isSequential()
device->isSequential()Description
TRUEevaluated 607 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 4707 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_Spdy
)
607-4707
268 return
executed 607 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
-1;
executed 607 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
607
269-
270 return
executed 4707 times by 2 tests: return device->size() - initialPosition;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
device->size() - initialPosition;
executed 4707 times by 2 tests: return device->size() - initialPosition;
Executed by:
  • tst_QNetworkReply
  • tst_Spdy
4707
271}-
272-
273qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const-
274{-
275 if (device->isSequential()
device->isSequential()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
276 return
never executed: return -1;
-1;
never executed: return -1;
0
277-
278 return
never executed: return device->pos();
device->pos();
never executed: return device->pos();
0
279}-
280-
281QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)0)-
282{-
283 byteDevice = bd;-
284 connect(bd, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "405""411"), qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "405""411"));-
285-
286 open(ReadOnly);-
287}-
288-
289QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice()-
290{-
291-
292}-
293-
294bool QByteDeviceWrappingIoDevice::isSequential() const-
295{-
296 return (byteDevice->size() == -1);-
297}-
298-
299bool QByteDeviceWrappingIoDevice::atEnd() const-
300{-
301 return byteDevice->atEnd();-
302}-
303-
304bool QByteDeviceWrappingIoDevice::reset()-
305{-
306 return byteDevice->reset();-
307}-
308-
309qint64 QByteDeviceWrappingIoDevice::size() const-
310{-
311 if (isSequential())-
312 return 0;-
313-
314 return byteDevice->size();-
315}-
316-
317-
318qint64 QByteDeviceWrappingIoDevice::readData( char * data, qint64 maxSize)-
319{-
320 qint64 len;-
321 const char *readPointer = byteDevice->readPointer(maxSize, len);-
322 if (len == -1)-
323 return -1;-
324-
325 memcpy(data, readPointer, len);-
326 byteDevice->advanceReadPointer(len);-
327 return len;-
328}-
329-
330qint64 QByteDeviceWrappingIoDevice::writeData( const char* data, qint64 maxSize)-
331{-
332 (void)data;;-
333 (void)maxSize;;-
334 return -1;-
335}-
336QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QIODevice *device)-
337{-
338-
339 if (QBuffer* buffer = qobject_cast<QBuffer*>(device)) {-
340 return new QNonContiguousByteDeviceBufferImpl(buffer);-
341 }-
342-
343-
344-
345-
346-
347 return new QNonContiguousByteDeviceIoDeviceImpl(device);-
348}-
349-
350-
351-
352-
353-
354-
355-
356QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device)-
357{-
358-
359 if (QBuffer *buffer = qobject_cast<QBuffer*>(device))-
360 return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer);-
361-
362-
363-
364-
365-
366 return QSharedPointer<QNonContiguousByteDeviceIoDeviceImpl>::create(device);-
367}-
368QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer)-
369{-
370 return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer);-
371}-
372-
373-
374-
375-
376-
377-
378QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer)-
379{-
380 return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer));-
381}-
382QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray)-
383{-
384 return new QNonContiguousByteDeviceByteArrayImpl(byteArray);-
385}-
386-
387-
388-
389-
390-
391-
392QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray)-
393{-
394 return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray);-
395}-
396QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice)-
397{-
398-
399-
400-
401-
402-
403 return new QByteDeviceWrappingIoDevice(byteDevice);-
404}-
405-
406-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9