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 
00041 class kdbgstream;
00042 class kndbgstream;
00043 
00051 typedef kdbgstream & (*KDBGFUNC)(kdbgstream &); // manipulator function
00052 typedef kndbgstream & (*KNDBGFUNC)(kndbgstream &); // manipulator function
00053 
00054 #ifdef __GNUC__
00055 #define k_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
00056 #else
00057 #define k_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00058 #endif
00059 
00060 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00061 
00062 class kdbgstreamprivate;
00076 class kdbgstream {
00077  public:
00081     kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
00082       area(_area), level(_level),  print(_print) { }
00083     kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) :
00084       output(QString::fromLatin1(initialString)), area(_area), level(_level),  print(_print) { }
00086     kdbgstream(kdbgstream &str) :
00087       output(str.output), area(str.area), level(str.level), print(str.print) { str.output.truncate(0); }
00088     kdbgstream(const kdbgstream &str) :
00089       output(str.output), area(str.area), level(str.level), print(str.print) {}
00090     ~kdbgstream();
00096     kdbgstream &operator<<(bool i)  {
00097     if (!print) return *this;
00098     output += QString::fromLatin1(i ? "true" : "false");
00099     return *this;
00100     }
00106     kdbgstream &operator<<(short i)  {
00107     if (!print) return *this;
00108     QString tmp; tmp.setNum(i); output += tmp;
00109     return *this;
00110     }
00116     kdbgstream &operator<<(unsigned short i) {
00117         if (!print) return *this;
00118         QString tmp; tmp.setNum(i); output += tmp;
00119         return *this;
00120     }
00126     kdbgstream &operator<<(char i);
00132     kdbgstream &operator<<(unsigned char i) {
00133         return operator<<( static_cast<char>( i ) );
00134     }
00140     kdbgstream &operator<<(int i)  {
00141     if (!print) return *this;
00142     QString tmp; tmp.setNum(i); output += tmp;
00143     return *this;
00144     }
00150     kdbgstream &operator<<(unsigned int i) {
00151         if (!print) return *this;
00152         QString tmp; tmp.setNum(i); output += tmp;
00153         return *this;
00154     }
00160     kdbgstream &operator<<(long i) {
00161         if (!print) return *this;
00162         QString tmp; tmp.setNum(i); output += tmp;
00163         return *this;
00164     }
00170     kdbgstream &operator<<(unsigned long i) {
00171         if (!print) return *this;
00172         QString tmp; tmp.setNum(i); output += tmp;
00173         return *this;
00174     }
00178     void flush(); //AB: maybe this should be virtual! would save some trouble for some 3rd party projects
00179 
00185     kdbgstream &operator<<(const QString& string) {
00186     if (!print) return *this;
00187     output += string;
00188     if (output.at(output.length() -1 ) == '\n')
00189         flush();
00190     return *this;
00191     }
00197     kdbgstream &operator<<(const char *string) {
00198     if (!print) return *this;
00199     output += QString::fromUtf8(string);
00200     if (output.at(output.length() - 1) == '\n')
00201         flush();
00202     return *this;
00203     }
00209     kdbgstream &operator<<(const QCString& string) {
00210         *this << string.data();
00211         return *this;
00212     }
00218     kdbgstream& operator<<(const void * p) {
00219         form("%p", p);
00220         return *this;
00221     }
00227     kdbgstream& operator<<(KDBGFUNC f) {
00228     if (!print) return *this;
00229     return (*f)(*this);
00230     }
00236     kdbgstream& operator<<(double d) {
00237       QString tmp; tmp.setNum(d); output += tmp;
00238       return *this;
00239     }
00246     kdbgstream &form(const char *format, ...)
00247 #ifdef __GNUC__
00248       __attribute__ ( ( format ( printf, 2, 3 ) ) )
00249 #endif
00250      ;
00251 
00257     kdbgstream& operator << (const QWidget* widget);
00258     kdbgstream& operator << (QWidget* widget); // KDE4 merge
00259 
00265     kdbgstream& operator << ( const QDateTime& dateTime );
00266 
00272     kdbgstream& operator << ( const QDate& date );
00273 
00279     kdbgstream& operator << ( const QTime& time );
00280 
00286     kdbgstream& operator << ( const QPoint& point );
00287 
00293     kdbgstream& operator << ( const QSize& size );
00294 
00300     kdbgstream& operator << ( const QRect& rect);
00301 
00307     kdbgstream& operator << ( const QRegion& region);
00308 
00314     kdbgstream& operator << ( const KURL& url );
00315 
00321     kdbgstream& operator << ( const QStringList& list);
00322 
00328     kdbgstream& operator << ( const QColor& color);
00329 
00336     kdbgstream& operator << ( const QPen& pen );
00337 
00343     kdbgstream& operator << ( const QBrush& brush );
00344 
00345 
00346  private:
00347     QString output;
00348     unsigned int area, level;
00349     bool print;
00350     kdbgstreamprivate* d;
00351 };
00352 
00359 inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
00360 
00367 inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; }
00368 
00369 kdbgstream &perror( kdbgstream &s);
00370 
00377 class kndbgstream {
00378  public:
00380     kndbgstream() {}
00381     ~kndbgstream() {}
00386     kndbgstream &operator<<(short int )  { return *this; }
00391     kndbgstream &operator<<(unsigned short int )  { return *this; }
00396     kndbgstream &operator<<(char )  { return *this; }
00401     kndbgstream &operator<<(unsigned char )  { return *this; }
00406     kndbgstream &operator<<(int )  { return *this; }
00411     kndbgstream &operator<<(unsigned int )  { return *this; }
00415     void flush() {}
00420     kndbgstream &operator<<(const QString& ) { return *this; }
00425     kndbgstream &operator<<(const QCString& ) { return *this; }
00430     kndbgstream &operator<<(const char *) { return *this; }
00435     kndbgstream& operator<<(const void *) { return *this; }
00440     kndbgstream& operator<<(void *) { return *this; }
00445     kndbgstream& operator<<(double) { return *this; }
00450     kndbgstream& operator<<(long) { return *this; }
00455     kndbgstream& operator<<(unsigned long) { return *this; }
00460     kndbgstream& operator<<(KNDBGFUNC) { return *this; }
00465     kndbgstream& operator << (const QWidget*) { return *this; }
00466     kndbgstream& operator << (QWidget*) { return *this; } // KDE4 merge
00471     kndbgstream &form(const char *, ...) { return *this; }
00472 
00473     kndbgstream& operator<<( const QDateTime& ) { return *this; }
00474     kndbgstream& operator<<( const QDate&     ) { return *this; }
00475     kndbgstream& operator<<( const QTime&     ) { return *this; }
00476     kndbgstream& operator<<( const QPoint & )  { return *this; }
00477     kndbgstream& operator<<( const QSize & )  { return *this; }
00478     kndbgstream& operator<<( const QRect & )  { return *this; }
00479     kndbgstream& operator<<( const QRegion & ) { return *this; }
00480     kndbgstream& operator<<( const KURL & )  { return *this; }
00481     kndbgstream& operator<<( const QStringList & ) { return *this; }
00482     kndbgstream& operator<<( const QColor & ) { return *this; }
00483     kndbgstream& operator<<( const QPen & ) { return *this; }
00484     kndbgstream& operator<<( const QBrush & ) { return *this; }
00485 };
00486 
00492 inline kndbgstream &endl( kndbgstream & s) { return s; }
00498 inline kndbgstream &flush( kndbgstream & s) { return s; }
00499 inline kndbgstream &perror( kndbgstream & s) { return s; }
00500 
00508 kdbgstream kdDebug(int area = 0);
00509 kdbgstream kdDebug(bool cond, int area = 0);
00515 QString kdBacktrace();
00523 QString kdBacktrace(int levels);
00529 inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); return kndbgstream(); }
00530 inline kndbgstream kndDebug(bool , int  = 0) { return kndbgstream(); }
00531 inline QString kndBacktrace() { return QString::null; }
00532 inline QString kndBacktrace(int) { return QString::null; }
00533 
00540 kdbgstream kdWarning(int area = 0);
00541 kdbgstream kdWarning(bool cond, int area = 0);
00548 kdbgstream kdError(int area = 0);
00549 kdbgstream kdError(bool cond, int area = 0);
00556 kdbgstream kdFatal(int area = 0);
00557 kdbgstream kdFatal(bool cond, int area = 0);
00558 
00564 void kdClearDebugConfig();
00565 
00568 #ifdef NDEBUG
00569 #define kdDebug kndDebug
00570 #define kdBacktrace kndBacktrace
00571 #endif
00572 
00573 #endif
00574 
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Apr 21 18:42:56 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003