KDECore
kdebug.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _KDEBUG_H_
00023 #define _KDEBUG_H_
00024
00025 #include <qstring.h>
00026 #include "kdelibs_export.h"
00027
00028 class QWidget;
00029 class QDateTime;
00030 class QDate;
00031 class QTime;
00032 class QPoint;
00033 class QSize;
00034 class QRect;
00035 class QRegion;
00036 class KURL;
00037 class QStringList;
00038 class QColor;
00039 class QPen;
00040 class QBrush;
00041 class QVariant;
00042 template <class T>
00043 class QValueList;
00044
00045 class kdbgstream;
00046 class kndbgstream;
00047
00055 typedef kdbgstream & (*KDBGFUNC)(kdbgstream &);
00056 typedef kndbgstream & (*KNDBGFUNC)(kndbgstream &);
00057
00058 #ifdef __GNUC__
00059 #define k_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
00060 #else
00061 #define k_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00062 #endif
00063
00064 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00065
00066 class kdbgstreamprivate;
00080 class KDECORE_EXPORT kdbgstream {
00081 public:
00085 kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
00086 area(_area), level(_level), print(_print) { }
00087 kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) :
00088 output(QString::fromLatin1(initialString)), area(_area), level(_level), print(_print) { }
00090 kdbgstream(kdbgstream &str);
00091 kdbgstream(const kdbgstream &str) :
00092 output(str.output), area(str.area), level(str.level), print(str.print) {}
00093 ~kdbgstream();
00099 kdbgstream &operator<<(bool i) {
00100 if (!print) return *this;
00101 output += QString::fromLatin1(i ? "true" : "false");
00102 return *this;
00103 }
00109 kdbgstream &operator<<(short i) {
00110 if (!print) return *this;
00111 QString tmp; tmp.setNum(i); output += tmp;
00112 return *this;
00113 }
00119 kdbgstream &operator<<(unsigned short i) {
00120 if (!print) return *this;
00121 QString tmp; tmp.setNum(i); output += tmp;
00122 return *this;
00123 }
00129 kdbgstream &operator<<(char ch);
00135 kdbgstream &operator<<(unsigned char ch) {
00136 return operator<<( static_cast<char>( ch ) );
00137 }
00143 kdbgstream &operator<<(int i) {
00144 if (!print) return *this;
00145 QString tmp; tmp.setNum(i); output += tmp;
00146 return *this;
00147 }
00153 kdbgstream &operator<<(unsigned int i) {
00154 if (!print) return *this;
00155 QString tmp; tmp.setNum(i); output += tmp;
00156 return *this;
00157 }
00163 kdbgstream &operator<<(long i) {
00164 if (!print) return *this;
00165 QString tmp; tmp.setNum(i); output += tmp;
00166 return *this;
00167 }
00173 kdbgstream &operator<<(unsigned long i) {
00174 if (!print) return *this;
00175 QString tmp; tmp.setNum(i); output += tmp;
00176 return *this;
00177 }
00183 kdbgstream &operator<<(Q_LLONG i) {
00184 if (!print) return *this;
00185 QString tmp; tmp.setNum(i); output += tmp;
00186 return *this;
00187 }
00193 kdbgstream &operator<<(Q_ULLONG i) {
00194 if (!print) return *this;
00195 QString tmp; tmp.setNum(i); output += tmp;
00196 return *this;
00197 }
00198
00202 void flush();
00203
00210 kdbgstream &operator<<(QChar ch);
00216 kdbgstream &operator<<(const QString& string) {
00217 if (!print) return *this;
00218 output += string;
00219 if (output.at(output.length() -1 ) == '\n')
00220 flush();
00221 return *this;
00222 }
00228 kdbgstream &operator<<(const char *string) {
00229 if (!print) return *this;
00230 output += QString::fromUtf8(string);
00231 if (output.at(output.length() - 1) == '\n')
00232 flush();
00233 return *this;
00234 }
00240 kdbgstream &operator<<(const QCString& string) {
00241 *this << string.data();
00242 return *this;
00243 }
00249 kdbgstream& operator<<(const void * p) {
00250 form("%p", p);
00251 return *this;
00252 }
00258 kdbgstream& operator<<(KDBGFUNC f) {
00259 if (!print) return *this;
00260 return (*f)(*this);
00261 }
00267 kdbgstream& operator<<(double d) {
00268 QString tmp; tmp.setNum(d); output += tmp;
00269 return *this;
00270 }
00277 kdbgstream &form(const char *format, ...)
00278 #ifdef __GNUC__
00279 __attribute__ ( ( format ( printf, 2, 3 ) ) )
00280 #endif
00281 ;
00282
00288 kdbgstream& operator << (const QWidget* widget);
00289 kdbgstream& operator << (QWidget* widget);
00290
00296 kdbgstream& operator << ( const QDateTime& dateTime );
00297
00303 kdbgstream& operator << ( const QDate& date );
00304
00310 kdbgstream& operator << ( const QTime& time );
00311
00317 kdbgstream& operator << ( const QPoint& point );
00318
00324 kdbgstream& operator << ( const QSize& size );
00325
00331 kdbgstream& operator << ( const QRect& rect);
00332
00338 kdbgstream& operator << ( const QRegion& region);
00339
00345 kdbgstream& operator << ( const KURL& url );
00346
00352
00353 kdbgstream& operator << ( const QStringList& list);
00354
00360 kdbgstream& operator << ( const QColor& color);
00361
00368 kdbgstream& operator << ( const QPen& pen );
00369
00375 kdbgstream& operator << ( const QBrush& brush );
00376
00383 kdbgstream& operator << ( const QVariant& variant );
00384
00391 kdbgstream& operator << ( const QByteArray& data );
00392
00399 template <class T>
00400 kdbgstream& operator << ( const QValueList<T> &list );
00401
00402 private:
00403 QString output;
00404 unsigned int area, level;
00405 bool print;
00406 kdbgstreamprivate* d;
00407 };
00408
00409 template <class T>
00410 kdbgstream &kdbgstream::operator<<( const QValueList<T> &list )
00411 {
00412 *this << "(";
00413 typename QValueList<T>::ConstIterator it = list.begin();
00414 if ( !list.isEmpty() ) {
00415 *this << *it++;
00416 }
00417 for ( ; it != list.end(); ++it ) {
00418 *this << "," << *it;
00419 }
00420 *this << ")";
00421 return *this;
00422 }
00423
00430 inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
00431
00438 inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; }
00439
00440 KDECORE_EXPORT kdbgstream &perror( kdbgstream &s);
00441
00448 class KDECORE_EXPORT kndbgstream {
00449 public:
00451 kndbgstream() {}
00452 ~kndbgstream() {}
00457 kndbgstream &operator<<(short int ) { return *this; }
00462 kndbgstream &operator<<(unsigned short int ) { return *this; }
00467 kndbgstream &operator<<(char ) { return *this; }
00472 kndbgstream &operator<<(unsigned char ) { return *this; }
00477 kndbgstream &operator<<(int ) { return *this; }
00482 kndbgstream &operator<<(unsigned int ) { return *this; }
00486 void flush() {}
00491 kndbgstream &operator<<(QChar) { return *this; }
00496 kndbgstream &operator<<(const QString& ) { return *this; }
00501 kndbgstream &operator<<(const QCString& ) { return *this; }
00506 kndbgstream &operator<<(const char *) { return *this; }
00511 kndbgstream& operator<<(const void *) { return *this; }
00516 kndbgstream& operator<<(void *) { return *this; }
00521 kndbgstream& operator<<(double) { return *this; }
00526 kndbgstream& operator<<(long) { return *this; }
00531 kndbgstream& operator<<(unsigned long) { return *this; }
00536 kndbgstream& operator<<(Q_LLONG) { return *this; }
00541 kndbgstream& operator<<(Q_ULLONG) { return *this; }
00546 kndbgstream& operator<<(KNDBGFUNC) { return *this; }
00551 kndbgstream& operator << (const QWidget*) { return *this; }
00552 kndbgstream& operator << (QWidget*) { return *this; }
00557 kndbgstream &form(const char *, ...) { return *this; }
00558
00559 kndbgstream& operator<<( const QDateTime& ) { return *this; }
00560 kndbgstream& operator<<( const QDate& ) { return *this; }
00561 kndbgstream& operator<<( const QTime& ) { return *this; }
00562 kndbgstream& operator<<( const QPoint & ) { return *this; }
00563 kndbgstream& operator<<( const QSize & ) { return *this; }
00564 kndbgstream& operator<<( const QRect & ) { return *this; }
00565 kndbgstream& operator<<( const QRegion & ) { return *this; }
00566 kndbgstream& operator<<( const KURL & ) { return *this; }
00567 kndbgstream& operator<<( const QStringList & ) { return *this; }
00568 kndbgstream& operator<<( const QColor & ) { return *this; }
00569 kndbgstream& operator<<( const QPen & ) { return *this; }
00570 kndbgstream& operator<<( const QBrush & ) { return *this; }
00571 kndbgstream& operator<<( const QVariant & ) { return *this; }
00572 kndbgstream& operator<<( const QByteArray & ) { return *this; }
00573
00574 template <class T>
00575 kndbgstream& operator<<( const QValueList<T> & ) { return *this; }
00576 };
00577
00583 inline kndbgstream &endl( kndbgstream & s) { return s; }
00589 inline kndbgstream &flush( kndbgstream & s) { return s; }
00590 inline kndbgstream &perror( kndbgstream & s) { return s; }
00591
00599 KDECORE_EXPORT kdbgstream kdDebug(int area = 0);
00600 KDECORE_EXPORT kdbgstream kdDebug(bool cond, int area = 0);
00606 KDECORE_EXPORT QString kdBacktrace();
00614 KDECORE_EXPORT QString kdBacktrace(int levels);
00620 inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); return kndbgstream(); }
00621 inline kndbgstream kndDebug(bool , int = 0) { return kndbgstream(); }
00622 inline QString kndBacktrace() { return QString::null; }
00623 inline QString kndBacktrace(int) { return QString::null; }
00624
00631 KDECORE_EXPORT kdbgstream kdWarning(int area = 0);
00632 KDECORE_EXPORT kdbgstream kdWarning(bool cond, int area = 0);
00639 KDECORE_EXPORT kdbgstream kdError(int area = 0);
00640 KDECORE_EXPORT kdbgstream kdError(bool cond, int area = 0);
00647 KDECORE_EXPORT kdbgstream kdFatal(int area = 0);
00648 KDECORE_EXPORT kdbgstream kdFatal(bool cond, int area = 0);
00649
00655 KDECORE_EXPORT void kdClearDebugConfig();
00656
00659 #ifdef NDEBUG
00660 #define kdDebug kndDebug
00661 #define kdBacktrace kndBacktrace
00662 #endif
00663
00664 #endif
00665