Eneboo - Documentación para desarrolladores
src/qt/src/tools/qtextstream.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qtextstream.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QTextStream class
00005 **
00006 ** Created : 940922
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the tools module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
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                              // text stream class
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 );          // obsolete
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 * );          // any pointer
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,                     // skip whitespace on input
00118         left      = 0x0002,                     // left-adjust output
00119         right     = 0x0004,                     // right-adjust output
00120         internal  = 0x0008,                     // pad after sign
00121         bin       = 0x0010,                     // binary format integer
00122         oct       = 0x0020,                     // octal format integer
00123         dec       = 0x0040,                     // decimal format integer
00124         hex       = 0x0080,                     // hex format integer
00125         showbase  = 0x0100,                     // show base indicator
00126         showpoint = 0x0200,                     // force decimal point (float)
00127         uppercase = 0x0400,                     // upper-case hex output
00128         showpos   = 0x0800,                     // add '+' to positive integers
00129         scientific= 0x1000,                     // scientific float output
00130         fixed     = 0x2000                      // fixed float output
00131     };
00132 
00133     static const int basefield;                 // bin | oct | dec | hex
00134     static const int adjustfield;               // left | right | internal
00135     static const int floatfield;                // scientific | fixed
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; // ### remove in Qt 4.0
00167     bool        latin1;
00168     bool        internalOrder;
00169     bool        networkOrder;
00170     void        *unused2; // ### remove in Qt 4.0
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:        // Disabled copy constructor and operator=
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:        // Disabled copy constructor and operator=
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:        // Disabled copy constructor and operator=
00224 #if defined(Q_DISABLE_COPY)
00225     QTextOStream( const QTextOStream & );
00226     QTextOStream &operator=( const QTextOStream & );
00227 #endif
00228 };
00229 
00230 /*****************************************************************************
00231   QTextStream inline functions
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   QTextStream manipulators
00284  *****************************************************************************/
00285 
00286 typedef QTextStream & (*QTSFUNC)(QTextStream &);// manipulator function
00287 typedef int (QTextStream::*QTSMFI)(int);        // manipulator w/int argument
00288 
00289 class Q_EXPORT QTSManip {                       // text stream manipulator
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;                                  // QTextStream member function
00295     int    arg;                                 // member function argument
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 );    // set bin notation
00308 Q_EXPORT QTextStream &oct( QTextStream &s );    // set oct notation
00309 Q_EXPORT QTextStream &dec( QTextStream &s );    // set dec notation
00310 Q_EXPORT QTextStream &hex( QTextStream &s );    // set hex notation
00311 Q_EXPORT QTextStream &endl( QTextStream &s );   // insert EOL ('\n')
00312 Q_EXPORT QTextStream &flush( QTextStream &s );  // flush output
00313 Q_EXPORT QTextStream &ws( QTextStream &s );     // eat whitespace on input
00314 Q_EXPORT QTextStream &reset( QTextStream &s );  // set default flags
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
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'