~ubuntu-branches/ubuntu/wily/qtbase-opensource-src/wily

« back to all changes in this revision

Viewing changes to src/corelib/io/qtextstream.h

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 12:46:17 UTC
  • Revision ID: package-import@ubuntu.com-20130205124617-c8jouts182j002fx
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 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 QTEXTSTREAM_H
 
43
#define QTEXTSTREAM_H
 
44
 
 
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>
 
50
 
 
51
#include <stdio.h>
 
52
 
 
53
#ifdef Status
 
54
#error qtextstream.h must be included before any header file that defines Status
 
55
#endif
 
56
 
 
57
QT_BEGIN_HEADER
 
58
 
 
59
QT_BEGIN_NAMESPACE
 
60
 
 
61
 
 
62
class QTextCodec;
 
63
class QTextDecoder;
 
64
 
 
65
class QTextStreamPrivate;
 
66
class Q_CORE_EXPORT QTextStream                                // text stream class
 
67
{
 
68
    Q_DECLARE_PRIVATE(QTextStream)
 
69
 
 
70
public:
 
71
    enum RealNumberNotation {
 
72
        SmartNotation,
 
73
        FixedNotation,
 
74
        ScientificNotation
 
75
    };
 
76
    enum FieldAlignment {
 
77
        AlignLeft,
 
78
        AlignRight,
 
79
        AlignCenter,
 
80
        AlignAccountingStyle
 
81
    };
 
82
    enum Status {
 
83
        Ok,
 
84
        ReadPastEnd,
 
85
        ReadCorruptData,
 
86
        WriteFailed
 
87
    };
 
88
    enum NumberFlag {
 
89
        ShowBase = 0x1,
 
90
        ForcePoint = 0x2,
 
91
        ForceSign = 0x4,
 
92
        UppercaseBase = 0x8,
 
93
        UppercaseDigits = 0x10
 
94
    };
 
95
    Q_DECLARE_FLAGS(NumberFlags, NumberFlag)
 
96
 
 
97
    QTextStream();
 
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();
 
104
 
 
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;
 
113
#endif
 
114
 
 
115
    void setLocale(const QLocale &locale);
 
116
    QLocale locale() const;
 
117
 
 
118
    void setDevice(QIODevice *device);
 
119
    QIODevice *device() const;
 
120
 
 
121
    void setString(QString *string, QIODevice::OpenMode openMode = QIODevice::ReadWrite);
 
122
    QString *string() const;
 
123
 
 
124
    Status status() const;
 
125
    void setStatus(Status status);
 
126
    void resetStatus();
 
127
 
 
128
    bool atEnd() const;
 
129
    void reset();
 
130
    void flush();
 
131
    bool seek(qint64 pos);
 
132
    qint64 pos() const;
 
133
 
 
134
    void skipWhiteSpace();
 
135
 
 
136
    QString readLine(qint64 maxlen = 0);
 
137
    QString readAll();
 
138
    QString read(qint64 maxlen);
 
139
 
 
140
    void setFieldAlignment(FieldAlignment alignment);
 
141
    FieldAlignment fieldAlignment() const;
 
142
 
 
143
    void setPadChar(QChar ch);
 
144
    QChar padChar() const;
 
145
 
 
146
    void setFieldWidth(int width);
 
147
    int fieldWidth() const;
 
148
 
 
149
    void setNumberFlags(NumberFlags flags);
 
150
    NumberFlags numberFlags() const;
 
151
 
 
152
    void setIntegerBase(int base);
 
153
    int integerBase() const;
 
154
 
 
155
    void setRealNumberNotation(RealNumberNotation notation);
 
156
    RealNumberNotation realNumberNotation() const;
 
157
 
 
158
    void setRealNumberPrecision(int precision);
 
159
    int realNumberPrecision() const;
 
160
 
 
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);
 
176
 
 
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);
 
194
 
 
195
private:
 
196
    Q_DISABLE_COPY(QTextStream)
 
197
 
 
198
    QScopedPointer<QTextStreamPrivate> d_ptr;
 
199
};
 
200
 
 
201
Q_DECLARE_OPERATORS_FOR_FLAGS(QTextStream::NumberFlags)
 
202
 
 
203
/*****************************************************************************
 
204
  QTextStream manipulators
 
205
 *****************************************************************************/
 
206
 
 
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
 
210
 
 
211
 
 
212
class Q_CORE_EXPORT QTextStreamManipulator
 
213
{
 
214
public:
 
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); } }
 
218
 
 
219
private:
 
220
    QTSMFI mf;                                        // QTextStream member function
 
221
    QTSMFC mc;                                        // QTextStream member function
 
222
    int arg;                                          // member function argument
 
223
    QChar ch;
 
224
};
 
225
 
 
226
inline QTextStream &operator>>(QTextStream &s, QTextStreamFunction f)
 
227
{ return (*f)(s); }
 
228
 
 
229
inline QTextStream &operator<<(QTextStream &s, QTextStreamFunction f)
 
230
{ return (*f)(s); }
 
231
 
 
232
inline QTextStream &operator<<(QTextStream &s, QTextStreamManipulator m)
 
233
{ m.exec(s); return s; }
 
234
 
 
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);
 
239
 
 
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);
 
246
 
 
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);
 
251
 
 
252
Q_CORE_EXPORT QTextStream &fixed(QTextStream &s);
 
253
Q_CORE_EXPORT QTextStream &scientific(QTextStream &s);
 
254
 
 
255
Q_CORE_EXPORT QTextStream &left(QTextStream &s);
 
256
Q_CORE_EXPORT QTextStream &right(QTextStream &s);
 
257
Q_CORE_EXPORT QTextStream &center(QTextStream &s);
 
258
 
 
259
Q_CORE_EXPORT QTextStream &endl(QTextStream &s);
 
260
Q_CORE_EXPORT QTextStream &flush(QTextStream &s);
 
261
Q_CORE_EXPORT QTextStream &reset(QTextStream &s);
 
262
 
 
263
Q_CORE_EXPORT QTextStream &bom(QTextStream &s);
 
264
 
 
265
Q_CORE_EXPORT QTextStream &ws(QTextStream &s);
 
266
 
 
267
inline QTextStreamManipulator qSetFieldWidth(int width)
 
268
{
 
269
    QTSMFI func = &QTextStream::setFieldWidth;
 
270
    return QTextStreamManipulator(func,width);
 
271
}
 
272
 
 
273
inline QTextStreamManipulator qSetPadChar(QChar ch)
 
274
{
 
275
    QTSMFC func = &QTextStream::setPadChar;
 
276
    return QTextStreamManipulator(func, ch);
 
277
}
 
278
 
 
279
inline QTextStreamManipulator qSetRealNumberPrecision(int precision)
 
280
{
 
281
    QTSMFI func = &QTextStream::setRealNumberPrecision;
 
282
    return QTextStreamManipulator(func, precision);
 
283
}
 
284
 
 
285
QT_END_NAMESPACE
 
286
 
 
287
QT_END_HEADER
 
288
 
 
289
#endif // QTEXTSTREAM_H