Line data Source code
1 : /****************************************************************************
2 : **
3 : ** Copyright (C) 2016 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 : #ifndef QT_NO_QOBJECT
45 : #include <QtCore/qobject.h>
46 : #else
47 : #include <QtCore/qobjectdefs.h>
48 : #include <QtCore/qscopedpointer.h>
49 : #endif
50 : #include <QtCore/qstring.h>
51 :
52 : #ifdef open
53 : #error qiodevice.h must be included before any header file that defines open
54 : #endif
55 :
56 : QT_BEGIN_NAMESPACE
57 :
58 :
59 : class QByteArray;
60 : class QIODevicePrivate;
61 :
62 : class Q_CORE_EXPORT QIODevice
63 : #ifndef QT_NO_QOBJECT
64 : : public QObject
65 : #endif
66 : {
67 : #ifndef QT_NO_QOBJECT
68 : Q_OBJECT
69 : #endif
70 : public:
71 : enum OpenModeFlag {
72 : NotOpen = 0x0000,
73 : ReadOnly = 0x0001,
74 : WriteOnly = 0x0002,
75 : ReadWrite = ReadOnly | WriteOnly,
76 : Append = 0x0004,
77 : Truncate = 0x0008,
78 : Text = 0x0010,
79 : Unbuffered = 0x0020
80 : };
81 : Q_DECLARE_FLAGS(OpenMode, OpenModeFlag)
82 :
83 : QIODevice();
84 : #ifndef QT_NO_QOBJECT
85 : explicit QIODevice(QObject *parent);
86 : #endif
87 : virtual ~QIODevice();
88 :
89 : OpenMode openMode() const;
90 :
91 : void setTextModeEnabled(bool enabled);
92 : bool isTextModeEnabled() const;
93 :
94 : bool isOpen() const;
95 : bool isReadable() const;
96 : bool isWritable() const;
97 : virtual bool isSequential() const;
98 :
99 : int readChannelCount() const;
100 : int writeChannelCount() const;
101 : int currentReadChannel() const;
102 : void setCurrentReadChannel(int channel);
103 : int currentWriteChannel() const;
104 : void setCurrentWriteChannel(int channel);
105 :
106 : virtual bool open(OpenMode mode);
107 : virtual void close();
108 :
109 : // ### Qt 6: pos() and seek() should not be virtual, and
110 : // ### seek() should call a virtual seekData() function.
111 : virtual qint64 pos() const;
112 : virtual qint64 size() const;
113 : virtual bool seek(qint64 pos);
114 : virtual bool atEnd() const;
115 : virtual bool reset();
116 :
117 : virtual qint64 bytesAvailable() const;
118 : virtual qint64 bytesToWrite() const;
119 :
120 : qint64 read(char *data, qint64 maxlen);
121 : QByteArray read(qint64 maxlen);
122 : QByteArray readAll();
123 : qint64 readLine(char *data, qint64 maxlen);
124 : QByteArray readLine(qint64 maxlen = 0);
125 : virtual bool canReadLine() const;
126 :
127 : void startTransaction();
128 : void commitTransaction();
129 : void rollbackTransaction();
130 : bool isTransactionStarted() const;
131 :
132 : qint64 write(const char *data, qint64 len);
133 : qint64 write(const char *data);
134 0 : inline qint64 write(const QByteArray &data)
135 0 : { return write(data.constData(), data.size()); }
136 :
137 : qint64 peek(char *data, qint64 maxlen);
138 : QByteArray peek(qint64 maxlen);
139 : qint64 skip(qint64 maxSize);
140 :
141 : virtual bool waitForReadyRead(int msecs);
142 : virtual bool waitForBytesWritten(int msecs);
143 :
144 : void ungetChar(char c);
145 : bool putChar(char c);
146 : bool getChar(char *c);
147 :
148 : QString errorString() const;
149 :
150 : #ifndef QT_NO_QOBJECT
151 : Q_SIGNALS:
152 : void readyRead();
153 : void channelReadyRead(int channel);
154 : void bytesWritten(qint64 bytes);
155 : void channelBytesWritten(int channel, qint64 bytes);
156 : void aboutToClose();
157 : void readChannelFinished();
158 : #endif
159 :
160 : protected:
161 : #ifdef QT_NO_QOBJECT
162 : QIODevice(QIODevicePrivate &dd);
163 : #else
164 : QIODevice(QIODevicePrivate &dd, QObject *parent = Q_NULLPTR);
165 : #endif
166 : virtual qint64 readData(char *data, qint64 maxlen) = 0;
167 : virtual qint64 readLineData(char *data, qint64 maxlen);
168 : virtual qint64 writeData(const char *data, qint64 len) = 0;
169 :
170 : void setOpenMode(OpenMode openMode);
171 :
172 : void setErrorString(const QString &errorString);
173 :
174 : #ifdef QT_NO_QOBJECT
175 : QScopedPointer<QIODevicePrivate> d_ptr;
176 : #endif
177 :
178 : private:
179 : Q_DECLARE_PRIVATE(QIODevice)
180 : Q_DISABLE_COPY(QIODevice)
181 : };
182 :
183 : Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
184 :
185 : #if !defined(QT_NO_DEBUG_STREAM)
186 : class QDebug;
187 : Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
188 : #endif
189 :
190 : QT_END_NAMESPACE
191 :
192 : #endif // QIODEVICE_H
|