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