1/****************************************************************************
2**
3** Copyright (C) 2020 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QIODEVICE_H
41#define QIODEVICE_H
42
43#include <QtCore/qglobal.h>
44#include <QtCore/qiodevicebase.h>
45#ifndef QT_NO_QOBJECT
46#include <QtCore/qobject.h>
47#else
48#include <QtCore/qobjectdefs.h>
49#include <QtCore/qscopedpointer.h>
50#endif
51#include <QtCore/qstring.h>
52
53#ifdef open
54#error qiodevice.h must be included before any header file that defines open
55#endif
56
57QT_BEGIN_NAMESPACE
58
59
60class QByteArray;
61class QIODevicePrivate;
62
63class Q_CORE_EXPORT QIODevice
64#ifndef QT_NO_QOBJECT
65 : public QObject,
66#else
67 :
68#endif
69 public QIODeviceBase
70{
71#ifndef QT_NO_QOBJECT
72 Q_OBJECT
73#endif
74public:
75 QIODevice();
76#ifndef QT_NO_QOBJECT
77 explicit QIODevice(QObject *parent);
78#endif
79 virtual ~QIODevice();
80
81 OpenMode openMode() const;
82
83 void setTextModeEnabled(bool enabled);
84 bool isTextModeEnabled() const;
85
86 bool isOpen() const;
87 bool isReadable() const;
88 bool isWritable() const;
89 virtual bool isSequential() const;
90
91 int readChannelCount() const;
92 int writeChannelCount() const;
93 int currentReadChannel() const;
94 void setCurrentReadChannel(int channel);
95 int currentWriteChannel() const;
96 void setCurrentWriteChannel(int channel);
97
98 virtual bool open(OpenMode mode);
99 virtual void close();
100
101 // ### Qt 6: pos() and seek() should not be virtual, and
102 // ### seek() should call a virtual seekData() function.
103 virtual qint64 pos() const;
104 virtual qint64 size() const;
105 virtual bool seek(qint64 pos);
106 virtual bool atEnd() const;
107 virtual bool reset();
108
109 virtual qint64 bytesAvailable() const;
110 virtual qint64 bytesToWrite() const;
111
112 qint64 read(char *data, qint64 maxlen);
113 QByteArray read(qint64 maxlen);
114 QByteArray readAll();
115 qint64 readLine(char *data, qint64 maxlen);
116 QByteArray readLine(qint64 maxlen = 0);
117 virtual bool canReadLine() const;
118
119 void startTransaction();
120 void commitTransaction();
121 void rollbackTransaction();
122 bool isTransactionStarted() const;
123
124 qint64 write(const char *data, qint64 len);
125 qint64 write(const char *data);
126 qint64 write(const QByteArray &data);
127
128 qint64 peek(char *data, qint64 maxlen);
129 QByteArray peek(qint64 maxlen);
130 qint64 skip(qint64 maxSize);
131
132 virtual bool waitForReadyRead(int msecs);
133 virtual bool waitForBytesWritten(int msecs);
134
135 void ungetChar(char c);
136 bool putChar(char c);
137 bool getChar(char *c);
138
139 QString errorString() const;
140
141#ifndef QT_NO_QOBJECT
142Q_SIGNALS:
143 void readyRead();
144 void channelReadyRead(int channel);
145 void bytesWritten(qint64 bytes);
146 void channelBytesWritten(int channel, qint64 bytes);
147 void aboutToClose();
148 void readChannelFinished();
149#endif
150
151protected:
152#ifdef QT_NO_QOBJECT
153 QIODevice(QIODevicePrivate &dd);
154#else
155 QIODevice(QIODevicePrivate &dd, QObject *parent = nullptr);
156#endif
157 virtual qint64 readData(char *data, qint64 maxlen) = 0;
158 virtual qint64 readLineData(char *data, qint64 maxlen);
159 virtual qint64 skipData(qint64 maxSize);
160 virtual qint64 writeData(const char *data, qint64 len) = 0;
161
162 void setOpenMode(OpenMode openMode);
163
164 void setErrorString(const QString &errorString);
165
166#ifdef QT_NO_QOBJECT
167 QScopedPointer<QIODevicePrivate> d_ptr;
168#endif
169
170private:
171 Q_DECLARE_PRIVATE(QIODevice)
172 Q_DISABLE_COPY(QIODevice)
173};
174
175Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
176
177#if !defined(QT_NO_DEBUG_STREAM)
178class QDebug;
179Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
180#endif
181
182QT_END_NAMESPACE
183
184#endif // QIODEVICE_H
185