diff options
Diffstat (limited to 'src/corelib/io/qnoncontiguousbytedevice.cpp')
-rw-r--r-- | src/corelib/io/qnoncontiguousbytedevice.cpp | 130 |
1 files changed, 52 insertions, 78 deletions
diff --git a/src/corelib/io/qnoncontiguousbytedevice.cpp b/src/corelib/io/qnoncontiguousbytedevice.cpp index cf2da0c896..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() @@ -227,10 +195,9 @@ qint64 QNonContiguousByteDeviceByteArrayImpl::pos() const return currentPosition; } -QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(QSharedPointer<QRingBuffer> rb) - : QNonContiguousByteDevice(), currentPosition(0) +QNonContiguousByteDeviceRingBufferImpl::QNonContiguousByteDeviceRingBufferImpl(std::shared_ptr<QRingBuffer> rb) + : QNonContiguousByteDevice(), ringBuffer(std::move(rb)) { - ringBuffer = rb; } QNonContiguousByteDeviceRingBufferImpl::~QNonContiguousByteDeviceRingBufferImpl() @@ -282,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() @@ -299,7 +271,7 @@ QNonContiguousByteDeviceIoDeviceImpl::~QNonContiguousByteDeviceIoDeviceImpl() const char *QNonContiguousByteDeviceIoDeviceImpl::readPointer(qint64 maximumLength, qint64 &len) { - if (eof == true) { + if (eof) { len = -1; return nullptr; } @@ -315,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; @@ -349,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 } @@ -365,7 +338,7 @@ bool QNonContiguousByteDeviceIoDeviceImpl::advanceReadPointer(qint64 amount) bool QNonContiguousByteDeviceIoDeviceImpl::atEnd() const { - return eof == true; + return eof; } bool QNonContiguousByteDeviceIoDeviceImpl::reset() @@ -404,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 { @@ -495,44 +466,46 @@ QNonContiguousByteDevice *QNonContiguousByteDeviceFactory::create(QIODevice *dev } /*! - Create a QNonContiguousByteDevice out of a QIODevice, return it in a QSharedPointer. + Create a QNonContiguousByteDevice out of a QIODevice, return it in a std::shared_ptr. For QFile, QBuffer and all other QIODevice, sequential or not. \internal */ -QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device) +std::shared_ptr<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QIODevice *device) { // shortcut if it is a QBuffer if (QBuffer *buffer = qobject_cast<QBuffer*>(device)) - return QSharedPointer<QNonContiguousByteDeviceBufferImpl>::create(buffer); + return std::make_shared<QNonContiguousByteDeviceBufferImpl>(buffer); // ### FIXME special case if device is a QFile that supports map() // then we can actually deal with the file without using read/peek // generic QIODevice - return QSharedPointer<QNonContiguousByteDeviceIoDeviceImpl>::create(device); // FIXME + return std::make_shared<QNonContiguousByteDeviceIoDeviceImpl>(device); // FIXME } /*! - \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer) + \fn static QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer) Create a QNonContiguousByteDevice out of a QRingBuffer. \internal */ -QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QSharedPointer<QRingBuffer> ringBuffer) +QNonContiguousByteDevice * +QNonContiguousByteDeviceFactory::create(std::shared_ptr<QRingBuffer> ringBuffer) { - return new QNonContiguousByteDeviceRingBufferImpl(ringBuffer); + return new QNonContiguousByteDeviceRingBufferImpl(std::move(ringBuffer)); } /*! - Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a QSharedPointer. + Create a QNonContiguousByteDevice out of a QRingBuffer, return it in a std::shared_ptr. \internal */ -QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QSharedPointer<QRingBuffer> ringBuffer) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(std::shared_ptr<QRingBuffer> ringBuffer) { - return QSharedPointer<QNonContiguousByteDeviceRingBufferImpl>::create(std::move(ringBuffer)); + return std::make_shared<QNonContiguousByteDeviceRingBufferImpl>(std::move(ringBuffer)); } /*! @@ -552,9 +525,10 @@ QNonContiguousByteDevice* QNonContiguousByteDeviceFactory::create(QByteArray *by \internal */ -QSharedPointer<QNonContiguousByteDevice> QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) +std::shared_ptr<QNonContiguousByteDevice> +QNonContiguousByteDeviceFactory::createShared(QByteArray *byteArray) { - return QSharedPointer<QNonContiguousByteDeviceByteArrayImpl>::create(byteArray); + return std::make_shared<QNonContiguousByteDeviceByteArrayImpl>(byteArray); } /*! |