00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef QTEXTSTREAM_H
00039 #define QTEXTSTREAM_H
00040
00041 #ifndef QT_H
00042 #include "qiodevice.h"
00043 #include "qstring.h"
00044 #include <stdio.h>
00045 #endif // QT_H
00046
00047 #ifndef QT_NO_TEXTSTREAM
00048 class QTextCodec;
00049 class QTextDecoder;
00050
00051 class QTextStreamPrivate;
00052
00053 class Q_EXPORT QTextStream
00054 {
00055 public:
00056 enum Encoding { Locale, Latin1, Unicode, UnicodeNetworkOrder,
00057 UnicodeReverse, RawUnicode, UnicodeUTF8 };
00058
00059 void setEncoding( Encoding );
00060 #ifndef QT_NO_TEXTCODEC
00061 void setCodec( QTextCodec* );
00062 QTextCodec *codec();
00063 #endif
00064
00065 QTextStream();
00066 QTextStream( QIODevice * );
00067 QTextStream( QString*, int mode );
00068 QTextStream( QString&, int mode );
00069 QTextStream( QByteArray, int mode );
00070 QTextStream( FILE *, int mode );
00071 virtual ~QTextStream();
00072
00073 QIODevice *device() const;
00074 void setDevice( QIODevice * );
00075 void unsetDevice();
00076
00077 bool atEnd() const;
00078 bool eof() const;
00079
00080 QTextStream &operator>>( QChar & );
00081 QTextStream &operator>>( char & );
00082 QTextStream &operator>>( signed short & );
00083 QTextStream &operator>>( unsigned short & );
00084 QTextStream &operator>>( signed int & );
00085 QTextStream &operator>>( unsigned int & );
00086 QTextStream &operator>>( signed long & );
00087 QTextStream &operator>>( unsigned long & );
00088 QTextStream &operator>>( float & );
00089 QTextStream &operator>>( double & );
00090 QTextStream &operator>>( char * );
00091 QTextStream &operator>>( QString & );
00092 QTextStream &operator>>( QCString & );
00093
00094 QTextStream &operator<<( QChar );
00095 QTextStream &operator<<( char );
00096 QTextStream &operator<<( signed short );
00097 QTextStream &operator<<( unsigned short );
00098 QTextStream &operator<<( signed int );
00099 QTextStream &operator<<( unsigned int );
00100 QTextStream &operator<<( signed long );
00101 QTextStream &operator<<( unsigned long );
00102 QTextStream &operator<<( float );
00103 QTextStream &operator<<( double );
00104 QTextStream &operator<<( const char* );
00105 QTextStream &operator<<( const QString & );
00106 QTextStream &operator<<( const QCString & );
00107 QTextStream &operator<<( void * );
00108
00109 QTextStream &readRawBytes( char *, uint len );
00110 QTextStream &writeRawBytes( const char* , uint len );
00111
00112 QString readLine();
00113 QString read();
00114 void skipWhiteSpace();
00115
00116 enum {
00117 skipws = 0x0001,
00118 left = 0x0002,
00119 right = 0x0004,
00120 internal = 0x0008,
00121 bin = 0x0010,
00122 oct = 0x0020,
00123 dec = 0x0040,
00124 hex = 0x0080,
00125 showbase = 0x0100,
00126 showpoint = 0x0200,
00127 uppercase = 0x0400,
00128 showpos = 0x0800,
00129 scientific= 0x1000,
00130 fixed = 0x2000
00131 };
00132
00133 static const int basefield;
00134 static const int adjustfield;
00135 static const int floatfield;
00136
00137 int flags() const;
00138 int flags( int f );
00139 int setf( int bits );
00140 int setf( int bits, int mask );
00141 int unsetf( int bits );
00142
00143 void reset();
00144
00145 int width() const;
00146 int width( int );
00147 int fill() const;
00148 int fill( int );
00149 int precision() const;
00150 int precision( int );
00151
00152 private:
00153 long input_int();
00154 void init();
00155 QTextStream &output_int( int, ulong, bool );
00156 QIODevice *dev;
00157
00158 int fflags;
00159 int fwidth;
00160 int fillchar;
00161 int fprec;
00162 bool doUnicodeHeader;
00163 bool owndev;
00164 QTextCodec *mapper;
00165 QTextStreamPrivate * d;
00166 QChar unused1;
00167 bool latin1;
00168 bool internalOrder;
00169 bool networkOrder;
00170 void *unused2;
00171
00172 QChar eat_ws();
00173 uint ts_getline( QChar* );
00174 void ts_ungetc( QChar );
00175 QChar ts_getc();
00176 uint ts_getbuf( QChar*, uint );
00177 void ts_putc(int);
00178 void ts_putc(QChar);
00179 bool ts_isspace(QChar);
00180 bool ts_isdigit(QChar);
00181 ulong input_bin();
00182 ulong input_oct();
00183 ulong input_dec();
00184 ulong input_hex();
00185 double input_double();
00186 QTextStream &writeBlock( const char* p, uint len );
00187 QTextStream &writeBlock( const QChar* p, uint len );
00188
00189 private:
00190 #if defined(Q_DISABLE_COPY)
00191 QTextStream( const QTextStream & );
00192 QTextStream &operator=( const QTextStream & );
00193 #endif
00194 };
00195
00196 typedef QTextStream QTS;
00197
00198 class Q_EXPORT QTextIStream : public QTextStream {
00199 public:
00200 QTextIStream( const QString* s ) :
00201 QTextStream((QString*)s,IO_ReadOnly) { }
00202 QTextIStream( QByteArray ba ) :
00203 QTextStream(ba,IO_ReadOnly) { }
00204 QTextIStream( FILE *f ) :
00205 QTextStream(f,IO_ReadOnly) { }
00206
00207 private:
00208 #if defined(Q_DISABLE_COPY)
00209 QTextIStream( const QTextIStream & );
00210 QTextIStream &operator=( const QTextIStream & );
00211 #endif
00212 };
00213
00214 class Q_EXPORT QTextOStream : public QTextStream {
00215 public:
00216 QTextOStream( QString* s ) :
00217 QTextStream(s,IO_WriteOnly) { }
00218 QTextOStream( QByteArray ba ) :
00219 QTextStream(ba,IO_WriteOnly) { }
00220 QTextOStream( FILE *f ) :
00221 QTextStream(f,IO_WriteOnly) { }
00222
00223 private:
00224 #if defined(Q_DISABLE_COPY)
00225 QTextOStream( const QTextOStream & );
00226 QTextOStream &operator=( const QTextOStream & );
00227 #endif
00228 };
00229
00230
00231
00232
00233
00234 inline QIODevice *QTextStream::device() const
00235 { return dev; }
00236
00237 inline bool QTextStream::atEnd() const
00238 { return dev ? dev->atEnd() : FALSE; }
00239
00240 inline bool QTextStream::eof() const
00241 { return atEnd(); }
00242
00243 inline int QTextStream::flags() const
00244 { return fflags; }
00245
00246 inline int QTextStream::flags( int f )
00247 { int oldf = fflags; fflags = f; return oldf; }
00248
00249 inline int QTextStream::setf( int bits )
00250 { int oldf = fflags; fflags |= bits; return oldf; }
00251
00252 inline int QTextStream::setf( int bits, int mask )
00253 { int oldf = fflags; fflags = (fflags & ~mask) | (bits & mask); return oldf; }
00254
00255 inline int QTextStream::unsetf( int bits )
00256 { int oldf = fflags; fflags &= ~bits; return oldf; }
00257
00258 inline int QTextStream::width() const
00259 { return fwidth; }
00260
00261 inline int QTextStream::width( int w )
00262 { int oldw = fwidth; fwidth = w; return oldw; }
00263
00264 inline int QTextStream::fill() const
00265 { return fillchar; }
00266
00267 inline int QTextStream::fill( int f )
00268 { int oldc = fillchar; fillchar = f; return oldc; }
00269
00270 inline int QTextStream::precision() const
00271 { return fprec; }
00272
00273 inline int QTextStream::precision( int p )
00274 { int oldp = fprec; fprec = p; return oldp; }
00275
00279 inline QChar QTextStream::ts_getc()
00280 { QChar r; return ( ts_getbuf( &r,1 ) == 1 ? r : QChar((ushort)0xffff) ); }
00281
00282
00283
00284
00285
00286 typedef QTextStream & (*QTSFUNC)(QTextStream &);
00287 typedef int (QTextStream::*QTSMFI)(int);
00288
00289 class Q_EXPORT QTSManip {
00290 public:
00291 QTSManip( QTSMFI m, int a ) { mf=m; arg=a; }
00292 void exec( QTextStream &s ) { (s.*mf)(arg); }
00293 private:
00294 QTSMFI mf;
00295 int arg;
00296 };
00297
00298 Q_EXPORT inline QTextStream &operator>>( QTextStream &s, QTSFUNC f )
00299 { return (*f)( s ); }
00300
00301 Q_EXPORT inline QTextStream &operator<<( QTextStream &s, QTSFUNC f )
00302 { return (*f)( s ); }
00303
00304 Q_EXPORT inline QTextStream &operator<<( QTextStream &s, QTSManip m )
00305 { m.exec(s); return s; }
00306
00307 Q_EXPORT QTextStream &bin( QTextStream &s );
00308 Q_EXPORT QTextStream &oct( QTextStream &s );
00309 Q_EXPORT QTextStream &dec( QTextStream &s );
00310 Q_EXPORT QTextStream &hex( QTextStream &s );
00311 Q_EXPORT QTextStream &endl( QTextStream &s );
00312 Q_EXPORT QTextStream &flush( QTextStream &s );
00313 Q_EXPORT QTextStream &ws( QTextStream &s );
00314 Q_EXPORT QTextStream &reset( QTextStream &s );
00315
00316 Q_EXPORT inline QTSManip qSetW( int w )
00317 {
00318 QTSMFI func = &QTextStream::width;
00319 return QTSManip(func,w);
00320 }
00321
00322 Q_EXPORT inline QTSManip qSetFill( int f )
00323 {
00324 QTSMFI func = &QTextStream::fill;
00325 return QTSManip(func,f);
00326 }
00327
00328 Q_EXPORT inline QTSManip qSetPrecision( int p )
00329 {
00330 QTSMFI func = &QTextStream::precision;
00331 return QTSManip(func,p);
00332 }
00333
00334 #endif // QT_NO_TEXTSTREAM
00335 #endif // QTEXTSTREAM_H