summaryrefslogtreecommitdiff
path: root/qmake/include/qtextstream.h
Unidiff
Diffstat (limited to 'qmake/include/qtextstream.h') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/include/qtextstream.h335
1 files changed, 335 insertions, 0 deletions
diff --git a/qmake/include/qtextstream.h b/qmake/include/qtextstream.h
new file mode 100644
index 0000000..6979ed7
--- a/dev/null
+++ b/qmake/include/qtextstream.h
@@ -0,0 +1,335 @@
1/****************************************************************************
2** $Id$
3**
4** Definition of QTextStream class
5**
6** Created : 940922
7**
8** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
9**
10** This file is part of the tools module of the Qt GUI Toolkit.
11**
12** This file may be distributed under the terms of the Q Public License
13** as defined by Trolltech AS of Norway and appearing in the file
14** LICENSE.QPL included in the packaging of this file.
15**
16** This file may be distributed and/or modified under the terms of the
17** GNU General Public License version 2 as published by the Free Software
18** Foundation and appearing in the file LICENSE.GPL included in the
19** packaging of this file.
20**
21** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
22** licenses may use this file in accordance with the Qt Commercial License
23** Agreement provided with the Software.
24**
25** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
26** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27**
28** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
29** information about Qt Commercial License Agreements.
30** See http://www.trolltech.com/qpl/ for QPL licensing information.
31** See http://www.trolltech.com/gpl/ for GPL licensing information.
32**
33** Contact info@trolltech.com if any conditions of this licensing are
34** not clear to you.
35**
36**********************************************************************/
37
38#ifndef QTEXTSTREAM_H
39#define QTEXTSTREAM_H
40
41#ifndef QT_H
42#include "qiodevice.h"
43#include "qstring.h"
44#include <stdio.h>
45#endif // QT_H
46
47#ifndef QT_NO_TEXTSTREAM
48class QTextCodec;
49class QTextDecoder;
50
51class QTextStreamPrivate;
52
53 class Q_EXPORT QTextStream // text stream class
54{
55public:
56 enum Encoding { Locale, Latin1, Unicode, UnicodeNetworkOrder,
57 UnicodeReverse, RawUnicode, UnicodeUTF8 };
58
59 voidsetEncoding( Encoding );
60#ifndef QT_NO_TEXTCODEC
61 voidsetCodec( QTextCodec* );
62 QTextCodec *codec();
63#endif
64
65 QTextStream();
66 QTextStream( QIODevice * );
67 QTextStream( QString*, int mode );
68 QTextStream( QString&, int mode ); // obsolete
69 QTextStream( QByteArray, int mode );
70 QTextStream( FILE *, int mode );
71 virtual ~QTextStream();
72
73 QIODevice*device() const;
74 void setDevice( QIODevice * );
75 void unsetDevice();
76
77 bool atEnd() const;
78 bool eof() const;
79
80 QTextStream &operator>>( QChar & );
81 QTextStream &operator>>( char & );
82 QTextStream &operator>>( signed short & );
83 QTextStream &operator>>( unsigned short & );
84 QTextStream &operator>>( signed int & );
85 QTextStream &operator>>( unsigned int & );
86 QTextStream &operator>>( signed long & );
87 QTextStream &operator>>( unsigned long & );
88 QTextStream &operator>>( float & );
89 QTextStream &operator>>( double & );
90 QTextStream &operator>>( char * );
91 QTextStream &operator>>( QString & );
92 QTextStream &operator>>( QCString & );
93
94 QTextStream &operator<<( QChar );
95 QTextStream &operator<<( char );
96 QTextStream &operator<<( signed short );
97 QTextStream &operator<<( unsigned short );
98 QTextStream &operator<<( signed int );
99 QTextStream &operator<<( unsigned int );
100 QTextStream &operator<<( signed long );
101 QTextStream &operator<<( unsigned long );
102 QTextStream &operator<<( float );
103 QTextStream &operator<<( double );
104 QTextStream &operator<<( const char* );
105 QTextStream &operator<<( const QString & );
106 QTextStream &operator<<( const QCString & );
107 QTextStream &operator<<( void * ); // any pointer
108
109 QTextStream &readRawBytes( char *, uint len );
110 QTextStream &writeRawBytes( const char* , uint len );
111
112 QStringreadLine();
113 QStringread();
114 voidskipWhiteSpace();
115
116 enum {
117 skipws = 0x0001, // skip whitespace on input
118 left = 0x0002, // left-adjust output
119 right = 0x0004, // right-adjust output
120 internal = 0x0008, // pad after sign
121 bin = 0x0010, // binary format integer
122 oct = 0x0020, // octal format integer
123 dec = 0x0040, // decimal format integer
124 hex = 0x0080, // hex format integer
125 showbase = 0x0100, // show base indicator
126 showpoint = 0x0200, // force decimal point (float)
127 uppercase = 0x0400, // upper-case hex output
128 showpos = 0x0800, // add '+' to positive integers
129 scientific= 0x1000, // scientific float output
130 fixed = 0x2000 // fixed float output
131 };
132
133 static const int basefield; // bin | oct | dec | hex
134 static const int adjustfield; // left | right | internal
135 static const int floatfield; // scientific | fixed
136
137 int flags() const;
138 int flags( int f );
139 int setf( int bits );
140 int setf( int bits, int mask );
141 int unsetf( int bits );
142
143 void reset();
144
145 int width()const;
146 int width( int );
147 int fill()const;
148 int fill( int );
149 int precision()const;
150 int precision( int );
151
152private:
153 longinput_int();
154 voidinit();
155 QTextStream &output_int( int, ulong, bool );
156 QIODevice*dev;
157
158 int fflags;
159 int fwidth;
160 int fillchar;
161 int fprec;
162 booldoUnicodeHeader;
163 boolowndev;
164 QTextCodec *mapper;
165 QTextStreamPrivate * d;
166 QCharunused1; // ### remove in Qt 4.0
167 boollatin1;
168 bool internalOrder;
169 boolnetworkOrder;
170 void*unused2; // ### remove in Qt 4.0
171
172 QChareat_ws();
173 uint ts_getline( QChar* );
174 voidts_ungetc( QChar );
175 QCharts_getc();
176 uintts_getbuf( QChar*, uint );
177 voidts_putc(int);
178 voidts_putc(QChar);
179 boolts_isspace(QChar);
180 boolts_isdigit(QChar);
181 ulonginput_bin();
182 ulonginput_oct();
183 ulonginput_dec();
184 ulonginput_hex();
185 doubleinput_double();
186 QTextStream &writeBlock( const char* p, uint len );
187 QTextStream &writeBlock( const QChar* p, uint len );
188
189 private:// Disabled copy constructor and operator=
190#if defined(Q_DISABLE_COPY)
191 QTextStream( const QTextStream & );
192 QTextStream &operator=( const QTextStream & );
193#endif
194};
195
196typedef QTextStream QTS;
197
198class Q_EXPORT QTextIStream : public QTextStream {
199public:
200 QTextIStream( const QString* s ) :
201 QTextStream((QString*)s,IO_ReadOnly) { }
202 QTextIStream( QByteArray ba ) :
203 QTextStream(ba,IO_ReadOnly) { }
204 QTextIStream( FILE *f ) :
205 QTextStream(f,IO_ReadOnly) { }
206
207 private:// Disabled copy constructor and operator=
208#if defined(Q_DISABLE_COPY)
209 QTextIStream( const QTextIStream & );
210 QTextIStream &operator=( const QTextIStream & );
211#endif
212};
213
214class Q_EXPORT QTextOStream : public QTextStream {
215public:
216 QTextOStream( QString* s ) :
217 QTextStream(s,IO_WriteOnly) { }
218 QTextOStream( QByteArray ba ) :
219 QTextStream(ba,IO_WriteOnly) { }
220 QTextOStream( FILE *f ) :
221 QTextStream(f,IO_WriteOnly) { }
222
223 private:// Disabled copy constructor and operator=
224#if defined(Q_DISABLE_COPY)
225 QTextOStream( const QTextOStream & );
226 QTextOStream &operator=( const QTextOStream & );
227#endif
228};
229
230/*****************************************************************************
231 QTextStream inline functions
232 *****************************************************************************/
233
234inline QIODevice *QTextStream::device() const
235{ return dev; }
236
237inline bool QTextStream::atEnd() const
238{ return dev ? dev->atEnd() : FALSE; }
239
240inline bool QTextStream::eof() const
241{ return atEnd(); }
242
243inline int QTextStream::flags() const
244{ return fflags; }
245
246inline int QTextStream::flags( int f )
247{ int oldf = fflags; fflags = f; return oldf; }
248
249inline int QTextStream::setf( int bits )
250{ int oldf = fflags; fflags |= bits; return oldf; }
251
252inline int QTextStream::setf( int bits, int mask )
253{ int oldf = fflags; fflags = (fflags & ~mask) | (bits & mask); return oldf; }
254
255inline int QTextStream::unsetf( int bits )
256 { int oldf = fflags; fflags &= ~bits;return oldf; }
257
258inline int QTextStream::width() const
259{ return fwidth; }
260
261inline int QTextStream::width( int w )
262 { int oldw = fwidth; fwidth = w; return oldw; }
263
264inline int QTextStream::fill() const
265{ return fillchar; }
266
267inline int QTextStream::fill( int f )
268 { int oldc = fillchar;fillchar = f; return oldc; }
269
270inline int QTextStream::precision() const
271{ return fprec; }
272
273inline int QTextStream::precision( int p )
274 { int oldp = fprec; fprec = p; return oldp; }
275
276/*!
277 Returns one character from the stream, or EOF.
278*/
279inline QChar QTextStream::ts_getc()
280{ QChar r; return ( ts_getbuf( &r,1 ) == 1 ? r : QChar((ushort)0xffff) ); }
281
282/*****************************************************************************
283 QTextStream manipulators
284 *****************************************************************************/
285
286typedef QTextStream & (*QTSFUNC)(QTextStream &);// manipulator function
287 typedef int (QTextStream::*QTSMFI)(int);// manipulator w/int argument
288
289 class Q_EXPORT QTSManip { // text stream manipulator
290public:
291 QTSManip( QTSMFI m, int a ) { mf=m; arg=a; }
292 void exec( QTextStream &s ) { (s.*mf)(arg); }
293private:
294 QTSMFI mf; // QTextStream member function
295 int arg; // member function argument
296};
297
298Q_EXPORT inline QTextStream &operator>>( QTextStream &s, QTSFUNC f )
299{ return (*f)( s ); }
300
301Q_EXPORT inline QTextStream &operator<<( QTextStream &s, QTSFUNC f )
302{ return (*f)( s ); }
303
304Q_EXPORT inline QTextStream &operator<<( QTextStream &s, QTSManip m )
305{ m.exec(s); return s; }
306
307 Q_EXPORT QTextStream &bin( QTextStream &s );// set bin notation
308 Q_EXPORT QTextStream &oct( QTextStream &s );// set oct notation
309 Q_EXPORT QTextStream &dec( QTextStream &s );// set dec notation
310 Q_EXPORT QTextStream &hex( QTextStream &s );// set hex notation
311 Q_EXPORT QTextStream &endl( QTextStream &s );// insert EOL ('\n')
312 Q_EXPORT QTextStream &flush( QTextStream &s );// flush output
313 Q_EXPORT QTextStream &ws( QTextStream &s );// eat whitespace on input
314 Q_EXPORT QTextStream &reset( QTextStream &s );// set default flags
315
316Q_EXPORT inline QTSManip qSetW( int w )
317{
318 QTSMFI func = &QTextStream::width;
319 return QTSManip(func,w);
320}
321
322Q_EXPORT inline QTSManip qSetFill( int f )
323{
324 QTSMFI func = &QTextStream::fill;
325 return QTSManip(func,f);
326}
327
328Q_EXPORT inline QTSManip qSetPrecision( int p )
329{
330 QTSMFI func = &QTextStream::precision;
331 return QTSManip(func,p);
332}
333
334#endif // QT_NO_TEXTSTREAM
335#endif // QTEXTSTREAM_H