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

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 8.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** 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 have questions regarding the use of this file, please contact
37** Nokia 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#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_HEADER
58
59QT_BEGIN_NAMESPACE
60
61QT_MODULE(Core)
62
63class QByteArray;
64class QIODevicePrivate;
65
66class 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
74public:
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
142Q_SIGNALS:
143 void readyRead();
144 void bytesWritten(qint64 bytes);
145 void aboutToClose();
146 void readChannelFinished();
147#endif
148
149protected:
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
167private:
168 Q_DECLARE_PRIVATE(QIODevice)
169 Q_DISABLE_COPY(QIODevice)