source: trunk/src/corelib/io/qiodevice.h@ 240

Last change on this file since 240 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

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