| 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 QIODEVICE_H |
| 5 | #define QIODEVICE_H |
| 6 | |
| 7 | #include <QtCore/qglobal.h> |
| 8 | #include <QtCore/qiodevicebase.h> |
| 9 | #ifndef QT_NO_QOBJECT |
| 10 | #include <QtCore/qobject.h> |
| 11 | #else |
| 12 | #include <QtCore/qobjectdefs.h> |
| 13 | #include <QtCore/qscopedpointer.h> |
| 14 | #endif |
| 15 | #include <QtCore/qstring.h> |
| 16 | |
| 17 | #ifdef open |
| 18 | #error qiodevice.h must be included before any header file that defines open |
| 19 | #endif |
| 20 | |
| 21 | QT_BEGIN_NAMESPACE |
| 22 | |
| 23 | |
| 24 | class QByteArray; |
| 25 | class QIODevicePrivate; |
| 26 | |
| 27 | class Q_CORE_EXPORT QIODevice |
| 28 | #ifndef QT_NO_QOBJECT |
| 29 | : public QObject, |
| 30 | #else |
| 31 | : |
| 32 | #endif |
| 33 | public QIODeviceBase |
| 34 | { |
| 35 | #ifndef QT_NO_QOBJECT |
| 36 | Q_OBJECT |
| 37 | #endif |
| 38 | public: |
| 39 | QIODevice(); |
| 40 | #ifndef QT_NO_QOBJECT |
| 41 | explicit QIODevice(QObject *parent); |
| 42 | #endif |
| 43 | virtual ~QIODevice(); |
| 44 | |
| 45 | QIODeviceBase::OpenMode openMode() const; |
| 46 | |
| 47 | void setTextModeEnabled(bool enabled); |
| 48 | bool isTextModeEnabled() const; |
| 49 | |
| 50 | bool isOpen() const; |
| 51 | bool isReadable() const; |
| 52 | bool isWritable() const; |
| 53 | virtual bool isSequential() const; |
| 54 | |
| 55 | int readChannelCount() const; |
| 56 | int writeChannelCount() const; |
| 57 | int currentReadChannel() const; |
| 58 | void setCurrentReadChannel(int channel); |
| 59 | int currentWriteChannel() const; |
| 60 | void setCurrentWriteChannel(int channel); |
| 61 | |
| 62 | virtual bool open(QIODeviceBase::OpenMode mode); |
| 63 | virtual void close(); |
| 64 | |
| 65 | // ### Qt 7 - QTBUG-76492: pos() and seek() should not be virtual, and |
| 66 | // ### seek() should call a virtual seekData() function. |
| 67 | virtual qint64 pos() const; |
| 68 | virtual qint64 size() const; |
| 69 | virtual bool seek(qint64 pos); |
| 70 | virtual bool atEnd() const; |
| 71 | virtual bool reset(); |
| 72 | |
| 73 | virtual qint64 bytesAvailable() const; |
| 74 | virtual qint64 bytesToWrite() const; |
| 75 | |
| 76 | qint64 read(char *data, qint64 maxlen); |
| 77 | QByteArray read(qint64 maxlen); |
| 78 | QByteArray readAll(); |
| 79 | qint64 readLine(char *data, qint64 maxlen); |
| 80 | QByteArray readLine(qint64 maxlen = 0); |
| 81 | virtual bool canReadLine() const; |
| 82 | |
| 83 | void startTransaction(); |
| 84 | void commitTransaction(); |
| 85 | void rollbackTransaction(); |
| 86 | bool isTransactionStarted() const; |
| 87 | |
| 88 | qint64 write(const char *data, qint64 len); |
| 89 | qint64 write(const char *data); |
| 90 | qint64 write(const QByteArray &data); |
| 91 | |
| 92 | qint64 peek(char *data, qint64 maxlen); |
| 93 | QByteArray peek(qint64 maxlen); |
| 94 | qint64 skip(qint64 maxSize); |
| 95 | |
| 96 | virtual bool waitForReadyRead(int msecs); |
| 97 | virtual bool waitForBytesWritten(int msecs); |
| 98 | |
| 99 | void ungetChar(char c); |
| 100 | bool putChar(char c); |
| 101 | bool getChar(char *c); |
| 102 | |
| 103 | QString errorString() const; |
| 104 | |
| 105 | #ifndef QT_NO_QOBJECT |
| 106 | Q_SIGNALS: |
| 107 | void readyRead(); |
| 108 | void channelReadyRead(int channel); |
| 109 | void bytesWritten(qint64 bytes); |
| 110 | void channelBytesWritten(int channel, qint64 bytes); |
| 111 | void aboutToClose(); |
| 112 | void readChannelFinished(); |
| 113 | #endif |
| 114 | |
| 115 | protected: |
| 116 | #ifdef QT_NO_QOBJECT |
| 117 | QIODevice(QIODevicePrivate &dd); |
| 118 | #else |
| 119 | QIODevice(QIODevicePrivate &dd, QObject *parent = nullptr); |
| 120 | #endif |
| 121 | virtual qint64 readData(char *data, qint64 maxlen) = 0; |
| 122 | virtual qint64 readLineData(char *data, qint64 maxlen); |
| 123 | virtual qint64 skipData(qint64 maxSize); |
| 124 | virtual qint64 writeData(const char *data, qint64 len) = 0; |
| 125 | |
| 126 | void setOpenMode(QIODeviceBase::OpenMode openMode); |
| 127 | |
| 128 | void setErrorString(const QString &errorString); |
| 129 | |
| 130 | #ifdef QT_NO_QOBJECT |
| 131 | QScopedPointer<QIODevicePrivate> d_ptr; |
| 132 | #endif |
| 133 | |
| 134 | private: |
| 135 | Q_DECLARE_PRIVATE(QIODevice) |
| 136 | Q_DISABLE_COPY(QIODevice) |
| 137 | }; |
| 138 | |
| 139 | Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode) |
| 140 | |
| 141 | #if !defined(QT_NO_DEBUG_STREAM) |
| 142 | class QDebug; |
| 143 | Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes); |
| 144 | #endif |
| 145 | |
| 146 | QT_END_NAMESPACE |
| 147 | |
| 148 | #endif // QIODEVICE_H |
| 149 | |