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 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #ifndef _KDEBUG_H_
00022 #define _KDEBUG_H_ "$Id: kdebug.h,v 1.61 2002/11/12 18:13:27 mutz Exp $"
00023 
00024 #include <qstring.h>
00025 class QWidget;
00026 
00027 class kdbgstream;
00028 class kndbgstream;
00029 typedef kdbgstream & (*KDBGFUNC)(kdbgstream &); // manipulator function
00030 typedef kndbgstream & (*KNDBGFUNC)(kndbgstream &); // manipulator function
00031 
00032 #ifdef __GNUC__
00033 #define k_funcinfo "[" << __PRETTY_FUNCTION__ << "] "
00034 #else
00035 #define k_funcinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00036 #endif
00037 
00038 #define k_lineinfo "[" << __FILE__ << ":" << __LINE__ << "] "
00039 
00040 class kdbgstreamprivate;
00054 class kdbgstream {
00055  public:
00059     kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
00060       area(_area), level(_level),  print(_print) { }
00061     kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, bool _print = true) :
00062       output(QString::fromLatin1(initialString)), area(_area), level(_level),  print(_print) { }
00064     kdbgstream(kdbgstream &str) :
00065       output(str.output), area(str.area), level(str.level), print(str.print) { str.output.truncate(0); }
00066     kdbgstream(const kdbgstream &str) :
00067       output(str.output), area(str.area), level(str.level), print(str.print) {}
00068     ~kdbgstream();
00074     kdbgstream &operator<<(bool i)  {
00075     if (!print) return *this;
00076     output += QString::fromLatin1(i ? "true" : "false");
00077     return *this;
00078     }
00084     kdbgstream &operator<<(short i)  {
00085     if (!print) return *this;
00086     QString tmp; tmp.setNum(i); output += tmp;
00087     return *this;
00088     }
00094     kdbgstream &operator<<(unsigned short i) {
00095         if (!print) return *this;
00096         QString tmp; tmp.setNum(i); output += tmp;
00097         return *this;
00098     }
00104     kdbgstream &operator<<(char i);
00110     kdbgstream &operator<<(unsigned char i) {
00111         return operator<<( static_cast<char>( i ) );
00112     }
00118     kdbgstream &operator<<(int i)  {
00119     if (!print) return *this;
00120     QString tmp; tmp.setNum(i); output += tmp;
00121     return *this;
00122     }
00128     kdbgstream &operator<<(unsigned int i) {
00129         if (!print) return *this;
00130         QString tmp; tmp.setNum(i); output += tmp;
00131         return *this;
00132     }
00138     kdbgstream &operator<<(long i) {
00139         if (!print) return *this;
00140         QString tmp; tmp.setNum(i); output += tmp;
00141         return *this;
00142     }
00148     kdbgstream &operator<<(unsigned long i) {
00149         if (!print) return *this;
00150         QString tmp; tmp.setNum(i); output += tmp;
00151         return *this;
00152     }
00156     void flush();
00162     kdbgstream &operator<<(const QString& string) {
00163     if (!print) return *this;
00164     output += string;
00165     if (output.at(output.length() -1 ) == '\n')
00166         flush();
00167     return *this;
00168     }
00174     kdbgstream &operator<<(const char *string) {
00175     if (!print) return *this;
00176     output += QString::fromUtf8(string);
00177     if (output.at(output.length() - 1) == '\n')
00178         flush();
00179     return *this;
00180     }
00186     kdbgstream &operator<<(const QCString& string) {
00187         *this << string.data();
00188         return *this;
00189     }
00195     kdbgstream& operator<<(const void * p) {
00196         form("%p", p);
00197         return *this;
00198     }
00204     kdbgstream& operator<<(KDBGFUNC f) {
00205     if (!print) return *this;
00206     return (*f)(*this);
00207     }
00213     kdbgstream& operator<<(double d) {
00214       QString tmp; tmp.setNum(d); output += tmp;
00215       return *this;
00216     }
00223     kdbgstream &form(const char *format, ...);
00229     kdbgstream& operator << (QWidget* widget);
00230  private:
00231     QString output;
00232     unsigned int area, level;
00233     bool print;
00234     kdbgstreamprivate* d;
00235 };
00236 
00242 inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
00248 inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; }
00249 kdbgstream &perror( kdbgstream &s);
00250 
00256 class kndbgstream {
00257  public:
00259     kndbgstream() {}
00260     ~kndbgstream() {}
00265     kndbgstream &operator<<(short int )  { return *this; }
00270     kndbgstream &operator<<(unsigned short int )  { return *this; }
00275     kndbgstream &operator<<(char )  { return *this; }
00280     kndbgstream &operator<<(unsigned char )  { return *this; }
00285     kndbgstream &operator<<(int )  { return *this; }
00290     kndbgstream &operator<<(unsigned int )  { return *this; }
00294     void flush() {}
00299     kndbgstream &operator<<(const QString& ) { return *this; }
00304     kndbgstream &operator<<(const QCString& ) { return *this; }
00309     kndbgstream &operator<<(const char *) { return *this; }
00314     kndbgstream& operator<<(const void *) { return *this; }
00319     kndbgstream& operator<<(void *) { return *this; }
00324     kndbgstream& operator<<(double) { return *this; }
00329     kndbgstream& operator<<(long) { return *this; }
00334     kndbgstream& operator<<(unsigned long) { return *this; }
00339     kndbgstream& operator<<(KNDBGFUNC) { return *this; }
00344     kndbgstream& operator << (QWidget*) { return *this; }
00349     kndbgstream &form(const char *, ...) { return *this; }
00350 };
00351 
00357 inline kndbgstream &endl( kndbgstream & s) { return s; }
00363 inline kndbgstream &flush( kndbgstream & s) { return s; }
00364 inline kndbgstream &perror( kndbgstream & s) { return s; }
00365 
00372 kdbgstream kdDebug(int area = 0);
00373 kdbgstream kdDebug(bool cond, int area = 0);
00378 QString kdBacktrace();
00385 QString kdBacktrace(int levels);
00391 inline kndbgstream kndDebug(int = 0) { return kndbgstream(); }
00392 inline kndbgstream kndDebug(bool , int  = 0) { return kndbgstream(); }
00393 inline QString kndBacktrace() { return QString::null; }
00394 
00400 kdbgstream kdWarning(int area = 0);
00401 kdbgstream kdWarning(bool cond, int area = 0);
00407 kdbgstream kdError(int area = 0);
00408 kdbgstream kdError(bool cond, int area = 0);
00414 kdbgstream kdFatal(int area = 0);
00415 kdbgstream kdFatal(bool cond, int area = 0);
00416 
00417 #ifdef NDEBUG
00418 #define kdDebug kndDebug
00419 #define kdBacktrace kndBacktrace
00420 #endif
00421 
00422 #endif
00423 
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:40 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001