1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the QtCore module of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
45
#include <QtCore/qiodevice.h>
46
#include <QtCore/qstring.h>
47
#include <QtCore/qchar.h>
48
#include <QtCore/qlocale.h>
49
#include <QtCore/qscopedpointer.h>
54
#error qtextstream.h must be included before any header file that defines Status
65
class QTextStreamPrivate;
66
class Q_CORE_EXPORT QTextStream // text stream class
68
Q_DECLARE_PRIVATE(QTextStream)
71
enum RealNumberNotation {
93
UppercaseDigits = 0x10
95
Q_DECLARE_FLAGS(NumberFlags, NumberFlag)
98
explicit QTextStream(QIODevice *device);
99
explicit QTextStream(FILE *fileHandle, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
100
explicit QTextStream(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
101
explicit QTextStream(QByteArray *array, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
102
explicit QTextStream(const QByteArray &array, QIODevice::OpenMode openMode = QIODevice::ReadOnly);
103
virtual ~QTextStream();
105
#ifndef QT_NO_TEXTCODEC
106
void setCodec(QTextCodec *codec);
107
void setCodec(const char *codecName);
108
QTextCodec *codec() const;
109
void setAutoDetectUnicode(bool enabled);
110
bool autoDetectUnicode() const;
111
void setGenerateByteOrderMark(bool generate);
112
bool generateByteOrderMark() const;
115
void setLocale(const QLocale &locale);
116
QLocale locale() const;
118
void setDevice(QIODevice *device);
119
QIODevice *device() const;
121
void setString(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
122
QString *string() const;
124
Status status() const;
125
void setStatus(Status status);
131
bool seek(qint64 pos);
134
void skipWhiteSpace();
136
QString readLine(qint64 maxlen = 0);
138
QString read(qint64 maxlen);
140
void setFieldAlignment(FieldAlignment alignment);
141
FieldAlignment fieldAlignment() const;
143
void setPadChar(QChar ch);
144
QChar padChar() const;
146
void setFieldWidth(int width);
147
int fieldWidth() const;
149
void setNumberFlags(NumberFlags flags);
150
NumberFlags numberFlags() const;
152
void setIntegerBase(int base);
153
int integerBase() const;
155
void setRealNumberNotation(RealNumberNotation notation);
156
RealNumberNotation realNumberNotation() const;
158
void setRealNumberPrecision(int precision);
159
int realNumberPrecision() const;
161
QTextStream &operator>>(QChar &ch);
162
QTextStream &operator>>(char &ch);
163
QTextStream &operator>>(signed short &i);
164
QTextStream &operator>>(unsigned short &i);
165
QTextStream &operator>>(signed int &i);
166
QTextStream &operator>>(unsigned int &i);
167
QTextStream &operator>>(signed long &i);
168
QTextStream &operator>>(unsigned long &i);
169
QTextStream &operator>>(qlonglong &i);
170
QTextStream &operator>>(qulonglong &i);
171
QTextStream &operator>>(float &f);
172
QTextStream &operator>>(double &f);
173
QTextStream &operator>>(QString &s);
174
QTextStream &operator>>(QByteArray &array);
175
QTextStream &operator>>(char *c);
177
QTextStream &operator<<(QChar ch);
178
QTextStream &operator<<(char ch);
179
QTextStream &operator<<(signed short i);
180
QTextStream &operator<<(unsigned short i);
181
QTextStream &operator<<(signed int i);
182
QTextStream &operator<<(unsigned int i);
183
QTextStream &operator<<(signed long i);
184
QTextStream &operator<<(unsigned long i);
185
QTextStream &operator<<(qlonglong i);
186
QTextStream &operator<<(qulonglong i);
187
QTextStream &operator<<(float f);
188
QTextStream &operator<<(double f);
189
QTextStream &operator<<(const QString &s);
190
QTextStream &operator<<(QLatin1String s);
191
QTextStream &operator<<(const QByteArray &array);
192
QTextStream &operator<<(const char *c);
193
QTextStream &operator<<(const void *ptr);
196
Q_DISABLE_COPY(QTextStream)
198
QScopedPointer<QTextStreamPrivate> d_ptr;
201
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
203
/*****************************************************************************
204
QTextStream manipulators
205
*****************************************************************************/
207
typedef QTextStream & (*QTextStreamFunction)(QTextStream &);// manipulator function
208
typedef void (QTextStream::*QTSMFI)(int); // manipulator w/int argument
209
typedef void (QTextStream::*QTSMFC)(QChar); // manipulator w/QChar argument
212
class Q_CORE_EXPORT QTextStreamManipulator
215
QTextStreamManipulator(QTSMFI m, int a) { mf = m; mc = 0; arg = a; }
216
QTextStreamManipulator(QTSMFC m, QChar c) { mf = 0; mc = m; ch = c; arg = -1; }
217
void exec(QTextStream &s) { if (mf) { (s.*mf)(arg); } else { (s.*mc)(ch); } }
220
QTSMFI mf; // QTextStream member function
221
QTSMFC mc; // QTextStream member function
222
int arg; // member function argument
226
inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
229
inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
232
inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
233
{ m.exec(s); return s; }
235
Q_CORE_EXPORT QTextStream &bin(QTextStream &s);
236
Q_CORE_EXPORT QTextStream &oct(QTextStream &s);
237
Q_CORE_EXPORT QTextStream &dec(QTextStream &s);
238
Q_CORE_EXPORT QTextStream &hex(QTextStream &s);
240
Q_CORE_EXPORT QTextStream &showbase(QTextStream &s);
241
Q_CORE_EXPORT QTextStream &forcesign(QTextStream &s);
242
Q_CORE_EXPORT QTextStream &forcepoint(QTextStream &s);
243
Q_CORE_EXPORT QTextStream &noshowbase(QTextStream &s);
244
Q_CORE_EXPORT QTextStream &noforcesign(QTextStream &s);
245
Q_CORE_EXPORT QTextStream &noforcepoint(QTextStream &s);
247
Q_CORE_EXPORT QTextStream &uppercasebase(QTextStream &s);
248
Q_CORE_EXPORT QTextStream &uppercasedigits(QTextStream &s);
249
Q_CORE_EXPORT QTextStream &lowercasebase(QTextStream &s);
250
Q_CORE_EXPORT QTextStream &lowercasedigits(QTextStream &s);
252
Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
253
Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
255
Q_CORE_EXPORT QTextStream &left(QTextStream &s);
256
Q_CORE_EXPORT QTextStream &right(QTextStream &s);
257
Q_CORE_EXPORT QTextStream ¢er(QTextStream &s);
259
Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
260
Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
261
Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
263
Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
265
Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
267
inline QTextStreamManipulator qSetFieldWidth(int width)
269
QTSMFI func = &QTextStream::setFieldWidth;
270
return QTextStreamManipulator(func,width);
273
inline QTextStreamManipulator qSetPadChar(QChar ch)
275
QTSMFC func = &QTextStream::setPadChar;
276
return QTextStreamManipulator(func, ch);
279
inline QTextStreamManipulator qSetRealNumberPrecision(int precision)
281
QTSMFI func = &QTextStream::setRealNumberPrecision;
282
return QTextStreamManipulator(func, precision);
289
#endif // QTEXTSTREAM_H