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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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