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
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
|
/* This file is part of the KDE libraries
Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
2000-2002 Stephan Kulow (coolo@kde.org)
2002 Holger Freyther (freyther@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _KDEBUG_H_
#define _KDEBUG_H_
#include <tqstring.h>
#include "tdelibs_export.h"
class TQWidget;
class TQDateTime;
class TQDate;
class TQTime;
class TQPoint;
class TQSize;
class TQRect;
class TQRegion;
class KURL;
class TQStringList;
class TQColor;
class TQPen;
class TQBrush;
class TQVariant;
template <class T>
class TQValueList;
class kdbgstream;
class kndbgstream;
/**
* \addtogroup kdebug Debug message generators
* @{
* KDE debug message streams let you and the user control just how many debug
* messages you see.
*/
typedef kdbgstream & (*KDBGFUNC)(kdbgstream &); // manipulator function
typedef kndbgstream & (*KNDBGFUNC)(kndbgstream &); // manipulator function
#ifdef __GNUC__
#define k_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
#else
#define k_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
#endif
#define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
class kdbgstreamprivate;
/**
* kdbgstream is a text stream that allows you to print debug messages.
* Using the overloaded "<<" operator you can send messages. Usually
* you do not create the kdbgstream yourself, but use kdDebug()
* kdWarning(), kdError() or kdFatal to obtain one.
*
* Example:
* \code
* int i = 5;
* kdDebug() << "The value of i is " << i << endl;
* \endcode
* @see kndbgstream
*/
class TDECORE_EXPORT kdbgstream {
public:
/**
* @internal
*/
kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
area(_area), level(_level), print(_print) { }
kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) :
output(TQString::fromLatin1(initialString)), area(_area), level(_level), print(_print) { }
/// Copy constructor
kdbgstream(kdbgstream &str);
kdbgstream(const kdbgstream &str) :
output(str.output), area(str.area), level(str.level), print(str.print) {}
~kdbgstream();
/**
* Prints the given value.
* @param i the boolean to print (as "true" or "false")
* @return this stream
*/
kdbgstream &operator<<(bool i) {
if (!print) return *this;
output += TQString::fromLatin1(i ? "true" : "false");
return *this;
}
/**
* Prints the given value.
* @param i the short to print
* @return this stream
*/
kdbgstream &operator<<(short i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the unsigned short to print
* @return this stream
*/
kdbgstream &operator<<(unsigned short i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param ch the char to print
* @return this stream
*/
kdbgstream &operator<<(char ch);
/**
* Prints the given value.
* @param ch the unsigned char to print
* @return this stream
*/
kdbgstream &operator<<(unsigned char ch) {
return operator<<( static_cast<char>( ch ) );
}
/**
* Prints the given value.
* @param i the int to print
* @return this stream
*/
kdbgstream &operator<<(int i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the unsigned int to print
* @return this stream
*/
kdbgstream &operator<<(unsigned int i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the long to print
* @return this stream
*/
kdbgstream &operator<<(long i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the unsigned long to print
* @return this stream
*/
kdbgstream &operator<<(unsigned long i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the long long to print
* @return this stream
*/
kdbgstream &operator<<(TQ_LLONG i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Prints the given value.
* @param i the unsigned long long to print
* @return this stream
*/
kdbgstream &operator<<(TQ_ULLONG i) {
if (!print) return *this;
TQString tmp; tmp.setNum(i); output += tmp;
return *this;
}
/**
* Flushes the output.
*/
void flush(); //AB: maybe this should be virtual! would save some trouble for some 3rd party projects
/**
* Prints the given value.
* @param ch the char to print
* @return this stream
* @since 3.3
*/
kdbgstream &operator<<(TQChar ch);
/**
* Prints the given value.
* @param string the string to print
* @return this stream
*/
kdbgstream &operator<<(const TQString& string) {
if (!print) return *this;
output += string;
if (output.at(output.length() -1 ) == (TQChar)'\n')
flush();
return *this;
}
/**
* Prints the given value.
* @param string the string to print
* @return this stream
*/
kdbgstream &operator<<(const char *string) {
if (!print) return *this;
output += TQString::fromUtf8(string);
if (output.at(output.length() - 1) == (TQChar)'\n')
flush();
return *this;
}
/**
* Prints the given value.
* @param string the string to print
* @return this stream
*/
kdbgstream &operator<<(const TQCString& string) {
*this << string.data();
return *this;
}
/**
* Prints the given value.
* @param p a pointer to print (in number form)
* @return this stream
*/
kdbgstream& operator<<(const void * p) {
form("%p", p);
return *this;
}
/**
* Invokes the given function.
* @param f the function to invoke
* @return the return value of @p f
*/
kdbgstream& operator<<(KDBGFUNC f) {
if (!print) return *this;
return (*f)(*this);
}
/**
* Prints the given value.
* @param d the double to print
* @return this stream
*/
kdbgstream& operator<<(double d) {
TQString tmp; tmp.setNum(d); output += tmp;
return *this;
}
/**
* Prints the string @p format which can contain
* printf-style formatted values.
* @param format the printf-style format
* @return this stream
*/
kdbgstream &form(const char *format, ...)
#ifdef __GNUC__
__attribute__ ( ( format ( printf, 2, 3 ) ) )
#endif
;
/** Operator to print out basic information about a TQWidget.
* Output of class names only works if the class is moc'ified.
* @param widget the widget to print
* @return this stream
*/
kdbgstream& operator << (const TQWidget* widget);
kdbgstream& operator << (TQWidget* widget); // KDE4 merge
/**
* Prints the given value.
* @param dateTime the datetime to print
* @return this stream
*/
kdbgstream& operator << ( const TQDateTime& dateTime );
/**
* Prints the given value.
* @param date the date to print
* @return this stream
*/
kdbgstream& operator << ( const TQDate& date );
/**
* Prints the given value.
* @param time the time to print
* @return this stream
*/
kdbgstream& operator << ( const TQTime& time );
/**
* Prints the given value.
* @param point the point to print
* @return this stream
*/
kdbgstream& operator << ( const TQPoint& point );
/**
* Prints the given value.
* @param size the TQSize to print
* @return this stream
*/
kdbgstream& operator << ( const TQSize& size );
/**
* Prints the given value.
* @param rect the TQRect to print
* @return this stream
*/
kdbgstream& operator << ( const TQRect& rect);
/**
* Prints the given value.
* @param region the TQRegion to print
* @return this stream
*/
kdbgstream& operator << ( const TQRegion& region);
/**
* Prints the given value.
* @param url the url to print
* @return this stream
*/
kdbgstream& operator << ( const KURL& url );
/**
* Prints the given value.
* @param list the stringlist to print
* @return this stream
*/
// ### KDE4: Remove in favor of template operator for TQValueList<T> below
kdbgstream& operator << ( const TQStringList& list);
/**
* Prints the given value.
* @param color the color to print
* @return this stream
*/
kdbgstream& operator << ( const TQColor& color);
/**
* Prints the given value.
* @param pen the pen to print
* @return this stream
* @since 3.2
*/
kdbgstream& operator << ( const TQPen& pen );
/**
* Prints the given value.
* @param brush the brush to print
* @return this stream
*/
kdbgstream& operator << ( const TQBrush& brush );
/**
* Prints the given value.
* @param variant the variant to print
* @return this stream
* @since 3.3
*/
kdbgstream& operator << ( const TQVariant& variant );
/**
* Prints the given value.
* @param data the byte array to print
* @return this stream
* @since 3.3
*/
kdbgstream& operator << ( const TQByteArray& data );
/**
* Prints the given value
* @param list the list to print
* @return this stream
* @since 3.3
*/
template <class T>
kdbgstream& operator << ( const TQValueList<T> &list );
private:
TQString output;
unsigned int area, level;
bool print;
kdbgstreamprivate* d;
};
template <class T>
kdbgstream &kdbgstream::operator<<( const TQValueList<T> &list )
{
*this << "(";
typename TQValueList<T>::ConstIterator it = list.begin();
if ( !list.isEmpty() ) {
*this << *it++;
}
for ( ; it != list.end(); ++it ) {
*this << "," << *it;
}
*this << ")";
return *this;
}
/**
* \relates TDEGlobal
* Prints an "\n".
* @param s the debug stream to write to
* @return the debug stream (@p s)
*/
inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
/**
* \relates TDEGlobal
* Flushes the stream.
* @param s the debug stream to write to
* @return the debug stream (@p s)
*/
inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; }
TDECORE_EXPORT kdbgstream &perror( kdbgstream &s);
/**
* \relates TDEGlobal
* kndbgstream is a dummy variant of kdbgstream. All functions do
* nothing.
* @see kndDebug()
*/
class TDECORE_EXPORT kndbgstream {
public:
/// Default constructor.
kndbgstream() {}
~kndbgstream() {}
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(short int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(unsigned short int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(char ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(unsigned char ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(int ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(unsigned int ) { return *this; }
/**
* Does nothing.
*/
void flush() {}
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(TQChar) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(const TQString& ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(const TQCString& ) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream &operator<<(const char *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(const void *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(void *) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(double) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(long) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(unsigned long) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(TQ_LLONG) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(TQ_ULLONG) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator<<(KNDBGFUNC) { return *this; }
/**
* Does nothing.
* @return this stream
*/
kndbgstream& operator << (const TQWidget*) { return *this; }
kndbgstream& operator << (TQWidget*) { return *this; } // KDE4 merge
/**
* Does nothing.
* @return this stream
*/
kndbgstream &form(const char *, ...) { return *this; }
kndbgstream& operator<<( const TQDateTime& ) { return *this; }
kndbgstream& operator<<( const TQDate& ) { return *this; }
kndbgstream& operator<<( const TQTime& ) { return *this; }
kndbgstream& operator<<( const TQPoint & ) { return *this; }
kndbgstream& operator<<( const TQSize & ) { return *this; }
kndbgstream& operator<<( const TQRect & ) { return *this; }
kndbgstream& operator<<( const TQRegion & ) { return *this; }
kndbgstream& operator<<( const KURL & ) { return *this; }
kndbgstream& operator<<( const TQStringList & ) { return *this; }
kndbgstream& operator<<( const TQColor & ) { return *this; }
kndbgstream& operator<<( const TQPen & ) { return *this; }
kndbgstream& operator<<( const TQBrush & ) { return *this; }
kndbgstream& operator<<( const TQVariant & ) { return *this; }
kndbgstream& operator<<( const TQByteArray & ) { return *this; }
template <class T>
kndbgstream& operator<<( const TQValueList<T> & ) { return *this; }
};
/**
* Does nothing.
* @param s a stream
* @return the given @p s
*/
inline kndbgstream &endl( kndbgstream & s) { return s; }
/**
* Does nothing.
* @param s a stream
* @return the given @p s
*/
inline kndbgstream &flush( kndbgstream & s) { return s; }
inline kndbgstream &perror( kndbgstream & s) { return s; }
/**
* \relates TDEGlobal
* Returns a debug stream. You can use it to print debug
* information.
* @param area an id to identify the output, 0 for default
* @see kndDebug()
*/
TDECORE_EXPORT kdbgstream kdDebug(int area = 0);
TDECORE_EXPORT kdbgstream kdDebug(bool cond, int area = 0);
/**
* \relates TDEGlobal
* Returns a backtrace.
* @return a backtrace
*/
TDECORE_EXPORT TQString kdBacktrace();
/**
* \relates TDEGlobal
* Returns a backtrace.
* @param levels the number of levels of the backtrace
* @return a backtrace
* @since 3.1
*/
TDECORE_EXPORT TQString kdBacktrace(int levels);
/**
* Returns a dummy debug stream. The stream does not print anything.
* @param area an id to identify the output, 0 for default
* @see kdDebug()
*/
inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); return kndbgstream(); }
inline kndbgstream kndDebug(bool , int = 0) { return kndbgstream(); }
inline TQString kndBacktrace() { return TQString::null; }
inline TQString kndBacktrace(int) { return TQString::null; }
/**
* \relates TDEGlobal
* Returns a warning stream. You can use it to print warning
* information.
* @param area an id to identify the output, 0 for default
*/
TDECORE_EXPORT kdbgstream kdWarning(int area = 0);
TDECORE_EXPORT kdbgstream kdWarning(bool cond, int area = 0);
/**
* \relates TDEGlobal
* Returns an error stream. You can use it to print error
* information.
* @param area an id to identify the output, 0 for default
*/
TDECORE_EXPORT kdbgstream kdError(int area = 0);
TDECORE_EXPORT kdbgstream kdError(bool cond, int area = 0);
/**
* \relates TDEGlobal
* Returns a fatal error stream. You can use it to print fatal error
* information.
* @param area an id to identify the output, 0 for default
*/
TDECORE_EXPORT kdbgstream kdFatal(int area = 0);
TDECORE_EXPORT kdbgstream kdFatal(bool cond, int area = 0);
/**
* \relates TDEGlobal
* Deletes the kdebugrc cache and therefore forces KDebug to reread the
* config file
*/
TDECORE_EXPORT void kdClearDebugConfig();
/** @} */
#ifdef NDEBUG
#define kdDebug kndDebug
#define kdBacktrace kndBacktrace
#endif
#endif
|