Line data Source code
1 : /****************************************************************************
2 : **
3 : ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4 : ** Contact: http://www.qt-project.org/legal
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 Digia. For licensing terms and
14 : ** conditions see http://qt.digia.com/licensing. For further information
15 : ** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20 : ** Foundation and appearing in the file LICENSE.LGPL included in the
21 : ** packaging of this file. Please review the following information to
22 : ** ensure the GNU Lesser General Public License version 2.1 requirements
23 : ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 : **
25 : ** In addition, as a special exception, Digia gives you certain additional
26 : ** rights. These rights are described in the Digia Qt LGPL Exception
27 : ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 : **
29 : ** GNU General Public License Usage
30 : ** Alternatively, this file may be used under the terms of the GNU
31 : ** General Public License version 3.0 as published by the Free Software
32 : ** Foundation and appearing in the file LICENSE.GPL included in the
33 : ** packaging of this file. Please review the following information to
34 : ** ensure the GNU General Public License version 3.0 requirements will be
35 : ** met: http://www.gnu.org/copyleft/gpl.html.
36 : **
37 : **
38 : ** $QT_END_LICENSE$
39 : **
40 : ****************************************************************************/
41 :
42 : #ifndef QIODEVICE_H
43 : #define QIODEVICE_H
44 :
45 : #include <QtCore/qglobal.h>
46 : #ifndef QT_NO_QOBJECT
47 : #include <QtCore/qobject.h>
48 : #else
49 : #include <QtCore/qobjectdefs.h>
50 : #include <QtCore/qscopedpointer.h>
51 : #endif
52 : #include <QtCore/qstring.h>
53 :
54 : #ifdef open
55 : #error qiodevice.h must be included before any header file that defines open
56 : #endif
57 :
58 : QT_BEGIN_NAMESPACE
59 :
60 :
61 : class QByteArray;
62 : class QIODevicePrivate;
63 :
64 : class Q_CORE_EXPORT QIODevice
65 : #ifndef QT_NO_QOBJECT
66 : : public QObject
67 : #endif
68 : {
69 : #ifndef QT_NO_QOBJECT
70 : Q_OBJECT
71 : #endif
72 : public:
73 : enum OpenModeFlag {
74 : NotOpen = 0x0000,
75 : ReadOnly = 0x0001,
76 : WriteOnly = 0x0002,
77 : ReadWrite = ReadOnly | WriteOnly,
78 : Append = 0x0004,
79 : Truncate = 0x0008,
80 : Text = 0x0010,
81 : Unbuffered = 0x0020
82 : };
83 : Q_DECLARE_FLAGS(OpenMode, OpenModeFlag)
84 :
85 : QIODevice();
86 : #ifndef QT_NO_QOBJECT
87 : explicit QIODevice(QObject *parent);
88 : #endif
89 : virtual ~QIODevice();
90 :
91 : OpenMode openMode() const;
92 :
93 : void setTextModeEnabled(bool enabled);
94 : bool isTextModeEnabled() const;
95 :
96 : bool isOpen() const;
97 : bool isReadable() const;
98 : bool isWritable() const;
99 : virtual bool isSequential() const;
100 :
101 : virtual bool open(OpenMode mode);
102 : virtual void close();
103 :
104 : // ### Qt 6: pos() and seek() should not be virtual, and
105 : // ### seek() should call a virtual seekData() function.
106 : virtual qint64 pos() const;
107 : virtual qint64 size() const;
108 : virtual bool seek(qint64 pos);
109 : virtual bool atEnd() const;
110 : virtual bool reset();
111 :
112 : virtual qint64 bytesAvailable() const;
113 : virtual qint64 bytesToWrite() const;
114 :
115 : qint64 read(char *data, qint64 maxlen);
116 : QByteArray read(qint64 maxlen);
117 : QByteArray readAll();
118 : qint64 readLine(char *data, qint64 maxlen);
119 : QByteArray readLine(qint64 maxlen = 0);
120 : virtual bool canReadLine() const;
121 :
122 : qint64 write(const char *data, qint64 len);
123 : qint64 write(const char *data);
124 0 : inline qint64 write(const QByteArray &data)
125 0 : { return write(data.constData(), data.size()); }
126 :
127 : qint64 peek(char *data, qint64 maxlen);
128 : QByteArray peek(qint64 maxlen);
129 :
130 : virtual bool waitForReadyRead(int msecs);
131 : virtual bool waitForBytesWritten(int msecs);
132 :
133 : void ungetChar(char c);
134 : bool putChar(char c);
135 : bool getChar(char *c);
136 :
137 : QString errorString() const;
138 :
139 : #ifndef QT_NO_QOBJECT
140 : Q_SIGNALS:
141 : void readyRead();
142 : void bytesWritten(qint64 bytes);
143 : void aboutToClose();
144 : void readChannelFinished();
145 : #endif
146 :
147 : protected:
148 : #ifdef QT_NO_QOBJECT
149 : QIODevice(QIODevicePrivate &dd);
150 : #else
151 : QIODevice(QIODevicePrivate &dd, QObject *parent = 0);
152 : #endif
153 : virtual qint64 readData(char *data, qint64 maxlen) = 0;
154 : virtual qint64 readLineData(char *data, qint64 maxlen);
155 : virtual qint64 writeData(const char *data, qint64 len) = 0;
156 :
157 : void setOpenMode(OpenMode openMode);
158 :
159 : void setErrorString(const QString &errorString);
160 :
161 : #ifdef QT_NO_QOBJECT
162 : QScopedPointer<QIODevicePrivate> d_ptr;
163 : #endif
164 :
165 : private:
166 : Q_DECLARE_PRIVATE(QIODevice)
167 : Q_DISABLE_COPY(QIODevice)
168 : };
169 :
170 : Q_DECLARE_OPERATORS_FOR_FLAGS(QIODevice::OpenMode)
171 :
172 : #if !defined(QT_NO_DEBUG_STREAM)
173 : class QDebug;
174 : Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes);
175 : #endif
176 :
177 : QT_END_NAMESPACE
178 :
179 : #endif // QIODEVICE_H
|