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 #ifndef KIPI_KDSTREAM
00029 #define KIPI_KDSTREAM
00030
00031
00032 class QImage;
00033 class QPixmap;
00034 class QColor;
00035 class QColorGroup;
00036 class QPalette;
00037 class QCursor;
00038 class QDate;
00039 class QDateTime;
00040 class QTime;
00041 class QFont;
00042 class QPen;
00043 class QPoint;
00044 class QSize;
00045 class QRect;
00046 class QObject;
00047 class QVariant;
00048 class QBrush;
00049 class QSizePolicy;
00050 class QKeySequence;
00051
00052 #include <qstring.h>
00053 #include <qvaluelist.h>
00054 #include <qstrlist.h>
00055 #include <qasciidict.h>
00056 #include <qintdict.h>
00057 #include <qptrdict.h>
00058 #include <qdict.h>
00059 #include <qvaluestack.h>
00060 #include <qasciicache.h>
00061 #include <qintcache.h>
00062 #include <qcache.h>
00063
00064 #if ( QT_VERSION < 300 )
00065 #include <qlist.h>
00066 #include <qstack.h>
00067 #include <qqueue.h>
00068 #include <qvector.h>
00069 #endif
00070
00071 #if ( QT_VERSION >= 300 )
00072 #include <qptrlist.h>
00073 #include <qptrstack.h>
00074 #include <qptrqueue.h>
00075 #include <qpair.h>
00076 #include <qptrvector.h>
00077 #include <qvaluevector.h>
00078 #endif
00079
00080
00081 class KDStream;
00082 typedef KDStream & (*KDSTREAMFUNC)(KDStream &);
00083 KDStream& endl( KDStream& stream);
00084 KDStream& flush( KDStream& stream);
00085
00086 class KDStream
00087 {
00088 public:
00089 KDStream( QString* outputString = 0);
00090 ~KDStream();
00091 void flush();
00092
00093
00094 KDStream& operator<<( bool );
00095 KDStream& operator<<( char );
00096 KDStream& operator<<( float );
00097 KDStream& operator<<( double );
00098 KDStream& operator<<( short );
00099 KDStream& operator<<( unsigned short );
00100 KDStream& operator<<( int );
00101 KDStream& operator<<( unsigned int );
00102 KDStream& operator<<( long );
00103 KDStream& operator<<( unsigned long );
00104 KDStream& operator<<( const char* );
00105 KDStream& operator<<( const void* );
00106
00107
00108 KDStream& operator<<( const QString& );
00109 KDStream& operator<<( const QCString& );
00110 KDStream& operator<<( const QChar& );
00111
00112 KDStream& operator<<( const QColor& );
00113 KDStream& operator<<( const QColorGroup& );
00114 KDStream& operator<<( const QPalette& );
00115 KDStream& operator<<( const QCursor& );
00116
00117 KDStream& operator<<( const QDate& );
00118 KDStream& operator<<( const QDateTime& );
00119 KDStream& operator<<( const QTime& );
00120
00121 KDStream& operator<<( const QFont& );
00122 KDStream& operator<<( const QPen& );
00123 KDStream& operator<<( const QPoint& );
00124 KDStream& operator<<( const QSize& );
00125 KDStream& operator<<( const QRect& );
00126 KDStream& operator<<( const QBrush& );
00127 KDStream& operator<<( const QSizePolicy& );
00128 KDStream& operator<<( const QKeySequence& );
00129 KDStream& operator<<( const QPixmap& );
00130 KDStream& operator<<( const QImage& );
00131
00132
00133 KDStream& operator<<( KDSTREAMFUNC );
00134 KDStream& operator<<( const QVariant& );
00135 KDStream& operator<<( const QObject& );
00136 KDStream& operator<<( const QStrList& list );
00137
00138 protected:
00139 QString QColor2Str( const QColor& col );
00140
00141 private:
00142 QString _output;
00143 QString* _out;
00144 };
00145
00146
00147
00148
00149
00150
00151 template <class Iterator> void KDStream_valueListStream( KDStream& st, Iterator begin, Iterator end )
00152 {
00153 st << "[";
00154 bool first = true;
00155 for ( Iterator it = begin; it != end; ++it ){
00156 if ( first )
00157 first = false;
00158 else
00159 st << ", ";
00160 st << *it;
00161 }
00162 st << "]";
00163 }
00164
00165 template<class Iterator> void KDStream_ptrListStream( KDStream& st, Iterator it, bool doubleDeref )
00166 {
00167 st << "[";
00168 bool first = true;
00169 for ( ; *it; ++ it) {
00170 if ( first )
00171 first = false;
00172 else
00173 st << ", ";
00174
00175 if ( doubleDeref )
00176 st << *(*it);
00177 else {
00178
00179
00180 st << *it;
00181 }
00182 }
00183 st << "]";
00184 }
00185
00186 template<class Iterator> void KDStream_ptrDictStream( KDStream& st, Iterator it )
00187 {
00188 st << "{";
00189 bool first = true;
00190 for ( ; it; ++ it) {
00191 if ( first )
00192 first = false;
00193 else
00194 st << ", ";
00195
00196 st << (it.currentKey()) << ": " << *(it.current()) ;
00197 }
00198 st << "}";
00199 }
00200
00201
00202
00203
00204
00205 template<class T> KDStream& operator<<( KDStream& st, const QValueList<T>& list )
00206 {
00207 KDStream_valueListStream( st, list.begin(), list.end() );
00208 return st;
00209 }
00210
00211 #if ( QT_VERSION < 300 )
00212 template<class T> KDStream& operator<<( KDStream& st, const QList<T>& list )
00213 {
00214 KDStream_ptrListStream ( st, QListIterator<T>( list ) , true );
00215 return st;
00216 }
00217
00218 template<class T> KDStream& operator<<( KDStream& st, const QArray<T>& array )
00219 {
00220 KDStream_valueListStream( st, array.begin(), array.end() );
00221 return st;
00222 }
00223
00224 template<class T> KDStream& operator<<( KDStream& st, const QVector<T>& vector )
00225 {
00226 QList<T> list;
00227 vector.toList( &list );
00228
00229 KDStream_ptrListStream ( st, QListIterator<T>( list ), true );
00230 return st;
00231 }
00232 #endif
00233 #if ( QT_VERSION >= 300 )
00234 template<class T> KDStream& operator<<( KDStream& st, const QMemArray<T>& array )
00235 {
00236 KDStream_valueListStream( st, array.begin(), array.end() );
00237 return st;
00238 }
00239
00240 template<class T> KDStream& operator<<( KDStream& st, const QPtrList<T>& list )
00241 {
00242 KDStream_ptrListStream ( st, QPtrListIterator<T>( list ), true );
00243 return st;
00244 }
00245
00246 template<class T1, class T2> KDStream& operator<<( KDStream& st, const QPair<T1,T2>& pair )
00247 {
00248 st << "(" << pair.first << "," << pair.second << ")";
00249 return st;
00250 }
00251
00252 template<class T> KDStream& operator<<( KDStream& st, const QPtrVector<T>& vector )
00253 {
00254 QPtrList<T> list;
00255 vector.toList( &list );
00256
00257 KDStream_ptrListStream( st, QPtrListIterator<T>( list ), true );
00258 return st;
00259 }
00260
00261 template<class T> KDStream& operator<<( KDStream& st, const QValueVector<T>& vector )
00262 {
00263 KDStream_valueListStream( st, vector.begin(), vector.end() );
00264 return st;
00265 }
00266 #endif
00267
00268 #if ( QT_VERSION < 300 )
00269 template<class T> KDStream& operator<<( KDStream& st, const QStack<T>& stack )
00270 {
00271
00272 QStack<T> copy(stack);
00273 #else
00274 template<class T> KDStream& operator<<( KDStream& st, const QPtrStack<T>& stack )
00275 {
00276
00277
00278 QPtrStack<T> copy(stack);
00279
00280 #endif
00281 st << "[";
00282 if ( stack.count() > 1 )
00283 st << "top| ";
00284 st << " ";
00285
00286 bool first = true;
00287 while ( !copy.isEmpty() ) {
00288 if (first)
00289 first = false;
00290 else
00291 st << ", ";
00292 st << *(copy.pop());
00293 }
00294
00295 st << " ";
00296 if ( stack.count() > 1 )
00297 st << " |bottom";
00298 st << "]";
00299 return st;
00300 }
00301
00302
00303
00304
00305
00306
00307 template<class T> KDStream& operator<<( KDStream& st, const QValueStack<T>& stack )
00308 {
00309
00310 QValueStack<T> copy(stack);
00311 st << "[";
00312 if ( stack.count() > 1 )
00313 st << "top| ";
00314 st << " ";
00315
00316 bool first = true;
00317 while ( !copy.isEmpty() ) {
00318 if (first)
00319 first = false;
00320 else
00321 st << ", ";
00322 st << copy.pop();
00323 }
00324
00325 st << " ";
00326 if ( stack.count() > 1 )
00327 st << " |bottom";
00328 st << "]";
00329 return st;
00330 }
00331
00332
00333 template<class T> KDStream& operator<<( KDStream& st, const QAsciiDict<T>& dict )
00334 {
00335 KDStream_ptrDictStream( st, QAsciiDictIterator<T>( dict ) );
00336 return st;
00337 }
00338
00339 template<class T> KDStream& operator<<( KDStream& st, const QIntDict<T>& dict )
00340 {
00341 KDStream_ptrDictStream( st, QIntDictIterator<T>( dict ) );
00342 return st;
00343 }
00344
00345 template<class T> KDStream& operator<<( KDStream& st, const QPtrDict<T>& dict )
00346 {
00347 KDStream_ptrDictStream( st, QPtrDictIterator<T>( dict ) );
00348 return st;
00349 }
00350
00351 template<class T> KDStream& operator<<( KDStream& st, const QDict<T>& dict )
00352 {
00353 KDStream_ptrDictStream( st, QDictIterator<T>( dict ) );
00354 return st;
00355 }
00356
00357 template<class T> KDStream& operator<<( KDStream& st, const QAsciiCache<T>& cache )
00358 {
00359 KDStream_ptrDictStream( st, QAsciiCacheIterator<T>( cache ) );
00360 return st;
00361 }
00362
00363 template<class T> KDStream& operator<<( KDStream& st, const QIntCache<T>& cache )
00364 {
00365 KDStream_ptrDictStream( st, QIntCacheIterator<T>( cache ) );
00366 return st;
00367 }
00368
00369 template<class T> KDStream& operator<<( KDStream& st, const QCache<T>& cache )
00370 {
00371 KDStream_ptrDictStream( st, QCacheIterator<T>( cache ) );
00372 return st;
00373 }
00374
00375 #endif