Qt 4.8
qiodevice.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 #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 
58 
60 
61 QT_MODULE(Core)
62 
63 class QByteArray;
64 class QIODevicePrivate;
65 
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
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
165 #endif
166 
167 private:
170 
171 public:
172 #ifdef QT3_SUPPORT
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 
251 
253 
254 #endif // QIODEVICE_H
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QIODevice::OpenMode modes)
Definition: qiodevice.cpp:1933
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
#define at(className, varName)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
OpenModeFlag
This enum is used with open() to describe the mode in which a device is opened.
Definition: qiodevice.h:75
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
Q_GUI_EXPORT QString errorString(EGLint code=eglGetError())
Definition: qegl.cpp:743
unsigned char uchar
Definition: qglobal.h:994
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
unsigned __int64 quint64
Definition: qglobal.h:943
static unsigned int getChar(const QChar *str, int &i, const int len)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
__int64 qint64
Definition: qglobal.h:942
#define Q_OBJECT
Definition: qobjectdefs.h:157
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
#define Q_CORE_EXPORT
Definition: qglobal.h:1449
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QScopedPointer< QObjectData > d_ptr
Definition: qobject.h:320
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QIODevice class is the base interface class of all I/O devices in Qt.
Definition: qiodevice.h:66
#define QT_END_HEADER
Definition: qglobal.h:137
#define Status
Definition: qcursor_x11.cpp:59
quint16 Offset
qint64 write(const QByteArray &data)
Writes the content of byteArray to the device.
Definition: qiodevice.h:126
#define enabled
int open(const char *, int,...)
The Text item allows you to add formatted text to a scene.