summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qnoncontiguousbytedevice.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qnoncontiguousbytedevice.cpp')
-rw-r--r--src/corelib/io/qnoncontiguousbytedevice.cpp109
1 files changed, 42 insertions, 67 deletions
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp
index 73075c532f..260fea7969 100644
--- a/src/corelib/io/qnoncontiguousbytedevice.cpp
+++ b/src/corelib/io/qnoncontiguousbytedevice.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qnoncontiguousbytedevice_p.h"
#include <qbuffer.h>
@@ -136,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()
@@ -175,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()
@@ -281,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()
@@ -298,7 +271,7 @@ QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl()
const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len)
{
- if (eof == true) {
+ if (eof) {
len = -1;
return nullptr;
}
@@ -314,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;
@@ -348,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
}
@@ -364,7 +338,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount)
bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const
{
- return eof == true;
+ return eof;
}
bool QNonContiguousByteDeviceIoDeviceImpl::reset()
@@ -403,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
{
@@ -519,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));
}
/*!
@@ -529,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));
}
@@ -551,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);
}