1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QFILEDEVICE_H |
5 | #define QFILEDEVICE_H |
6 | |
7 | #include <QtCore/qiodevice.h> |
8 | #include <QtCore/qstring.h> |
9 | |
10 | QT_BEGIN_NAMESPACE |
11 | |
12 | class QDateTime; |
13 | class QFileDevicePrivate; |
14 | |
15 | class Q_CORE_EXPORT QFileDevice : public QIODevice |
16 | { |
17 | #ifndef QT_NO_QOBJECT |
18 | Q_OBJECT |
19 | #endif |
20 | Q_DECLARE_PRIVATE(QFileDevice) |
21 | |
22 | public: |
23 | enum FileError { |
24 | NoError = 0, |
25 | ReadError = 1, |
26 | WriteError = 2, |
27 | FatalError = 3, |
28 | ResourceError = 4, |
29 | OpenError = 5, |
30 | AbortError = 6, |
31 | TimeOutError = 7, |
32 | UnspecifiedError = 8, |
33 | RemoveError = 9, |
34 | RenameError = 10, |
35 | PositionError = 11, |
36 | ResizeError = 12, |
37 | PermissionsError = 13, |
38 | CopyError = 14 |
39 | }; |
40 | |
41 | enum FileTime { |
42 | FileAccessTime, |
43 | FileBirthTime, |
44 | FileMetadataChangeTime, |
45 | FileModificationTime |
46 | }; |
47 | |
48 | enum Permission { |
49 | ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000, |
50 | ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100, |
51 | ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010, |
52 | ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001 |
53 | }; |
54 | Q_DECLARE_FLAGS(Permissions, Permission) |
55 | |
56 | enum FileHandleFlag { |
57 | AutoCloseHandle = 0x0001, |
58 | DontCloseHandle = 0 |
59 | }; |
60 | Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag) |
61 | |
62 | ~QFileDevice(); |
63 | |
64 | FileError error() const; |
65 | void unsetError(); |
66 | |
67 | void close() override; |
68 | |
69 | bool isSequential() const override; |
70 | |
71 | int handle() const; |
72 | virtual QString fileName() const; |
73 | |
74 | qint64 pos() const override; |
75 | bool seek(qint64 offset) override; |
76 | bool atEnd() const override; |
77 | bool flush(); |
78 | |
79 | qint64 size() const override; |
80 | |
81 | virtual bool resize(qint64 sz); |
82 | virtual Permissions permissions() const; |
83 | virtual bool setPermissions(Permissions permissionSpec); |
84 | |
85 | enum MemoryMapFlag { |
86 | NoOptions = 0, |
87 | MapPrivateOption = 0x0001 |
88 | }; |
89 | Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag) |
90 | |
91 | uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions); |
92 | bool unmap(uchar *address); |
93 | |
94 | QDateTime fileTime(QFileDevice::FileTime time) const; |
95 | bool setFileTime(const QDateTime &newDate, QFileDevice::FileTime fileTime); |
96 | |
97 | protected: |
98 | QFileDevice(); |
99 | #ifdef QT_NO_QOBJECT |
100 | QFileDevice(QFileDevicePrivate &dd); |
101 | #else |
102 | explicit QFileDevice(QObject *parent); |
103 | QFileDevice(QFileDevicePrivate &dd, QObject *parent = nullptr); |
104 | #endif |
105 | |
106 | qint64 readData(char *data, qint64 maxlen) override; |
107 | qint64 writeData(const char *data, qint64 len) override; |
108 | qint64 readLineData(char *data, qint64 maxlen) override; |
109 | |
110 | private: |
111 | Q_DISABLE_COPY(QFileDevice) |
112 | }; |
113 | |
114 | Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions) |
115 | Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags) |
116 | Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags) |
117 | |
118 | QT_END_NAMESPACE |
119 | |
120 | #endif // QFILEDEVICE_H |
121 | |