diff options
author | David Faure <faure@kde.org> | 2012-02-26 10:05:39 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-06 12:09:57 +0100 |
commit | dc75c20397e7322ba87578e766e0cd86ece90f93 (patch) | |
tree | 1fd15d53a083f2386ae2608cd22a960af7d6c4d8 /src/corelib/io/qfiledevice_p.h | |
parent | d51abed57a8f677a0d4eac57fd3f16bd4662190a (diff) |
Split up base class QFileDevice for open-file operations (read/write)
This will be used later on as a base class for QTemporaryFile and
QSaveFile.
Change-Id: Ic2e1d232f95dc29b8e2f75e24a881ab459d3f037
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'src/corelib/io/qfiledevice_p.h')
-rw-r--r-- | src/corelib/io/qfiledevice_p.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/corelib/io/qfiledevice_p.h b/src/corelib/io/qfiledevice_p.h new file mode 100644 index 0000000000..2550cd73a2 --- /dev/null +++ b/src/corelib/io/qfiledevice_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QFILEDEVICE_P_H +#define QFILEDEVICE_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include "private/qiodevice_p.h" +#include "private/qringbuffer_p.h" + +QT_BEGIN_NAMESPACE + +class QAbstractFileEngine; +class QFSFileEngine; + +class QFileDevicePrivate : public QIODevicePrivate +{ + Q_DECLARE_PUBLIC(QFileDevice) +protected: + QFileDevicePrivate(); + ~QFileDevicePrivate(); + + virtual QAbstractFileEngine *engine() const; + + QFileDevice::FileHandleFlags handleFlags; + + mutable QAbstractFileEngine *fileEngine; + bool lastWasWrite; + QRingBuffer writeBuffer; + inline bool ensureFlushed() const; + + bool putCharHelper(char c); + + QFileDevice::FileError error; + void setError(QFileDevice::FileError err); + void setError(QFileDevice::FileError err, const QString &errorString); + void setError(QFileDevice::FileError err, int errNum); + + mutable qint64 cachedSize; +}; + +inline bool QFileDevicePrivate::ensureFlushed() const +{ + // This function ensures that the write buffer has been flushed (const + // because certain const functions need to call it. + if (lastWasWrite) { + const_cast<QFileDevicePrivate *>(this)->lastWasWrite = false; + if (!const_cast<QFileDevice *>(q_func())->flush()) + return false; + } + return true; +} + +QT_END_NAMESPACE + +#endif // QFILEDEVICE_P_H |