summaryrefslogtreecommitdiffstats
path: root/libkipi/libkipi/KDStream.h
blob: be909dd04a9b9fc860cfbcb744837fb5e17abbcf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
/* -*- Mode: C++ -*-
   KD Tools - a set of useful widgets for TQt
   $Id: KDStream.h 387954 2005-02-10 07:49:40Z blackie $
*/

/****************************************************************************
** Copyright (C) 2001-2005 Klar�lvdalens Datakonsult AB.  All rights reserved.
**
** This file is part of the KD Tools library.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid commercial KD Tools licenses may use this file in
** accordance with the KD Tools Commercial License Agreement provided with
** the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** Contact info@klaralvdalens-datakonsult.se if any conditions of this
** licensing are not clear to you.
**
**********************************************************************/

#ifndef KIPI_KDSTREAM
#define KIPI_KDSTREAM

// Forward declarations.
class TQImage;
class TQPixmap;
class TQColor;
class TQColorGroup;
class TQPalette;
class TQCursor;
class TQDate;
class TQDateTime;
class TQTime;
class TQFont;
class TQPen;
class TQPoint;
class TQSize;
class TQRect;
class TQObject;
class TQVariant;
class TQBrush;
class TQSizePolicy;
class TQKeySequence;

#include <tqstring.h>
#include <tqvaluelist.h>
#include <tqstrlist.h>
#include <tqasciidict.h>
#include <tqintdict.h>
#include <tqptrdict.h>
#include <tqdict.h>
#include <tqvaluestack.h>
#include <tqasciicache.h>
#include <tqintcache.h>
#include <tqcache.h>

#include <tqptrlist.h>
#include <tqptrstack.h>
#include <tqptrqueue.h>
#include <tqpair.h>
#include <tqptrvector.h>
#include <tqvaluevector.h>

// utility functions.
class KDStream;
typedef KDStream & (*KDSTREAMFUNC)(KDStream &);
KDStream& endl( KDStream& stream);
KDStream& flush( KDStream& stream);

class KDStream
{
public:
  KDStream( TQString* outputString = 0);
  ~KDStream();
  void flush();

  // Standard C++ types
  KDStream& operator<<( bool );
  KDStream& operator<<( char );
  KDStream& operator<<( float );
  KDStream& operator<<( double );
  KDStream& operator<<( short );
  KDStream& operator<<( unsigned short );
  KDStream& operator<<( int );
  KDStream& operator<<( unsigned int );
  KDStream& operator<<( long );
  KDStream& operator<<( unsigned long );
  KDStream& operator<<( const char* );
  KDStream& operator<<( const void* );

  // Data holding classes.
  KDStream& operator<<( const TQString& );
  KDStream& operator<<( const TQCString& );
  KDStream& operator<<( const TQChar& );

  KDStream& operator<<( const TQColor& );
  KDStream& operator<<( const TQColorGroup& );
  KDStream& operator<<( const TQPalette& );
  KDStream& operator<<( const TQCursor& );

  KDStream& operator<<( const TQDate& );
  KDStream& operator<<( const TQDateTime& );
  KDStream& operator<<( const TQTime& );

  KDStream& operator<<( const TQFont& );
  KDStream& operator<<( const TQPen& );
  KDStream& operator<<( const TQPoint& );
  KDStream& operator<<( const TQSize& );
  KDStream& operator<<( const TQRect& );
  KDStream& operator<<( const TQBrush& );
  KDStream& operator<<( const TQSizePolicy& );
  KDStream& operator<<( const TQKeySequence& );
  KDStream& operator<<( const TQPixmap& );
  KDStream& operator<<( const TQImage& );

  // misc
  KDStream& operator<<( KDSTREAMFUNC );
  KDStream& operator<<( const TQVariant& );
  KDStream& operator<<( const TQObject& );
  KDStream& operator<<( const TQStrList& list );

protected:
  TQString TQColor2Str( const TQColor& col );

private:
  TQString _output;
  TQString* _out;
};


// Helper functions for KDStream.
// Defined as global functions to support
// compilers without support for member templates
// You should not need to call those yourself
template <class Iterator> void KDStream_valueListStream( KDStream& st, Iterator begin, Iterator end )
{
  st << "[";
  bool first = true;
  for ( Iterator it = begin; it != end; ++it ){
    if ( first )
      first = false;
    else
      st << ", ";
    st << *it;
  }
  st << "]";
}

template<class Iterator> void KDStream_ptrListStream( KDStream& st, Iterator it, bool doubleDeref )
{
  st << "[";
  bool first = true;
  for ( ; *it; ++ it) {
    if ( first )
      first = false;
    else
      st << ", ";

    if ( doubleDeref )
      st << *(*it);
    else {
      // TQStrList ought to be a value list rather than a ptr list, one less dereference is
      // necesary here, otherwise we will only stream out a char, rather than a char *
      st << *it;
    }
  }
  st << "]";
}

template<class Iterator> void KDStream_ptrDictStream( KDStream& st, Iterator it )
{
  st << "{";
  bool first = true;
  for ( ; it; ++ it) {
    if ( first )
      first = false;
    else
      st << ", ";

    st << (it.currentKey()) << ": " << *(it.current()) ;
  }
  st << "}";
}

// Stream operators for containers
// Defined as global functions to support
// compilers without member templates

template<class T> KDStream& operator<<( KDStream& st, const TQValueList<T>& list )
{
  KDStream_valueListStream( st, list.begin(), list.end() );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQMemArray<T>& array )
{
  KDStream_valueListStream( st, array.begin(), array.end() );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQPtrList<T>& list )
{
  KDStream_ptrListStream ( st, TQPtrListIterator<T>( list ), true );
  return st;
}

template<class T1, class T2> KDStream& operator<<( KDStream& st, const TQPair<T1,T2>& pair )
{
  st << "(" << pair.first << "," << pair.second << ")";
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQPtrVector<T>& vector )
{
  TQPtrList<T> list;
  vector.toList( &list );

  KDStream_ptrListStream( st, TQPtrListIterator<T>( list ), true );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQValueVector<T>& vector )
{
  KDStream_valueListStream( st, vector.begin(), vector.end() );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQPtrStack<T>& stack )
{

  // I need a copy to look at the individual elements.
  TQPtrStack<T> copy(stack);
  /*}*/

  st << "[";
  if ( stack.count() > 1 )
    st << "top| ";
  st << " ";

  bool first = true;
  while ( !copy.isEmpty() ) {
    if (first)
      first = false;
    else
      st << ", ";
    st << *(copy.pop());
  }

  st << " ";
  if (  stack.count() > 1 )
    st << " |bottom";
  st << "]";
  return st;
}

// This function can unfortunately not be merged with the function for
// Q(Ptr)Stack, as the Q(Ptr)Stack dereferences what it pops of the stack,
// before streaming it:
// Q(Ptr)Stack: *this << *(copy.pop());
// TQValueStack: *this <<   copy.pop() ;
template<class T> KDStream& operator<<( KDStream& st, const TQValueStack<T>& stack )
{
  // I need a copy to look at the individual elements.
  TQValueStack<T> copy(stack);
  st << "[";
  if ( stack.count() > 1 )
    st << "top| ";
  st << " ";

  bool first = true;
  while ( !copy.isEmpty() ) {
    if (first)
      first = false;
    else
      st << ", ";
    st << copy.pop();
  }

  st << " ";
  if (  stack.count() > 1 )
    st << " |bottom";
  st << "]";
  return st;
}


template<class T> KDStream& operator<<( KDStream& st, const TQAsciiDict<T>& dict )
{
  KDStream_ptrDictStream( st, TQAsciiDictIterator<T>( dict ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQIntDict<T>& dict )
{
  KDStream_ptrDictStream( st, TQIntDictIterator<T>( dict ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQPtrDict<T>& dict )
{
  KDStream_ptrDictStream( st, TQPtrDictIterator<T>( dict ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQDict<T>& dict )
{
  KDStream_ptrDictStream( st, TQDictIterator<T>( dict ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQAsciiCache<T>& cache )
{
  KDStream_ptrDictStream( st, TQAsciiCacheIterator<T>( cache ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQIntCache<T>& cache )
{
  KDStream_ptrDictStream( st, TQIntCacheIterator<T>( cache ) );
  return st;
}

template<class T> KDStream& operator<<( KDStream& st, const TQCache<T>& cache )
{
  KDStream_ptrDictStream( st, TQCacheIterator<T>( cache ) );
  return st;
}

#endif /* KDStream */