diff options
Diffstat (limited to 'src/corelib/io/qnoncontiguousbytedevice.cpp')
-rw-r--r-- | src/corelib/io/qnoncontiguousbytedevice.cpp | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index 87fa6f02bd..260fea7969 100644 --- a/src/corelib/io/qnoncontiguousbytedevice.cpp +++ b/src/corelib/io/qnoncontiguousbytedevice.cpp @@ -100,14 +100,18 @@ QNonContiguousByteDevice::~QNonContiguousByteDevice() } // FIXME we should scrap this whole implementation and instead change the ByteArrayImpl to be able to cope with sub-arrays? -QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice() +QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) + : QNonContiguousByteDevice(), + buffer(b), + byteArray(QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), + buffer->size() - buffer->pos())), + arrayImpl(new QNonContiguousByteDeviceByteArrayImpl(&byteArray)) { - buffer = b; - byteArray = QByteArray::fromRawData(buffer->buffer().constData() + buffer->pos(), buffer->size() - buffer->pos()); - arrayImpl = new QNonContiguousByteDeviceByteArrayImpl(&byteArray); arrayImpl->setParent(this); - connect(arrayImpl, SIGNAL(readyRead()), SIGNAL(readyRead())); - connect(arrayImpl, SIGNAL(readProgress(qint64,qint64)), SIGNAL(readProgress(qint64,qint64))); + connect(arrayImpl, &QNonContiguousByteDevice::readyRead, this, + &QNonContiguousByteDevice::readyRead); + connect(arrayImpl, &QNonContiguousByteDevice::readProgress, this, + &QNonContiguousByteDevice::readProgress); } QNonContiguousByteDeviceBufferImpl::~QNonContiguousByteDeviceBufferImpl() @@ -139,9 +143,9 @@ qint64 QNonContiguousByteDeviceBufferImpl::size() const return arrayImpl->size(); } -QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) : QNonContiguousByteDevice(), currentPosition(0) +QNonContiguousByteDeviceByteArrayImpl::QNonContiguousByteDeviceByteArrayImpl(QByteArray *ba) + : QNonContiguousByteDevice(), byteArray(ba), currentPosition(0) { - byteArray = ba; } QNonContiguousByteDeviceByteArrayImpl::~QNonContiguousByteDeviceByteArrayImpl() @@ -245,14 +249,19 @@ qint64 QNonContiguousByteDeviceRingBufferImpl::size() const QNonContiguousByteDeviceIoDeviceImpl::QNonContiguousByteDeviceIoDeviceImpl(QIODevice *d) : QNonContiguousByteDevice(), - currentReadBuffer(nullptr), currentReadBufferSize(16*1024), - currentReadBufferAmount(0), currentReadBufferPosition(0), totalAdvancements(0), - eof(false) + device(d), + currentReadBuffer(nullptr), + currentReadBufferSize(16 * 1024), + currentReadBufferAmount(0), + currentReadBufferPosition(0), + totalAdvancements(0), + eof(false), + initialPosition(d->pos()) { - device = d; - initialPosition = d->pos(); - connect(device, SIGNAL(readyRead()), this, SIGNAL(readyRead()), Qt::QueuedConnection); - connect(device, SIGNAL(readChannelFinished()), this, SIGNAL(readyRead()), Qt::QueuedConnection); + connect(device, &QIODevice::readyRead, this, + &QNonContiguousByteDevice::readyRead); + connect(device, &QIODevice::readChannelFinished, this, + &QNonContiguousByteDevice::readyRead); } QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() @@ -262,7 +271,7 @@ QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len) { - if (eof == true) { + if (eof) { len = -1; return nullptr; } @@ -278,7 +287,8 @@ const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLeng return currentReadBuffer->data() + currentReadBufferPosition; } - qint64 haveRead = device->read(currentReadBuffer->data(), qMin(maximumLength, currentReadBufferSize)); + qint64 haveRead = device->read(currentReadBuffer->data(), + qMin(maximumLength, currentReadBufferSize)); if ((haveRead == -1) || (haveRead == 0 && device->atEnd() && !device->isSequential())) { eof = true; @@ -312,7 +322,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) if (currentReadBufferPosition > currentReadBufferAmount) { qint64 i = currentReadBufferPosition - currentReadBufferAmount; while (i > 0) { - if (device->getChar(nullptr) == false) { + if (!device->getChar(nullptr)) { emit readProgress(totalAdvancements - i, size()); return false; // ### FIXME handle eof } @@ -328,7 +338,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const { - return eof == true; + return eof; } bool QNonContiguousByteDeviceIoDeviceImpl::reset() @@ -367,18 +377,16 @@ qint64 QNonContiguousByteDeviceIoDeviceImpl::pos() const return device->pos(); } -QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) : QIODevice((QObject*)nullptr) +QByteDeviceWrappingIoDevice::QByteDeviceWrappingIoDevice(QNonContiguousByteDevice *bd) + : QIODevice(nullptr), byteDevice(bd) { - byteDevice = bd; - connect(bd, SIGNAL(readyRead()), SIGNAL(readyRead())); + connect(bd, &QNonContiguousByteDevice::readyRead, this, &QIODevice::readyRead); open(ReadOnly); } QByteDeviceWrappingIoDevice::~QByteDeviceWrappingIoDevice() -{ - -} + = default; bool QByteDeviceWrappingIoDevice::isSequential() const { @@ -483,9 +491,10 @@ std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::creat \internal */ -QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer) +QNonContiguousByteDevice * +QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer) { - return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); + return new QNonContiguousByteDeviceRingBufferImpl(std::move(ringBuffer)); } /*! @@ -493,7 +502,8 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_pt \internal */ -std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer) { return std::make_shared<QNonContiguousByteDeviceRingBufferImpl>(std::move(ringBuffer)); } @@ -515,7 +525,8 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by \internal */ -std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) { return std::make_shared<QNonContiguousByteDeviceByteArrayImpl>(byteArray); } |