Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qnoncontiguousbytedevice.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0) | - | ||||||
4 | { | - | ||||||
5 | } | - | ||||||
6 | - | |||||||
7 | QNonContiguousByteDevice::~QNonContiguousByteDevice() | - | ||||||
8 | { | - | ||||||
9 | } | - | ||||||
10 | - | |||||||
11 | - | |||||||
12 | QNonContiguousByteDeviceBufferImpl::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 | - | |||||||
22 | QNonContiguousByteDeviceBufferImpl::~QNonContiguousByteDeviceBufferImpl() | - | ||||||
23 | { | - | ||||||
24 | } | - | ||||||
25 | - | |||||||
26 | const char* QNonContiguousByteDeviceBufferImpl::readPointer(qint64 maximumLength, qint64 &len) | - | ||||||
27 | { | - | ||||||
28 | return arrayImpl->readPointer(maximumLength, len); | - | ||||||
29 | } | - | ||||||
30 | - | |||||||
31 | bool QNonContiguousByteDeviceBufferImpl::advanceReadPointer(qint64 amount) | - | ||||||
32 | { | - | ||||||
33 | return arrayImpl->advanceReadPointer(amount); | - | ||||||
34 | } | - | ||||||
35 | - | |||||||
36 | bool QNonContiguousByteDeviceBufferImpl::atEnd() const | - | ||||||
37 | { | - | ||||||
38 | return executed 1051 times by 3 tests: arrayImpl->atEnd();return arrayImpl->atEnd(); Executed by:
executed 1051 times by 3 tests: return arrayImpl->atEnd(); Executed by:
| 1051 | ||||||
39 | } | - | ||||||
40 | - | |||||||
41 | bool QNonContiguousByteDeviceBufferImpl::reset() | - | ||||||
42 | { | - | ||||||
43 | return arrayImpl->reset(); | - | ||||||
44 | } | - | ||||||
45 | - | |||||||
46 | qint64 QNonContiguousByteDeviceBufferImpl::size() const | - | ||||||
47 | { | - | ||||||
48 | return executed 1100 times by 3 tests: arrayImpl->size();return arrayImpl->size(); Executed by:
executed 1100 times by 3 tests: return arrayImpl->size(); Executed by:
| 1100 | ||||||
49 | } | - | ||||||
50 | - | |||||||
51 | QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0) | - | ||||||
52 | { | - | ||||||
53 | byteArray = ba; | - | ||||||
54 | } | - | ||||||
55 | - | |||||||
56 | QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl() | - | ||||||
57 | { | - | ||||||
58 | } | - | ||||||
59 | - | |||||||
60 | const 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 | - | |||||||
75 | bool QNonContiguousByteDeviceByteArrayImpl::advanceReadPointer(qint64 amount) | - | ||||||
76 | { | - | ||||||
77 | currentPosition += amount; | - | ||||||
78 | readProgress(currentPosition, size()); | - | ||||||
79 | return true; | - | ||||||
80 | } | - | ||||||
81 | - | |||||||
82 | bool QNonContiguousByteDeviceByteArrayImpl::atEnd() const | - | ||||||
83 | { | - | ||||||
84 | return executed 2361 times by 4 tests: currentPosition >= size();return currentPosition >= size(); Executed by:
executed 2361 times by 4 tests: return currentPosition >= size(); Executed by:
| 2361 | ||||||
85 | } | - | ||||||
86 | - | |||||||
87 | bool QNonContiguousByteDeviceByteArrayImpl::reset() | - | ||||||
88 | { | - | ||||||
89 | currentPosition = 0; | - | ||||||
90 | return true; | - | ||||||
91 | } | - | ||||||
92 | - | |||||||
93 | qint64 QNonContiguousByteDeviceByteArrayImpl::size() const | - | ||||||
94 | { | - | ||||||
95 | return executed 6023 times by 4 tests: byteArray->size();return byteArray->size(); Executed by:
executed 6023 times by 4 tests: return byteArray->size(); Executed by:
| 6023 | ||||||
96 | } | - | ||||||
97 | - | |||||||
98 | qint64 QNonContiguousByteDeviceByteArrayImpl::pos() const | - | ||||||
99 | { | - | ||||||
100 | return executed 4 times by 1 test: currentPosition;return currentPosition; Executed by:
executed 4 times by 1 test: return currentPosition; Executed by:
| 4 | ||||||
101 | } | - | ||||||
102 | - | |||||||
103 | QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb) | - | ||||||
104 | : QNonContiguousByteDevice(), currentPosition(0) | - | ||||||
105 | { | - | ||||||
106 | ringBuffer = rb; | - | ||||||
107 | } | - | ||||||
108 | - | |||||||
109 | QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl() | - | ||||||
110 | { | - | ||||||
111 | } | - | ||||||
112 | - | |||||||
113 | const 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 | - | |||||||
128 | bool QNonContiguousByteDeviceRingBufferImpl::advanceReadPointer(qint64 amount) | - | ||||||
129 | { | - | ||||||
130 | currentPosition += amount; | - | ||||||
131 | readProgress(currentPosition, size()); | - | ||||||
132 | return true; | - | ||||||
133 | } | - | ||||||
134 | - | |||||||
135 | bool QNonContiguousByteDeviceRingBufferImpl::atEnd() const | - | ||||||
136 | { | - | ||||||
137 | return executed 1126 times by 1 test: currentPosition >= size();return currentPosition >= size(); Executed by:
executed 1126 times by 1 test: return currentPosition >= size(); Executed by:
| 1126 | ||||||
138 | } | - | ||||||
139 | - | |||||||
140 | qint64 QNonContiguousByteDeviceRingBufferImpl::pos() const | - | ||||||
141 | { | - | ||||||
142 | return executed 716 times by 1 test: currentPosition;return currentPosition; Executed by:
executed 716 times by 1 test: return currentPosition; Executed by:
| 716 | ||||||
143 | } | - | ||||||
144 | - | |||||||
145 | bool QNonContiguousByteDeviceRingBufferImpl::reset() | - | ||||||
146 | { | - | ||||||
147 | currentPosition = 0; | - | ||||||
148 | return true; | - | ||||||
149 | } | - | ||||||
150 | - | |||||||
151 | qint64 QNonContiguousByteDeviceRingBufferImpl::size() const | - | ||||||
152 | { | - | ||||||
153 | return executed 2293 times by 1 test: ringBuffer->size();return ringBuffer->size(); Executed by:
executed 2293 times by 1 test: return ringBuffer->size(); Executed by:
| 2293 | ||||||
154 | } | - | ||||||
155 | - | |||||||
156 | QNonContiguousByteDeviceIoDeviceImpl::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 | - | |||||||
168 | QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() | - | ||||||
169 | { | - | ||||||
170 | delete currentReadBuffer; | - | ||||||
171 | } | - | ||||||
172 | - | |||||||
173 | const 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 | - | |||||||
209 | bool 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 | - | |||||||
240 | bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const | - | ||||||
241 | { | - | ||||||
242 | return executed 1580 times by 2 tests: eof == true;return eof == true; Executed by:
executed 1580 times by 2 tests: return eof == true; Executed by:
| 1580 | ||||||
243 | } | - | ||||||
244 | - | |||||||
245 | bool 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 | - | |||||||
263 | qint64 QNonContiguousByteDeviceIoDeviceImpl::size() const | - | ||||||
264 | { | - | ||||||
265 | - | |||||||
266 | - | |||||||
267 | if (device->isSequential()
| 607-4707 | ||||||
268 | return executed 607 times by 1 test: -1;return -1; Executed by:
executed 607 times by 1 test: return -1; Executed by:
| 607 | ||||||
269 | - | |||||||
270 | return executed 4707 times by 2 tests: device->size() - initialPosition;return device->size() - initialPosition; Executed by:
executed 4707 times by 2 tests: return device->size() - initialPosition; Executed by:
| 4707 | ||||||
271 | } | - | ||||||
272 | - | |||||||
273 | qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const | - | ||||||
274 | { | - | ||||||
275 | if (device->isSequential()
| 0 | ||||||
276 | return never executed: -1;return -1; never executed: return -1; | 0 | ||||||
277 | - | |||||||
278 | return never executed: device->pos();return device->pos(); never executed: return device->pos(); | 0 | ||||||
279 | } | - | ||||||
280 | - | |||||||
281 | QByteDeviceWrappingIoDevice::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 | - | |||||||
289 | QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice() | - | ||||||
290 | { | - | ||||||
291 | - | |||||||
292 | } | - | ||||||
293 | - | |||||||
294 | bool QByteDeviceWrappingIoDevice::isSequential() const | - | ||||||
295 | { | - | ||||||
296 | return (byteDevice->size() == -1); | - | ||||||
297 | } | - | ||||||
298 | - | |||||||
299 | bool QByteDeviceWrappingIoDevice::atEnd() const | - | ||||||
300 | { | - | ||||||
301 | return byteDevice->atEnd(); | - | ||||||
302 | } | - | ||||||
303 | - | |||||||
304 | bool QByteDeviceWrappingIoDevice::reset() | - | ||||||
305 | { | - | ||||||
306 | return byteDevice->reset(); | - | ||||||
307 | } | - | ||||||
308 | - | |||||||
309 | qint64 QByteDeviceWrappingIoDevice::size() const | - | ||||||
310 | { | - | ||||||
311 | if (isSequential()) | - | ||||||
312 | return 0; | - | ||||||
313 | - | |||||||
314 | return byteDevice->size(); | - | ||||||
315 | } | - | ||||||
316 | - | |||||||
317 | - | |||||||
318 | qint64 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 | - | |||||||
330 | qint64 QByteDeviceWrappingIoDevice::writeData( const char* data, qint64 maxSize) | - | ||||||
331 | { | - | ||||||
332 | (void)data;; | - | ||||||
333 | (void)maxSize;; | - | ||||||
334 | return -1; | - | ||||||
335 | } | - | ||||||
336 | QNonContiguousByteDevice* 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 | - | |||||||
356 | QSharedPointer<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 | } | - | ||||||
368 | QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer) | - | ||||||
369 | { | - | ||||||
370 | return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); | - | ||||||
371 | } | - | ||||||
372 | - | |||||||
373 | - | |||||||
374 | - | |||||||
375 | - | |||||||
376 | - | |||||||
377 | - | |||||||
378 | QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer) | - | ||||||
379 | { | - | ||||||
380 | return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer)); | - | ||||||
381 | } | - | ||||||
382 | QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *byteArray) | - | ||||||
383 | { | - | ||||||
384 | return new QNonContiguousByteDeviceByteArrayImpl(byteArray); | - | ||||||
385 | } | - | ||||||
386 | - | |||||||
387 | - | |||||||
388 | - | |||||||
389 | - | |||||||
390 | - | |||||||
391 | - | |||||||
392 | QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) | - | ||||||
393 | { | - | ||||||
394 | return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray); | - | ||||||
395 | } | - | ||||||
396 | QIODevice* QNonContiguousByteDeviceFactory::wrap(QNonContiguousByteDevice* byteDevice) | - | ||||||
397 | { | - | ||||||
398 | - | |||||||
399 | - | |||||||
400 | - | |||||||
401 | - | |||||||
402 | - | |||||||
403 | return new QByteDeviceWrappingIoDevice(byteDevice); | - | ||||||
404 | } | - | ||||||
405 | - | |||||||
406 | - | |||||||
Switch to Source code | Preprocessed file |