summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/odebug.h
Unidiff
Diffstat (limited to 'libopie2/opiecore/odebug.h') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/odebug.h474
1 files changed, 474 insertions, 0 deletions
diff --git a/libopie2/opiecore/odebug.h b/libopie2/opiecore/odebug.h
new file mode 100644
index 0000000..85941fd
--- a/dev/null
+++ b/libopie2/opiecore/odebug.h
@@ -0,0 +1,474 @@
1/*
2 This file is part of the Opie Project
3 (C) 2003 Michael 'Mickey' Lauer (mickey@tm.informatik.uni-frankfurt.de)
4 Inspired by the KDE debug classes, which are
5 (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
6 (C) 2002 Holger Freyther (freyther@kde.org)
7 =.
8 .=l.
9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details.
24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA.
31*/
32
33#ifndef ODEBUG_H
34#define ODEBUG_H
35
36#include <qstring.h>
37
38class QWidget;
39class QDateTime;
40class QDate;
41class QTime;
42class QPoint;
43class QSize;
44class QRect;
45class QRegion;
46class QStringList;
47class QColor;
48class QBrush;
49
50class odbgstream;
51class ondbgstream;
52
53#ifdef __GNUC__
54#define o_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
55#else
56#define o_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
57#endif
58
59#define o_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
60
61#define owarn odWarning()
62#define oerr odError()
63#define odebug odDebug()
64#define ofatal odFatal()
65#define oendl "\n"
66
67class odbgstreamprivate;
68/**
69 * odbgstream is a text stream that allows you to print debug messages.
70 * Using the overloaded "<<" operator you can send messages. Usually
71 * you do not create the odbgstream yourself, but use @ref odDebug() (odebug)
72 * @ref odWarning() (owarn), @ref odError() (oerr) or @ref odFatal (ofatal) to obtain one.
73 *
74 * Example:
75 * <pre>
76 * int i = 5;
77 * odebug << "The value of i is " << i << oendl;
78 * </pre>
79 * @see odbgstream
80 */
81
82/*======================================================================================
83 * odbgstream
84 *======================================================================================*/
85
86class odbgstream
87{
88 public:
89 /**
90 * @internal
91 */
92 odbgstream(unsigned int _area, unsigned int _level, bool _print = true);
93 odbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true);
94 odbgstream(odbgstream &str);
95 odbgstream(const odbgstream &str);
96 virtual ~odbgstream();
97
98 /**
99 * Prints the given value.
100 * @param i the boolean to print (as "true" or "false")
101 * @return this stream
102 */
103 odbgstream &operator<<(bool i);
104 /**
105 * Prints the given value.
106 * @param i the short to print
107 * @return this stream
108 */
109 odbgstream &operator<<(short i);
110 /**
111 * Prints the given value.
112 * @param i the unsigned short to print
113 * @return this stream
114 */
115 odbgstream &operator<<(unsigned short i);
116 /**
117 * Prints the given value.
118 * @param i the char to print
119 * @return this stream
120 */
121 odbgstream &operator<<(char i);
122 /**
123 * Prints the given value.
124 * @param i the unsigned char to print
125 * @return this stream
126 */
127 odbgstream &operator<<(unsigned char i);
128 /**
129 * Prints the given value.
130 * @param i the int to print
131 * @return this stream
132 */
133 odbgstream &operator<<(int i);
134 /**
135 * Prints the given value.
136 * @param i the unsigned int to print
137 * @return this stream
138 */
139 odbgstream &operator<<(unsigned int i);
140 /**
141 * Prints the given value.
142 * @param i the long to print
143 * @return this stream
144 */
145 odbgstream &operator<<(long i);
146 /**
147 * Prints the given value.
148 * @param i the unsigned long to print
149 * @return this stream
150 */
151 odbgstream &operator<<(unsigned long i);
152 /**
153 * Flushes the output.
154 */
155 virtual void flush();
156 /**
157 * Prints the given value.
158 * @param string the string to print
159 * @return this stream
160 */
161 odbgstream &operator<<(const QString& string);
162 /**
163 * Prints the given value.
164 * @param string the string to print
165 * @return this stream
166 */
167 odbgstream &operator<<(const char *string);
168 /**
169 * Prints the given value.
170 * @param string the string to print
171 * @return this stream
172 */
173 odbgstream &operator<<(const QCString& string);
174 /**
175 * Prints the given value.
176 * @param p a pointer to print (in number form)
177 * @return this stream
178 */
179 odbgstream& operator<<(const void * p);
180 /**
181 * Prints the given value.
182 * @param d the double to print
183 * @return this stream
184 */
185 odbgstream& operator<<(double d);
186 /**
187 * Prints the string @p format which can contain
188 * printf-style formatted values.
189 * @param format the printf-style format
190 * @return this stream
191 */
192 odbgstream &form(const char *format, ...);
193 /** Operator to print out basic information about a QWidget.
194 * Output of class names only works if the class is moc'ified.
195 * @param widget the widget to print
196 * @return this stream
197 */
198 odbgstream& operator<< (QWidget* widget);
199
200 /**
201 * Prints the given value.
202 * @param dateTime the datetime to print
203 * @return this stream
204 */
205 odbgstream& operator<< ( const QDateTime& dateTime );
206
207 /**
208 * Prints the given value.
209 * @param date the date to print
210 * @return this stream
211 */
212 odbgstream& operator<< ( const QDate& date );
213
214 /**
215 * Prints the given value.
216 * @param time the time to print
217 * @return this stream
218 */
219 odbgstream& operator<< ( const QTime& time );
220
221 /**
222 * Prints the given value.
223 * @param point the point to print
224 * @return this stream
225 */
226 odbgstream& operator<< ( const QPoint& point );
227
228 /**
229 * Prints the given value.
230 * @param size the QSize to print
231 * @return this stream
232 */
233 odbgstream& operator<< ( const QSize& size );
234
235 /**
236 * Prints the given value.
237 * @param rect the QRect to print
238 * @return this stream
239 */
240 odbgstream& operator<< ( const QRect& rect);
241
242 /**
243 * Prints the given value.
244 * @param region the QRegion to print
245 * @return this stream
246 */
247 odbgstream& operator<< ( const QRegion& region);
248
249 /**
250 * Prints the given value.
251 * @param list the stringlist to print
252 * @return this stream
253 */
254 odbgstream& operator<< ( const QStringList& list);
255
256 /**
257 * Prints the given value.
258 * @param color the color to print
259 * @return this stream
260 */
261 odbgstream& operator<< ( const QColor& color);
262
263 /**
264 * Prints the given value.
265 * @param brush the brush to print
266 * @return this stream
267 */
268 odbgstream& operator<< ( const QBrush& brush );
269
270 private:
271 QString output;
272 unsigned int area, level;
273 bool print;
274 odbgstreamprivate* d;
275};
276
277/**
278 * Prints an "\n".
279 * @param s the debug stream to write to
280 * @return the debug stream (@p s)
281 */
282inline odbgstream& endl( odbgstream &s) { s << "\n"; return s; }
283/**
284 * Flushes the stream.
285 * @param s the debug stream to write to
286 * @return the debug stream (@p s)
287 */
288inline odbgstream& flush( odbgstream &s) { s.flush(); return s; }
289
290odbgstream &perror( odbgstream &s);
291
292/**
293 * ondbgstream is a dummy variant of @ref odbgstream. All functions do
294 * nothing.
295 * @see ondDebug()
296 */
297class ondbgstream {
298 public:
299 /// Empty constructor.
300 ondbgstream() {}
301 ~ondbgstream() {}
302 /**
303 * Does nothing.
304 * @return this stream
305 */
306 ondbgstream &operator<<(short int ) { return *this; }
307 /**
308 * Does nothing.
309 * @return this stream
310 */
311 ondbgstream &operator<<(unsigned short int ) { return *this; }
312 /**
313 * Does nothing.
314 * @return this stream
315 */
316 ondbgstream &operator<<(char ) { return *this; }
317 /**
318 * Does nothing.
319 * @return this stream
320 */
321 ondbgstream &operator<<(unsigned char ) { return *this; }
322 /**
323 * Does nothing.
324 * @return this stream
325 */
326 ondbgstream &operator<<(int ) { return *this; }
327 /**
328 * Does nothing.
329 * @return this stream
330 */
331 ondbgstream &operator<<(unsigned int ) { return *this; }
332 /**
333 * Does nothing.
334 */
335 void flush() {}
336 /**
337 * Does nothing.
338 * @return this stream
339 */
340 ondbgstream &operator<<(const QString& ) { return *this; }
341 /**
342 * Does nothing.
343 * @return this stream
344 */
345 ondbgstream &operator<<(const QCString& ) { return *this; }
346 /**
347 * Does nothing.
348 * @return this stream
349 */
350 ondbgstream &operator<<(const char *) { return *this; }
351 /**
352 * Does nothing.
353 * @return this stream
354 */
355 ondbgstream& operator<<(const void *) { return *this; }
356 /**
357 * Does nothing.
358 * @return this stream
359 */
360 ondbgstream& operator<<(void *) { return *this; }
361 /**
362 * Does nothing.
363 * @return this stream
364 */
365 ondbgstream& operator<<(double) { return *this; }
366 /**
367 * Does nothing.
368 * @return this stream
369 */
370 ondbgstream& operator<<(long) { return *this; }
371 /**
372 * Does nothing.
373 * @return this stream
374 */
375 ondbgstream& operator<<(unsigned long) { return *this; }
376 /**
377 * Does nothing.
378 * @return this stream
379 */
380 ondbgstream& operator << (QWidget*) { return *this; }
381 /**
382 * Does nothing.
383 * @return this stream
384 */
385 ondbgstream &form(const char *, ...) { return *this; }
386
387 ondbgstream& operator<<( const QDateTime& ) { return *this; }
388 ondbgstream& operator<<( const QDate& ) { return *this; }
389 ondbgstream& operator<<( const QTime& ) { return *this; }
390 ondbgstream& operator<<( const QPoint & ) { return *this; }
391 ondbgstream& operator<<( const QSize & ) { return *this; }
392 ondbgstream& operator<<( const QRect & ) { return *this; }
393 ondbgstream& operator<<( const QRegion & ) { return *this; }
394 ondbgstream& operator<<( const QStringList & ) { return *this; }
395 ondbgstream& operator<<( const QColor & ) { return *this; }
396 ondbgstream& operator<<( const QBrush & ) { return *this; }
397};
398
399/*======================================================================================
400 * related functions
401 *======================================================================================*/
402
403/**
404 * Does nothing.
405 * @param a stream
406 * @return the given @p s
407 */
408inline ondbgstream& endl( ondbgstream & s) { return s; }
409/**
410 * Does nothing.
411 * @param a stream
412 * @return the given @p s
413 */
414inline ondbgstream& flush( ondbgstream & s) { return s; }
415inline ondbgstream& perror( ondbgstream & s) { return s; }
416
417/**
418 * Returns a debug stream. You can use it to print debug
419 * information.
420 * @param area an id to identify the output, 0 for default
421 */
422odbgstream odDebug(int area = 0);
423odbgstream odDebug(bool cond, int area = 0);
424/**
425 * Returns a backtrace.
426 * @param levels the number of levels (-1 for unlimited) of the backtrace
427 * @return a backtrace
428 */
429QString odBacktrace(int levels = -1);
430/**
431 * Returns a dummy debug stream. The stream does not print anything.
432 * @param area an id to identify the output, 0 for default
433 * @see odDebug()
434 */
435inline ondbgstream ondDebug(int = 0) { return ondbgstream(); }
436inline ondbgstream ondDebug(bool , int = 0) { return ondbgstream(); }
437inline QString ondBacktrace() { return QString::null; }
438inline QString ondBacktrace(int) { return QString::null; }
439
440/**
441 * Returns a warning stream. You can use it to print warning
442 * information.
443 * @param area an id to identify the output, 0 for default
444 */
445odbgstream odWarning(int area = 0);
446odbgstream odWarning(bool cond, int area = 0);
447/**
448 * Returns an error stream. You can use it to print error
449 * information.
450 * @param area an id to identify the output, 0 for default
451 */
452odbgstream odError(int area = 0);
453odbgstream odError(bool cond, int area = 0);
454/**
455 * Returns a fatal error stream. You can use it to print fatal error
456 * information.
457 * @param area an id to identify the output, 0 for default
458 */
459odbgstream odFatal(int area = 0);
460odbgstream odFatal(bool cond, int area = 0);
461
462/**
463 * Deletes the odebugrc cache and therefore forces KDebug to reread the
464 * config file
465 */
466void odClearDebugConfig();
467
468#ifdef OPIE_NO_DEBUG
469#define odDebug ondDebug
470#define odBacktrace ondBacktrace
471#endif
472
473#endif
474