kdecore Library API Documentation

kdebug.h

00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org) 00003 2000-2002 Stephan Kulow (coolo@kde.org) 00004 2002 Holger Freyther (freyther@kde.org) 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00019 Boston, MA 02111-1307, USA. 00020 */ 00021 00022 #ifndef _KDEBUG_H_ 00023 #define _KDEBUG_H_ 00024 00025 #include <qstring.h> 00026 00027 class QWidget; 00028 class QDateTime; 00029 class QDate; 00030 class QTime; 00031 class QPoint; 00032 class QSize; 00033 class QRect; 00034 class QRegion; 00035 class KURL; 00036 class QStringList; 00037 class QColor; 00038 class QPen; 00039 class QBrush; 00040 class QVariant; 00041 template <class T> 00042 class QValueList; 00043 00044 class kdbgstream; 00045 class kndbgstream; 00046 00054 typedef kdbgstream & (*KDBGFUNC)(kdbgstream &); // manipulator function 00055 typedef kndbgstream & (*KNDBGFUNC)(kndbgstream &); // manipulator function 00056 00057 #ifdef __GNUC__ 00058 #define k_funcinfo "[" << __PRETTY_FUNCTION__ << "] " 00059 #else 00060 #define k_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] " 00061 #endif 00062 00063 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] " 00064 00065 class kdbgstreamprivate; 00079 class kdbgstream { 00080 public: 00084 kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) : 00085 area(_area), level(_level), print(_print) { } 00086 kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) : 00087 output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) { } 00089 kdbgstream(kdbgstream &str); 00090 kdbgstream(const kdbgstream &str) : 00091 output(str.output), area(str.area), level(str.level), print(str.print) {} 00092 ~kdbgstream(); 00098 kdbgstream &operator<<(bool i) { 00099 if (!print) return *this; 00100 output += QString::fromLatin1(i ? "true" : "false"); 00101 return *this; 00102 } 00108 kdbgstream &operator<<(short i) { 00109 if (!print) return *this; 00110 QString tmp; tmp.setNum(i); output += tmp; 00111 return *this; 00112 } 00118 kdbgstream &operator<<(unsigned short i) { 00119 if (!print) return *this; 00120 QString tmp; tmp.setNum(i); output += tmp; 00121 return *this; 00122 } 00128 kdbgstream &operator<<(char ch); 00134 kdbgstream &operator<<(unsigned char ch) { 00135 return operator<<( static_cast<char>( ch ) ); 00136 } 00142 kdbgstream &operator<<(int i) { 00143 if (!print) return *this; 00144 QString tmp; tmp.setNum(i); output += tmp; 00145 return *this; 00146 } 00152 kdbgstream &operator<<(unsigned int i) { 00153 if (!print) return *this; 00154 QString tmp; tmp.setNum(i); output += tmp; 00155 return *this; 00156 } 00162 kdbgstream &operator<<(long i) { 00163 if (!print) return *this; 00164 QString tmp; tmp.setNum(i); output += tmp; 00165 return *this; 00166 } 00172 kdbgstream &operator<<(unsigned long i) { 00173 if (!print) return *this; 00174 QString tmp; tmp.setNum(i); output += tmp; 00175 return *this; 00176 } 00182 kdbgstream &operator<<(Q_LLONG i) { 00183 if (!print) return *this; 00184 QString tmp; tmp.setNum(i); output += tmp; 00185 return *this; 00186 } 00192 kdbgstream &operator<<(Q_ULLONG i) { 00193 if (!print) return *this; 00194 QString tmp; tmp.setNum(i); output += tmp; 00195 return *this; 00196 } 00197 00201 void flush(); //AB: maybe this should be virtual! would save some trouble for some 3rd party projects 00202 00209 kdbgstream &operator<<(QChar ch); 00215 kdbgstream &operator<<(const QString& string) { 00216 if (!print) return *this; 00217 output += string; 00218 if (output.at(output.length() -1 ) == '\n') 00219 flush(); 00220 return *this; 00221 } 00227 kdbgstream &operator<<(const char *string) { 00228 if (!print) return *this; 00229 output += QString::fromUtf8(string); 00230 if (output.at(output.length() - 1) == '\n') 00231 flush(); 00232 return *this; 00233 } 00239 kdbgstream &operator<<(const QCString& string) { 00240 *this << string.data(); 00241 return *this; 00242 } 00248 kdbgstream& operator<<(const void * p) { 00249 form("%p", p); 00250 return *this; 00251 } 00257 kdbgstream& operator<<(KDBGFUNC f) { 00258 if (!print) return *this; 00259 return (*f)(*this); 00260 } 00266 kdbgstream& operator<<(double d) { 00267 QString tmp; tmp.setNum(d); output += tmp; 00268 return *this; 00269 } 00276 kdbgstream &form(const char *format, ...) 00277 #ifdef __GNUC__ 00278 __attribute__ ( ( format ( printf, 2, 3 ) ) ) 00279 #endif 00280 ; 00281 00287 kdbgstream& operator << (const QWidget* widget); 00288 kdbgstream& operator << (QWidget* widget); // KDE4 merge 00289 00295 kdbgstream& operator << ( const QDateTime& dateTime ); 00296 00302 kdbgstream& operator << ( const QDate& date ); 00303 00309 kdbgstream& operator << ( const QTime& time ); 00310 00316 kdbgstream& operator << ( const QPoint& point ); 00317 00323 kdbgstream& operator << ( const QSize& size ); 00324 00330 kdbgstream& operator << ( const QRect& rect); 00331 00337 kdbgstream& operator << ( const QRegion& region); 00338 00344 kdbgstream& operator << ( const KURL& url ); 00345 00351 // ### KDE4: Remove in favor of template operator for QValueList<T> below 00352 kdbgstream& operator << ( const QStringList& list); 00353 00359 kdbgstream& operator << ( const QColor& color); 00360 00367 kdbgstream& operator << ( const QPen& pen ); 00368 00374 kdbgstream& operator << ( const QBrush& brush ); 00375 00382 kdbgstream& operator << ( const QVariant& variant ); 00383 00390 kdbgstream& operator << ( const QByteArray& data ); 00391 00398 template <class T> 00399 kdbgstream& operator << ( const QValueList<T> &list ); 00400 00401 private: 00402 QString output; 00403 unsigned int area, level; 00404 bool print; 00405 kdbgstreamprivate* d; 00406 }; 00407 00408 template <class T> 00409 kdbgstream &kdbgstream::operator<<( const QValueList<T> &list ) 00410 { 00411 *this << "("; 00412 typename QValueList<T>::ConstIterator it = list.begin(); 00413 if ( !list.isEmpty() ) { 00414 *this << *it++; 00415 } 00416 for ( ; it != list.end(); ++it ) { 00417 *this << "," << *it; 00418 } 00419 *this << ")"; 00420 return *this; 00421 } 00422 00429 inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; } 00430 00437 inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; } 00438 00439 kdbgstream &perror( kdbgstream &s); 00440 00447 class kndbgstream { 00448 public: 00450 kndbgstream() {} 00451 ~kndbgstream() {} 00456 kndbgstream &operator<<(short int ) { return *this; } 00461 kndbgstream &operator<<(unsigned short int ) { return *this; } 00466 kndbgstream &operator<<(char ) { return *this; } 00471 kndbgstream &operator<<(unsigned char ) { return *this; } 00476 kndbgstream &operator<<(int ) { return *this; } 00481 kndbgstream &operator<<(unsigned int ) { return *this; } 00485 void flush() {} 00490 kndbgstream &operator<<(QChar) { return *this; } 00495 kndbgstream &operator<<(const QString& ) { return *this; } 00500 kndbgstream &operator<<(const QCString& ) { return *this; } 00505 kndbgstream &operator<<(const char *) { return *this; } 00510 kndbgstream& operator<<(const void *) { return *this; } 00515 kndbgstream& operator<<(void *) { return *this; } 00520 kndbgstream& operator<<(double) { return *this; } 00525 kndbgstream& operator<<(long) { return *this; } 00530 kndbgstream& operator<<(unsigned long) { return *this; } 00535 kndbgstream& operator<<(Q_LLONG) { return *this; } 00540 kndbgstream& operator<<(Q_ULLONG) { return *this; } 00545 kndbgstream& operator<<(KNDBGFUNC) { return *this; } 00550 kndbgstream& operator << (const QWidget*) { return *this; } 00551 kndbgstream& operator << (QWidget*) { return *this; } // KDE4 merge 00556 kndbgstream &form(const char *, ...) { return *this; } 00557 00558 kndbgstream& operator<<( const QDateTime& ) { return *this; } 00559 kndbgstream& operator<<( const QDate& ) { return *this; } 00560 kndbgstream& operator<<( const QTime& ) { return *this; } 00561 kndbgstream& operator<<( const QPoint & ) { return *this; } 00562 kndbgstream& operator<<( const QSize & ) { return *this; } 00563 kndbgstream& operator<<( const QRect & ) { return *this; } 00564 kndbgstream& operator<<( const QRegion & ) { return *this; } 00565 kndbgstream& operator<<( const KURL & ) { return *this; } 00566 kndbgstream& operator<<( const QStringList & ) { return *this; } 00567 kndbgstream& operator<<( const QColor & ) { return *this; } 00568 kndbgstream& operator<<( const QPen & ) { return *this; } 00569 kndbgstream& operator<<( const QBrush & ) { return *this; } 00570 kndbgstream& operator<<( const QVariant & ) { return *this; } 00571 kndbgstream& operator<<( const QByteArray & ) { return *this; } 00572 00573 template <class T> 00574 kndbgstream& operator<<( const QValueList<T> & ) { return *this; } 00575 }; 00576 00582 inline kndbgstream &endl( kndbgstream & s) { return s; } 00588 inline kndbgstream &flush( kndbgstream & s) { return s; } 00589 inline kndbgstream &perror( kndbgstream & s) { return s; } 00590 00598 kdbgstream kdDebug(int area = 0); 00599 kdbgstream kdDebug(bool cond, int area = 0); 00605 QString kdBacktrace(); 00613 QString kdBacktrace(int levels); 00619 inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); return kndbgstream(); } 00620 inline kndbgstream kndDebug(bool , int = 0) { return kndbgstream(); } 00621 inline QString kndBacktrace() { return QString::null; } 00622 inline QString kndBacktrace(int) { return QString::null; } 00623 00630 kdbgstream kdWarning(int area = 0); 00631 kdbgstream kdWarning(bool cond, int area = 0); 00638 kdbgstream kdError(int area = 0); 00639 kdbgstream kdError(bool cond, int area = 0); 00646 kdbgstream kdFatal(int area = 0); 00647 kdbgstream kdFatal(bool cond, int area = 0); 00648 00654 void kdClearDebugConfig(); 00655 00658 #ifdef NDEBUG 00659 #define kdDebug kndDebug 00660 #define kdBacktrace kndBacktrace 00661 #endif 00662 00663 #endif 00664
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Oct 17 11:26:07 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003