1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QFILEDEVICE_H
41#define QFILEDEVICE_H
42
43#include <QtCore/qiodevice.h>
44#include <QtCore/qstring.h>
45
46QT_BEGIN_NAMESPACE
47
48class QDateTime;
49class QFileDevicePrivate;
50
51class Q_CORE_EXPORT QFileDevice : public QIODevice
52{
53#ifndef QT_NO_QOBJECT
54 Q_OBJECT
55#endif
56 Q_DECLARE_PRIVATE(QFileDevice)
57
58public:
59 enum FileError {
60 NoError = 0,
61 ReadError = 1,
62 WriteError = 2,
63 FatalError = 3,
64 ResourceError = 4,
65 OpenError = 5,
66 AbortError = 6,
67 TimeOutError = 7,
68 UnspecifiedError = 8,
69 RemoveError = 9,
70 RenameError = 10,
71 PositionError = 11,
72 ResizeError = 12,
73 PermissionsError = 13,
74 CopyError = 14
75 };
76
77 enum FileTime {
78 FileAccessTime,
79 FileBirthTime,
80 FileMetadataChangeTime,
81 FileModificationTime
82 };
83
84 enum Permission {
85 ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
86 ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
87 ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
88 ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
89 };
90 Q_DECLARE_FLAGS(Permissions, Permission)
91
92 enum FileHandleFlag {
93 AutoCloseHandle = 0x0001,
94 DontCloseHandle = 0
95 };
96 Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
97
98 ~QFileDevice();
99
100 FileError error() const;
101 void unsetError();
102
103 void close() override;
104
105 bool isSequential() const override;
106
107 int handle() const;
108 virtual QString fileName() const;
109
110 qint64 pos() const override;
111 bool seek(qint64 offset) override;
112 bool atEnd() const override;
113 bool flush();
114
115 qint64 size() const override;
116
117 virtual bool resize(qint64 sz);
118 virtual Permissions permissions() const;
119 virtual bool setPermissions(Permissions permissionSpec);
120
121 enum MemoryMapFlag {
122 NoOptions = 0,
123 MapPrivateOption = 0x0001
124 };
125 Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag)
126
127 uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
128 bool unmap(uchar *address);
129
130 QDateTime fileTime(QFileDevice::FileTime time) const;
131 bool setFileTime(const QDateTime &newDate, QFileDevice::FileTime fileTime);
132
133protected:
134 QFileDevice();
135#ifdef QT_NO_QOBJECT
136 QFileDevice(QFileDevicePrivate &dd);
137#else
138 explicit QFileDevice(QObject *parent);
139 QFileDevice(QFileDevicePrivate &dd, QObject *parent = nullptr);
140#endif
141
142 qint64 readData(char *data, qint64 maxlen) override;
143 qint64 writeData(const char *data, qint64 len) override;
144 qint64 readLineData(char *data, qint64 maxlen) override;
145
146private:
147 Q_DISABLE_COPY(QFileDevice)
148};
149
150Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
151Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags)
152Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags)
153
154QT_END_NAMESPACE
155
156#endif // QFILEDEVICE_H
157

source code of qtbase/src/corelib/io/qfiledevice.h