Commit dc75c203 authored by David Faure's avatar David Faure Committed by Qt by Nokia
Browse files

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: default avatarOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Reviewed-by: default avatarLars Knoll <lars.knoll@nokia.com>
parent d51abed5
dev 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 6.0 6.0.0 6.1 6.1.0 6.1.1 6.1.2 6.1.3 6.2 6.2.0 6.2.1 6.2.2 old/5.0 old/5.1 old/5.2 wip/cmake wip/highdpi wip/lite wip/mir wip/nacl wip/network-test-server wip/remac wip/tizen wip/webassembly v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1 v5.3.2 v5.3.1 v5.3.0 v5.3.0-rc1 v5.3.0-beta1 v5.3.0-alpha1 v5.2.1 v5.2.0 v5.2.0-rc1 v5.2.0-beta1 v5.2.0-alpha1 v5.1.1 v5.1.0 v5.1.0-rc2 v5.1.0-rc1 v5.1.0-beta1 v5.1.0-alpha1 v5.0.2 v5.0.1 v5.0.0 v5.0.0-rc2 v5.0.0-rc1 v5.0.0-beta2 v5.0.0-beta1
No related merge requests found
Showing with 1026 additions and 696 deletions
......@@ -15,7 +15,7 @@ OBJS=project.o property.o main.o makefile.o unixmake2.o unixmake.o \
#qt code
QOBJS=qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o \
qbytearray.o qbytearraymatcher.o qdatastream.o qbuffer.o qlist.o qfile.o \
qbytearray.o qbytearraymatcher.o qdatastream.o qbuffer.o qlist.o qfiledevice.o qfile.o \
qfilesystementry.o qfilesystemengine_unix.o qfilesystemengine.o qfilesystemiterator_unix.o \
qfsfileengine_unix.o qfsfileengine.o \
qfsfileengine_iterator.o qregexp.o qvector.o qbitarray.o qdir.o qdiriterator.o quuid.o qhash.o \
......@@ -37,6 +37,7 @@ DEPEND_SRC=project.cpp property.cpp meta.cpp main.cpp generators/makefile.cpp ge
generators/integrity/gbuild.cpp \
$(SOURCE_PATH)/src/corelib/codecs/qtextcodec.cpp $(SOURCE_PATH)/src/corelib/codecs/qutfcodec.cpp \
$(SOURCE_PATH)/src/corelib/tools/qstring.cpp $(SOURCE_PATH)/src/corelib/io/qfile.cpp \
$(SOURCE_PATH)/src/corelib/io/qfiledevice.cpp \
$(SOURCE_PATH)/src/corelib/io/qtextstream.cpp $(SOURCE_PATH)/src/corelib/io/qiodevice.cpp \
$(SOURCE_PATH)/src/corelib/global/qmalloc.cpp \
$(SOURCE_PATH)/src/corelib/global/qglobal.cpp $(SOURCE_PATH)/src/corelib/tools/qregexp.cpp \
......@@ -176,6 +177,9 @@ qlist.o: $(SOURCE_PATH)/src/corelib/tools/qlist.cpp
qfile.o: $(SOURCE_PATH)/src/corelib/io/qfile.cpp
$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/io/qfile.cpp
qfiledevice.o: $(SOURCE_PATH)/src/corelib/io/qfiledevice.cpp
$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/io/qfiledevice.cpp
qfilesystementry.o: $(SOURCE_PATH)/src/corelib/io/qfilesystementry.cpp
$(CXX) -c -o $@ $(CXXFLAGS) $(SOURCE_PATH)/src/corelib/io/qfilesystementry.cpp
......
......@@ -82,6 +82,7 @@ QTOBJS= \
qdatetime.obj \
qdir.obj \
qdiriterator.obj \
qfiledevice.obj \
qfile.obj \
qtemporaryfile.obj \
qabstractfileengine.obj \
......
......@@ -84,6 +84,7 @@ QTOBJS= \
qdatetime.o \
qdir.o \
qdiriterator.o \
qfiledevice.o \
qfile.o \
qtemporaryfile.o \
qfileinfo.o \
......
......@@ -42,6 +42,7 @@ bootstrap { #Qt code
qdatetime.cpp \
qdir.cpp \
qdiriterator.cpp \
qfiledevice.cpp \
qfile.cpp \
qabstractfileengine.cpp \
qfileinfo.cpp \
......
......@@ -11,6 +11,8 @@ HEADERS += \
io/qdir_p.h \
io/qdiriterator.h \
io/qfile.h \
io/qfiledevice.h \
io/qfiledevice_p.h \
io/qfileinfo.h \
io/qfileinfo_p.h \
io/qiodevice.h \
......@@ -49,6 +51,7 @@ SOURCES += \
io/qdir.cpp \
io/qdiriterator.cpp \
io/qfile.cpp \
io/qfiledevice.cpp \
io/qfileinfo.cpp \
io/qiodevice.cpp \
io/qnoncontiguousbytedevice.cpp \
......
This diff is collapsed.
......@@ -42,7 +42,7 @@
#ifndef QFILE_H
#define QFILE_H
#include <QtCore/qiodevice.h>
#include <QtCore/qfiledevice.h>
#include <QtCore/qstring.h>
#include <stdio.h>
......@@ -57,7 +57,7 @@ QT_BEGIN_NAMESPACE
class QTemporaryFile;
class QFilePrivate;
class Q_CORE_EXPORT QFile : public QIODevice
class Q_CORE_EXPORT QFile : public QFileDevice
{
#ifndef QT_NO_QOBJECT
Q_OBJECT
......@@ -65,39 +65,6 @@ class Q_CORE_EXPORT QFile : public QIODevice
Q_DECLARE_PRIVATE(QFile)
public:
enum FileError {
NoError = 0,
ReadError = 1,
WriteError = 2,
FatalError = 3,
ResourceError = 4,
OpenError = 5,
AbortError = 6,
TimeOutError = 7,
UnspecifiedError = 8,
RemoveError = 9,
RenameError = 10,
PositionError = 11,
ResizeError = 12,
PermissionsError = 13,
CopyError = 14
};
enum Permission {
ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
};
Q_DECLARE_FLAGS(Permissions, Permission)
enum FileHandleFlag {
AutoCloseHandle = 0x0001,
DontCloseHandle = 0
};
Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
QFile();
QFile(const QString &name);
#ifndef QT_NO_QOBJECT
......@@ -106,9 +73,6 @@ public:
#endif
~QFile();
FileError error() const;
void unsetError();
QString fileName() const;
void setFileName(const QString &name);
......@@ -141,18 +105,11 @@ public:
bool copy(const QString &newName);
static bool copy(const QString &fileName, const QString &newName);
bool isSequential() const;
bool open(OpenMode flags);
bool open(FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
bool open(int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle);
virtual void close();
qint64 size() const;
qint64 pos() const;
bool seek(qint64 offset);
bool atEnd() const;
bool flush();
bool resize(qint64 sz);
static bool resize(const QString &filename, qint64 sz);
......@@ -162,15 +119,6 @@ public:
bool setPermissions(Permissions permissionSpec);
static bool setPermissions(const QString &filename, Permissions permissionSpec);
int handle() const;
enum MemoryMapFlags {
NoOptions = 0
};
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
bool unmap(uchar *address);
protected:
#ifdef QT_NO_QOBJECT
QFile(QFilePrivate &dd);
......@@ -178,17 +126,11 @@ protected:
QFile(QFilePrivate &dd, QObject *parent = 0);
#endif
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
qint64 readLineData(char *data, qint64 maxlen);
private:
friend class QTemporaryFile;
Q_DISABLE_COPY(QFile)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QFile::Permissions)
QT_END_NAMESPACE
QT_END_HEADER
......
......@@ -53,15 +53,13 @@
// We mean it.
//
#include "private/qabstractfileengine_p.h"
#include "private/qiodevice_p.h"
#include "private/qringbuffer_p.h"
#include "private/qfiledevice_p.h"
QT_BEGIN_NAMESPACE
class QTemporaryFile;
class QFilePrivate : public QIODevicePrivate
class QFilePrivate : public QFileDevicePrivate
{
Q_DECLARE_PUBLIC(QFile)
friend class QTemporaryFile;
......@@ -76,20 +74,6 @@ protected:
virtual QAbstractFileEngine *engine() const;
QString fileName;
mutable QAbstractFileEngine *fileEngine;
bool lastWasWrite;
QRingBuffer writeBuffer;
inline bool ensureFlushed() const;
bool putCharHelper(char c);
QFile::FileError error;
void setError(QFile::FileError err);
void setError(QFile::FileError err, const QString &errorString);
void setError(QFile::FileError err, int errNum);
mutable qint64 cachedSize;
private:
static QFile::EncoderFn encoder;
......
This diff is collapsed.
/****************************************************************************
**
** 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_H
#define QFILEDEVICE_H
#include <QtCore/qiodevice.h>
#include <QtCore/qstring.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class QFileDevicePrivate;
class Q_CORE_EXPORT QFileDevice : public QIODevice
{
#ifndef QT_NO_QOBJECT
Q_OBJECT
#endif
Q_DECLARE_PRIVATE(QFileDevice)
public:
enum FileError {
NoError = 0,
ReadError = 1,
WriteError = 2,
FatalError = 3,
ResourceError = 4,
OpenError = 5,
AbortError = 6,
TimeOutError = 7,
UnspecifiedError = 8,
RemoveError = 9,
RenameError = 10,
PositionError = 11,
ResizeError = 12,
PermissionsError = 13,
CopyError = 14
};
enum Permission {
ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
};
Q_DECLARE_FLAGS(Permissions, Permission)
enum FileHandleFlag {
AutoCloseHandle = 0x0001,
DontCloseHandle = 0
};
Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
~QFileDevice();
FileError error() const;
void unsetError();
virtual void close();
bool isSequential() const;
int handle() const;
virtual QString fileName() const;
qint64 pos() const;
bool seek(qint64 offset);
bool atEnd() const;
bool flush();
qint64 size() const;
virtual bool resize(qint64 sz);
virtual Permissions permissions() const;
virtual bool setPermissions(Permissions permissionSpec);
enum MemoryMapFlags {
NoOptions = 0
};
uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
bool unmap(uchar *address);
protected:
QFileDevice();
#ifdef QT_NO_QOBJECT
QFileDevice(QFileDevicePrivate &dd);
#else
explicit QFileDevice(QObject *parent);
QFileDevice(QFileDevicePrivate &dd, QObject *parent = 0);
#endif
qint64 readData(char *data, qint64 maxlen);
qint64 writeData(const char *data, qint64 len);
qint64 readLineData(char *data, qint64 maxlen);
private:
Q_DISABLE_COPY(QFileDevice)
};
Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
QT_END_NAMESPACE
QT_END_HEADER
#endif // QFILEDEVICE_H
/****************************************************************************
**
** 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
......@@ -67,6 +67,7 @@ SOURCES += \
../../corelib/io/qfsfileengine.cpp \
../../corelib/io/qfsfileengine_iterator.cpp \
../../corelib/io/qiodevice.cpp \
../../corelib/io/qfiledevice.cpp \
../../corelib/io/qtemporaryfile.cpp \
../../corelib/io/qtextstream.cpp \
../../corelib/io/qurl.cpp \
......
......@@ -36,6 +36,7 @@ OBJECTS = \
qdatastream.o \
qdir.o \
qdiriterator.o \
qfiledevice.o \
qfile.o \
qfileinfo.o \
qabstractfileengine.o \
......
......@@ -34,6 +34,7 @@ OBJECTS = \
qdatastream.obj \
qdir.obj \
qdiriterator.obj \
qfiledevice.obj \
qfile.obj \
qfileinfo.obj \
qabstractfileengine.obj \
......@@ -103,6 +104,7 @@ qbuffer.obj: $(CORESRC)\io\qbuffer.cpp $(PCH)
qdatastream.obj: $(CORESRC)\io\qdatastream.cpp $(PCH)
qdir.obj: $(CORESRC)\io\qdir.cpp $(PCH)
qdiriterator.obj: $(CORESRC)\io\qdiriterator.cpp $(PCH)
qfiledevice.obj: $(CORESRC)\io\qfiledevice.cpp $(PCH)
qfile.obj: $(CORESRC)\io\qfile.cpp $(PCH)
qfileinfo.obj: $(CORESRC)\io\qfileinfo.cpp $(PCH)
qabstractfileengine.obj: $(CORESRC)\io\qabstractfileengine.cpp $(PCH)
......
......@@ -48,6 +48,7 @@ HEADERS = configureapp.h environment.h tools.h\
$$QT_SOURCE_TREE/src/corelib/io/qdatastream.h \
$$QT_SOURCE_TREE/src/corelib/io/qdir.h \
$$QT_SOURCE_TREE/src/corelib/io/qdiriterator.h \
$$QT_SOURCE_TREE/src/corelib/io/qfiledevice.h \
$$QT_SOURCE_TREE/src/corelib/io/qfile.h \
$$QT_SOURCE_TREE/src/corelib/io/qfileinfo.h \
$$QT_SOURCE_TREE/src/corelib/io/qfilesystementry_p.h \
......@@ -92,6 +93,7 @@ SOURCES = main.cpp configureapp.cpp environment.cpp tools.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qdatastream.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qdir.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qdiriterator.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qfiledevice.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qfile.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qfileinfo.cpp \
$$QT_SOURCE_TREE/src/corelib/io/qabstractfileengine.cpp \
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment