|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtCore module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QIODEVICE_H |
|
43 #define QIODEVICE_H |
|
44 |
|
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 |
|
57 QT_BEGIN_HEADER |
|
58 |
|
59 QT_BEGIN_NAMESPACE |
|
60 |
|
61 QT_MODULE(Core) |
|
62 |
|
63 class QByteArray; |
|
64 class QIODevicePrivate; |
|
65 |
|
66 class Q_CORE_EXPORT QIODevice |
|
67 #ifndef QT_NO_QOBJECT |
|
68 : public QObject |
|
69 #endif |
|
70 { |
|
71 #ifndef QT_NO_QOBJECT |
|
72 Q_OBJECT |
|
73 #endif |
|
74 public: |
|
75 enum OpenModeFlag { |
|
76 NotOpen = 0x0000, |
|
77 ReadOnly = 0x0001, |
|
78 WriteOnly = 0x0002, |
|
79 ReadWrite = ReadOnly | WriteOnly, |
|
80 Append = 0x0004, |
|
81 Truncate = 0x0008, |
|
82 Text = 0x0010, |
|
83 Unbuffered = 0x0020 |
|
84 }; |
|
85 Q_DECLARE_FLAGS(OpenMode, OpenModeFlag) |
|
86 |
|
87 QIODevice(); |
|
88 #ifndef QT_NO_QOBJECT |
|
89 explicit QIODevice(QObject *parent); |
|
90 #endif |
|
91 virtual ~QIODevice(); |
|
92 |
|
93 OpenMode openMode() const; |
|
94 |
|
95 void setTextModeEnabled(bool enabled); |
|
96 bool isTextModeEnabled() const; |
|
97 |
|
98 bool isOpen() const; |
|
99 bool isReadable() const; |
|
100 bool isWritable() const; |
|
101 virtual bool isSequential() const; |
|
102 |
|
103 virtual bool open(OpenMode mode); |
|
104 virtual void close(); |
|
105 |
|
106 // ### Qt 5: pos() and seek() should not be virtual, and |
|
107 // ### seek() should call a virtual seekData() function. |
|
108 virtual qint64 pos() const; |
|
109 virtual qint64 size() const; |
|
110 virtual bool seek(qint64 pos); |
|
111 virtual bool atEnd() const; |
|
112 virtual bool reset(); |
|
113 |
|
114 virtual qint64 bytesAvailable() const; |
|
115 virtual qint64 bytesToWrite() const; |
|
116 |
|
117 qint64 read(char *data, qint64 maxlen); |
|
118 QByteArray read(qint64 maxlen); |
|
119 QByteArray readAll(); |
|
120 qint64 readLine(char *data, qint64 maxlen); |
|
121 QByteArray readLine(qint64 maxlen = 0); |
|
122 virtual bool canReadLine() const; |
|
123 |
|
124 qint64 write(const char *data, qint64 len); |
|
125 qint64 write(const char *data); |
|
126 inline qint64 write(const QByteArray &data) |
|
127 { return write(data.constData(), data.size()); } |
|
128 |
|
129 qint64 peek(char *data, qint64 maxlen); |
|
130 QByteArray peek(qint64 maxlen); |
|
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 |
|
142 Q_SIGNALS: |
|
143 void readyRead(); |
|
144 void bytesWritten(qint64 bytes); |
|
145 void aboutToClose(); |
|
146 void readChannelFinished(); |
|
147 #endif |
|
148 |
|
149 protected: |
|
150 #ifdef QT_NO_QOBJECT |
|
151 QIODevice(QIODevicePrivate &dd); |
|
152 #else |
|
153 QIODevice(QIODevicePrivate &dd, QObject *parent = 0); |
|
154 #endif |
|
155 virtual qint64 readData(char *data, qint64 maxlen) = 0; |
|
156 virtual qint64 readLineData(char *data, qint64 maxlen); |
|
157 virtual qint64 writeData(const char *data, qint64 len) = 0; |
|
158 |
|
159 void setOpenMode(OpenMode openMode); |
|
160 |
|
161 void setErrorString(const QString &errorString); |
|
162 |
|
163 #ifdef QT_NO_QOBJECT |
|
164 QScopedPointer<QIODevicePrivate> d_ptr; |
|
165 #endif |
|
166 |
|
167 private: |
|
168 Q_DECLARE_PRIVATE(QIODevice) |
|
169 Q_DISABLE_COPY(QIODevice) |
|
170 |
|
171 #ifdef QT3_SUPPORT |
|
172 public: |
|
173 typedef qint64 Offset; |
|
174 |
|
175 inline QT3_SUPPORT int flags() const { return static_cast<int>(openMode()); } |
|
176 inline QT3_SUPPORT int mode() const { return static_cast<int>(openMode()); } |
|
177 inline QT3_SUPPORT int state() const; |
|
178 |
|
179 inline QT3_SUPPORT bool isDirectAccess() const { return !isSequential(); } |
|
180 inline QT3_SUPPORT bool isSequentialAccess() const { return isSequential(); } |
|
181 inline QT3_SUPPORT bool isCombinedAccess() const { return false; } |
|
182 inline QT3_SUPPORT bool isBuffered() const { return true; } |
|
183 inline QT3_SUPPORT bool isRaw() const { return false; } |
|
184 inline QT3_SUPPORT bool isSynchronous() const { return true; } |
|
185 inline QT3_SUPPORT bool isAsynchronous() const { return false; } |
|
186 inline QT3_SUPPORT bool isTranslated() const { return (openMode() & Text) != 0; } |
|
187 inline QT3_SUPPORT bool isInactive() const { return !isOpen(); } |
|
188 |
|
189 typedef int Status; |
|
190 QT3_SUPPORT Status status() const; |
|
191 QT3_SUPPORT void resetStatus(); |
|
192 |
|
193 inline QT3_SUPPORT Offset at() const { return pos(); } |
|
194 inline QT3_SUPPORT bool at(Offset offset) { return seek(offset); } |
|
195 |
|
196 inline QT3_SUPPORT qint64 readBlock(char *data, quint64 maxlen) { return read(data, maxlen); } |
|
197 inline QT3_SUPPORT qint64 writeBlock(const char *data, quint64 len) { return write(data, len); } |
|
198 inline QT3_SUPPORT qint64 writeBlock(const QByteArray &data) { return write(data); } |
|
199 |
|
200 inline QT3_SUPPORT int getch() { char c; return getChar(&c) ? int(uchar(c)) : -1; } |
|
201 inline QT3_SUPPORT int putch(int c) { return putChar(char(c)) ? int(uchar(c)) : -1; } |
|
202 inline QT3_SUPPORT int ungetch(int c) { ungetChar(uchar(c)); return c; } |
|
203 #endif |
|
204 }; |
|
205 |
|
206 Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode) |
|
207 |
|
208 #ifdef QT3_SUPPORT |
|
209 static QT3_SUPPORT_VARIABLE const uint IO_Direct = 0x0100; |
|
210 static QT3_SUPPORT_VARIABLE const uint IO_Sequential = 0x0200; |
|
211 static QT3_SUPPORT_VARIABLE const uint IO_Combined = 0x0300; |
|
212 static QT3_SUPPORT_VARIABLE const uint IO_TypeMask = 0x0300; |
|
213 |
|
214 static QT3_SUPPORT_VARIABLE const uint IO_Raw = 0x0000; |
|
215 static QT3_SUPPORT_VARIABLE const uint IO_Async = 0x0000; |
|
216 |
|
217 #define IO_ReadOnly QIODevice::ReadOnly |
|
218 #define IO_WriteOnly QIODevice::WriteOnly |
|
219 #define IO_ReadWrite QIODevice::ReadWrite |
|
220 #define IO_Append QIODevice::Append |
|
221 #define IO_Truncate QIODevice::Truncate |
|
222 #define IO_Translate QIODevice::Text |
|
223 #define IO_ModeMask 0x00ff |
|
224 |
|
225 static QT3_SUPPORT_VARIABLE const uint IO_Open = 0x1000; |
|
226 static QT3_SUPPORT_VARIABLE const uint IO_StateMask = 0xf000; |
|
227 |
|
228 static QT3_SUPPORT_VARIABLE const uint IO_Ok = 0; |
|
229 static QT3_SUPPORT_VARIABLE const uint IO_ReadError = 1; |
|
230 static QT3_SUPPORT_VARIABLE const uint IO_WriteError = 2; |
|
231 static QT3_SUPPORT_VARIABLE const uint IO_FatalError = 3; |
|
232 static QT3_SUPPORT_VARIABLE const uint IO_ResourceError = 4; |
|
233 static QT3_SUPPORT_VARIABLE const uint IO_OpenError = 5; |
|
234 static QT3_SUPPORT_VARIABLE const uint IO_ConnectError = 5; |
|
235 static QT3_SUPPORT_VARIABLE const uint IO_AbortError = 6; |
|
236 static QT3_SUPPORT_VARIABLE const uint IO_TimeOutError = 7; |
|
237 static QT3_SUPPORT_VARIABLE const uint IO_UnspecifiedError = 8; |
|
238 |
|
239 inline QT3_SUPPORT int QIODevice::state() const |
|
240 { |
|
241 return isOpen() ? 0x1000 : 0; |
|
242 } |
|
243 #endif |
|
244 |
|
245 #if !defined(QT_NO_DEBUG_STREAM) |
|
246 class QDebug; |
|
247 Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes); |
|
248 #endif |
|
249 |
|
250 QT_END_NAMESPACE |
|
251 |
|
252 QT_END_HEADER |
|
253 |
|
254 #endif // QIODEVICE_H |