File indexing completed on 2025-09-18 09:26:27
0001
0002
0003
0004 #ifndef QFILEDEVICE_H
0005 #define QFILEDEVICE_H
0006
0007 #include <QtCore/qiodevice.h>
0008 #include <QtCore/qstring.h>
0009
0010 QT_BEGIN_NAMESPACE
0011
0012 class QDateTime;
0013 class QFileDevicePrivate;
0014
0015 #if !defined(QT_USE_NODISCARD_FILE_OPEN) && !defined(QT_NO_USE_NODISCARD_FILE_OPEN)
0016 # if QT_VERSION < QT_VERSION_CHECK(6, 10, 0)
0017 # define QT_NO_USE_NODISCARD_FILE_OPEN
0018 # else
0019 # define QT_USE_NODISCARD_FILE_OPEN
0020 # endif
0021 #endif
0022
0023 #if defined(QT_USE_NODISCARD_FILE_OPEN) && defined(QT_NO_USE_NODISCARD_FILE_OPEN)
0024 #error "Inconsistent macro definition for nodiscard QFile::open"
0025 #elif defined(QT_USE_NODISCARD_FILE_OPEN)
0026 #define QFILE_MAYBE_NODISCARD [[nodiscard]]
0027 #else
0028 #define QFILE_MAYBE_NODISCARD
0029 #endif
0030
0031 class Q_CORE_EXPORT QFileDevice : public QIODevice
0032 {
0033 #ifndef QT_NO_QOBJECT
0034 Q_OBJECT
0035 #endif
0036 Q_DECLARE_PRIVATE(QFileDevice)
0037
0038 public:
0039 enum FileError {
0040 NoError = 0,
0041 ReadError = 1,
0042 WriteError = 2,
0043 FatalError = 3,
0044 ResourceError = 4,
0045 OpenError = 5,
0046 AbortError = 6,
0047 TimeOutError = 7,
0048 UnspecifiedError = 8,
0049 RemoveError = 9,
0050 RenameError = 10,
0051 PositionError = 11,
0052 ResizeError = 12,
0053 PermissionsError = 13,
0054 CopyError = 14
0055 };
0056
0057 enum FileTime {
0058 FileAccessTime,
0059 FileBirthTime,
0060 FileMetadataChangeTime,
0061 FileModificationTime
0062 };
0063
0064 enum Permission {
0065 ReadOwner = 0x4000, WriteOwner = 0x2000, ExeOwner = 0x1000,
0066 ReadUser = 0x0400, WriteUser = 0x0200, ExeUser = 0x0100,
0067 ReadGroup = 0x0040, WriteGroup = 0x0020, ExeGroup = 0x0010,
0068 ReadOther = 0x0004, WriteOther = 0x0002, ExeOther = 0x0001
0069 };
0070 Q_DECLARE_FLAGS(Permissions, Permission)
0071
0072 enum FileHandleFlag {
0073 AutoCloseHandle = 0x0001,
0074 DontCloseHandle = 0
0075 };
0076 Q_DECLARE_FLAGS(FileHandleFlags, FileHandleFlag)
0077
0078 ~QFileDevice();
0079
0080 FileError error() const;
0081 void unsetError();
0082
0083 void close() override;
0084
0085 bool isSequential() const override;
0086
0087 int handle() const;
0088 virtual QString fileName() const;
0089
0090 qint64 pos() const override;
0091 bool seek(qint64 offset) override;
0092 bool atEnd() const override;
0093 bool flush();
0094
0095 qint64 size() const override;
0096
0097 virtual bool resize(qint64 sz);
0098 virtual Permissions permissions() const;
0099 virtual bool setPermissions(Permissions permissionSpec);
0100
0101 enum MemoryMapFlag {
0102 NoOptions = 0,
0103 MapPrivateOption = 0x0001
0104 };
0105 Q_DECLARE_FLAGS(MemoryMapFlags, MemoryMapFlag)
0106
0107 uchar *map(qint64 offset, qint64 size, MemoryMapFlags flags = NoOptions);
0108 bool unmap(uchar *address);
0109
0110 QDateTime fileTime(QFileDevice::FileTime time) const;
0111 bool setFileTime(const QDateTime &newDate, QFileDevice::FileTime fileTime);
0112
0113 protected:
0114 QFileDevice();
0115 #ifdef QT_NO_QOBJECT
0116 QFileDevice(QFileDevicePrivate &dd);
0117 #else
0118 explicit QFileDevice(QObject *parent);
0119 QFileDevice(QFileDevicePrivate &dd, QObject *parent = nullptr);
0120 #endif
0121
0122 qint64 readData(char *data, qint64 maxlen) override;
0123 qint64 writeData(const char *data, qint64 len) override;
0124 qint64 readLineData(char *data, qint64 maxlen) override;
0125
0126 private:
0127 Q_DISABLE_COPY(QFileDevice)
0128 };
0129
0130 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::Permissions)
0131 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::FileHandleFlags)
0132 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDevice::MemoryMapFlags)
0133
0134 QT_END_NAMESPACE
0135
0136 #endif