[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: [RFC] kdebug patch
From:       Thomas Braxton <brax108 () cox ! net>
Date:       2005-08-30 21:50:48
Message-ID: 200508301650.48801.brax108 () cox ! net
[Download RAW message or body]

On Tuesday 30 August 2005 11:07 am, David Faure wrote:
>
> Oh! OK, sorry, I misunderstood.
> No problem then.
> Except that I can't apply the patch:
>
> patching file kdebug.cpp
> Hunk #6 FAILED at 496.
> 1 out of 7 hunks FAILED -- saving rejects to file kdebug.cpp.rej
> patching file kdebug.h
>
> Instead of me patching by hand (this hunk is very big), can you "svn
> update" so that svn does the merging?
> Thanks a lot.
here is a new patch that should merge cleanly

I also noticed a couple of other things:
1) should we even document the API of kndbgstream or should we just put a note 
that any function that operates on kdbgstream should have a corresponding 
function for kndbgstream that does nothing?
2) The implementation of operator<< for most classes should modify d->output 
directly instead of calling operator<<(QString).
If you want I can get these changed right away, then I think I'll be done with 
kdebug

["kdelibs-kdebug.patch" (text/x-diff)]

Index: kdecore/kdebug.cpp
===================================================================
--- kdecore/kdebug.cpp	(revision 455243)
+++ kdecore/kdebug.cpp	(working copy)
@@ -35,7 +35,7 @@
 #include <qmessagebox.h>
 #include <klocale.h>
 #include <qfile.h>
-#include <q3intdict.h>
+#include <qhash.h>
 
 #include <qstring.h>
 #include <qdatetime.h>
@@ -64,32 +64,28 @@
 #include <execinfo.h>
 #endif
 
-class KDebugEntry;
-
-class KDebugEntry
+struct KDebugEntry
 {
-public:
-    KDebugEntry (int n, const QByteArray& d) {number=n; descr=d;}
+    KDebugEntry (unsigned int n = 0, const QByteArray& d = QByteArray()) {number=n; \
descr=d;}  unsigned int number;
     QByteArray descr;
 };
 
-static Q3IntDict<KDebugEntry> *KDebugCache;
+typedef QHash<unsigned int, KDebugEntry> debug_cache;
+static debug_cache *KDebugCache;
 
-static KStaticDeleter< Q3IntDict<KDebugEntry> > kdd;
+static KStaticDeleter< debug_cache > kdd;
 
 static QByteArray getDescrFromNum(unsigned int _num)
 {
   if (!KDebugCache) {
-    kdd.setObject(KDebugCache, new Q3IntDict<KDebugEntry>( 601 ));
+    kdd.setObject(KDebugCache, new debug_cache);
     // Do not call this deleter from ~KApplication
     KGlobal::unregisterStaticDeleter(&kdd);
-    KDebugCache->setAutoDelete(true);
   }
 
-  KDebugEntry *ent = KDebugCache->find( _num );
-  if ( ent )
-    return ent->descr;
+  if ( KDebugCache->contains( _num ) )
+    return KDebugCache->value( _num ).descr;
 
   if ( !KDebugCache->isEmpty() ) // areas already loaded
     return QByteArray();
@@ -131,18 +127,17 @@
           ch=line[++i];
       } while ( ch >= '0' && ch <= '9');
 
-      const Q_ULONG number = QString( line.mid(numStart,i) ).toULong(); // ###
+      unsigned int number = QString( line.mid(numStart,i) ).toUInt(); // ###
 
       while (line[i] && line[i] <= ' ')
         i++;
 
-      KDebugCache->insert(number, new KDebugEntry(number, line.mid(i, len-i-1)));
+      KDebugCache->insert(number, KDebugEntry(number, line.mid(i, len-i-1)));
   }
   file.close();
 
-  ent = KDebugCache->find( _num );
-  if ( ent )
-      return ent->descr;
+  if ( KDebugCache->contains( _num ) )
+      return KDebugCache->value( _num ).descr;
 
   return QByteArray();
 }
@@ -198,7 +193,7 @@
   }
 
   if (kDebug_data->config && kDebug_data->oldarea != nArea) {
-    kDebug_data->config->setGroup( QString::number(static_cast<int>(nArea)) );
+    kDebug_data->config->setGroup( QString::number(nArea) );
     kDebug_data->oldarea = nArea;
     if ( nArea > 0 && KGlobal::_instance )
       kDebug_data->aAreaName = getDescrFromNum(nArea);
@@ -314,112 +309,168 @@
         abort();
 }
 
-kdbgstream &perror( kdbgstream &s) { return s << \
                QString::fromLocal8Bit(strerror(errno)); }
-kdbgstream kdDebug(int area) { return kdbgstream(area, KDEBUG_INFO); }
-kdbgstream kdDebug(bool cond, int area) { if (cond) return kdbgstream(area, \
KDEBUG_INFO); else return kdbgstream(0, 0, false); } +kdbgstream &perror( kdbgstream \
&s) +{
+    return s << QString::fromLocal8Bit(strerror(errno));
+}
+kdbgstream kdDebug(int area)
+{
+    return kdbgstream(area, KDEBUG_INFO);
+}
+kdbgstream kdDebug(bool cond, int area)
+{
+    if (cond)
+        return kdDebug(area);
+    return kdbgstream(0, 0, false);
+}
 
-kdbgstream kdError(int area) { return kdbgstream("ERROR: ", area, KDEBUG_ERROR); }
-kdbgstream kdError(bool cond, int area) { if (cond) return kdbgstream("ERROR: ", \
                area, KDEBUG_ERROR); else return kdbgstream(0,0,false); }
-kdbgstream kdWarning(int area) { return kdbgstream("WARNING: ", area, KDEBUG_WARN); \
                }
-kdbgstream kdWarning(bool cond, int area) { if (cond) return kdbgstream("WARNING: ", \
                area, KDEBUG_WARN); else return kdbgstream(0,0,false); }
-kdbgstream kdFatal(int area) { return kdbgstream("FATAL: ", area, KDEBUG_FATAL); }
-kdbgstream kdFatal(bool cond, int area) { if (cond) return kdbgstream("FATAL: ", \
area, KDEBUG_FATAL); else return kdbgstream(0,0,false); } +kdbgstream kdError(int \
area) +{
+    return kdbgstream("ERROR: ", area, KDEBUG_ERROR);
+}
+kdbgstream kdError(bool cond, int area)
+{
+    if (cond)
+        return kdError(area);
+    return kdbgstream(0,0,false);
+}
 
-kdbgstream::kdbgstream(kdbgstream &str)
- : output(str.output), area(str.area), level(str.level), print(str.print) 
-{ 
-    str.output.truncate(0); 
+kdbgstream kdWarning(int area)
+{
+    return kdbgstream("WARNING: ", area, KDEBUG_WARN);
 }
+kdbgstream kdWarning(bool cond, int area)
+{
+     if (cond)
+         return kdWarning(area);
+     return kdbgstream(0,0,false);
+}
 
+kdbgstream kdFatal(int area)
+{
+    return kdbgstream("FATAL: ", area, KDEBUG_FATAL);
+}
+kdbgstream kdFatal(bool cond, int area)
+{
+    if (cond)
+        return kdFatal(area);
+    return kdbgstream(0,0,false);
+}
+
+struct kdbgstream::Private {
+    QString output;
+    unsigned int area, level;
+    bool print;
+    Private(const Private& p)
+        : output(p.output), area(p.area), level(p.level), print(p.print) { ; }
+    Private(const QString& str, uint a, uint lvl, bool p)
+        : output(str), area(a), level(lvl), print(p)  { ; }
+    Private(unsigned int a, unsigned int l, bool p)
+        : area(a), level(l), print(p)  { ; }
+};
+
+kdbgstream::kdbgstream(unsigned int _area, unsigned int _level, bool _print)
+    : d(new Private(_area, _level, _print))
+{
+}
+
+kdbgstream::kdbgstream(const char * initialString, unsigned int _a,
+                       unsigned int _lvl, bool _p)
+    : d(new Private(QString::fromLatin1(initialString), _a, _lvl, _p))
+{
+}
+
+kdbgstream::kdbgstream(const kdbgstream &str)
+    : d(new Private(*(str.d)))
+{
+    str.d->output.truncate(0);
+}
+
 void kdbgstream::flush() {
-    if (output.isEmpty() || !print)
+    if (d->output.isEmpty() || !d->print)
 	return;
-    kDebugBackend( level, area, output.local8Bit().data() );
-    output = QString::null;
+    kDebugBackend( d->level, d->area, d->output.local8Bit().data() );
+    d->output = QString::null;
 }
 
 kdbgstream &kdbgstream::form(const char *format, ...)
 {
+    if (!d->print)
+        return *this;
+
     char buf[4096];
     va_list arguments;
     va_start( arguments, format );
     qvsnprintf( buf, sizeof(buf), format, arguments );
     va_end(arguments);
     *this << buf;
+
     return *this;
 }
 
-kdbgstream::~kdbgstream() {
-    if (!output.isEmpty()) {
+kdbgstream::~kdbgstream()
+{
+    if (!d->output.isEmpty()) {
 	fprintf(stderr, "ASSERT: debug output not ended with \\n\n");
         fprintf(stderr, "%s", kdBacktrace().latin1());
 	*this << "\n";
     }
+    delete d;
 }
 
-kdbgstream& kdbgstream::operator << (char ch)
+kdbgstream& kdbgstream::operator << (QChar ch)
 {
-  if (!print) return *this;
-  if (!isprint(ch))
-    output += "\\x" + QString::number( static_cast<uint>( ch ), 16 ).rightJustify(2, \
                '0');
-  else {
-    output += ch;
-    if (ch == '\n') flush();
-  }
-  return *this;
+    if (!d->print)
+        return *this;
+
+    if (!ch.isPrint())
+        d->output += QString("\\x")
+	          + QString::number(ch.unicode(), 16).rightJustified(2, '0');
+    else {
+        d->output += ch;
+        if (ch == '\n')
+            flush();
+    }
+
+    return *this;
 }
 
-kdbgstream& kdbgstream::operator << (QChar ch)
+kdbgstream& kdbgstream::operator<<(const QString& string)
 {
-  if (!print) return *this;
-  if (!ch.isPrint())
-    output += "\\x" + QString::number( ch.unicode(), 16 ).rightJustify(2, '0');
-  else {
-    output += ch;
-    if (ch == '\n') flush();
-  }
-  return *this;
-}
+    if (!d->print)
+        return *this;
 
-kdbgstream& kdbgstream::operator << (QWidget* widget)
-{
-    return *this << const_cast< const QWidget* >( widget );
+    d->output += string;
+    if (d->output.length() && d->output.at(d->output.length() -1 ) == '\n')
+        flush();
+    return *this;
 }
 
 kdbgstream& kdbgstream::operator << (const QWidget* widget)
 {
-  QString string, temp;
+  if (!d->print)
+      return *this;
+
+  QString string;
   // -----
   if(widget==0)
     {
-      string=(QString)"[Null pointer]";
+      string=QString("[Null pointer]");
     } else {
-      temp.setNum((ulong)widget, 16);
-      string=(QString)"["+widget->className()+" pointer "
-	+ "(0x" + temp + ")";
-      if(widget->name(0)==0)
-	{
+      string = QString("[%1 pointer(0x%2)").arg(widget->className())
+                    .arg(QString::number(ulong(widget), 16)
+		         .rightJustified(8, '0'));
+      if(widget->objectName().isEmpty()) {
 	  string += " to unnamed widget, ";
-	} else {
-	  string += (QString)" to widget " + widget->name() + ", ";
-	}
-      string += "geometry="
-	+ QString().setNum(widget->width())
-	+ "x"+QString().setNum(widget->height())
-	+ "+"+QString().setNum(widget->x())
-	+ "+"+QString().setNum(widget->y())
-	+ "]";
+      } else {
+	  string += QString(" to widget %1, ").arg(widget->objectName());
+      }
+      string += QString("geometry=%1x%2+%3+%4]").arg(widget->width())
+                     .arg(widget->height())
+		     .arg(widget->x())
+		     .arg(widget->y());
     }
-  if (!print)
-    {
-      return *this;
-    }
-  output += string;
-  if (output.at(output.length() -1 ) == '\n')
-    {
-      flush();
-    }
-  return *this;
+  return *this << string;
 }
 /*
  * either use 'output' directly and do the flush if needed
@@ -432,23 +483,31 @@
 }
 kdbgstream& kdbgstream::operator<<( const QDate& date) {
     *this << date.toString();
-
     return *this;
 }
 kdbgstream& kdbgstream::operator<<( const QTime& time ) {
     *this << time.toString();
     return *this;
 }
+kdbgstream& kdbgstream::operator<<( KDBGFUNC f ) {
+    if (!d->print) return *this;
+    return (*f)(*this);
+}
 kdbgstream& kdbgstream::operator<<( const QPoint& p ) {
-    *this << "(" << p.x() << ", " << p.y() << ")";
+    *this << QString("(%1, %2)").arg(p.x()).arg(p.y());
     return *this;
 }
 kdbgstream& kdbgstream::operator<<( const QSize& s ) {
-    *this << "[" << s.width() << "x" << s.height() << "]";
+    *this << QString("[%1x%2]").arg(s.width()).arg(s.height());
     return *this;
 }
+static QString s_rectString(const QRect& r)
+{
+    QString str("%1,%2 - %3x%4]");
+    return str.arg(r.x()).arg(r.y()).arg(r.width()).arg(r.height());
+}
 kdbgstream& kdbgstream::operator<<( const QRect& r ) {
-    *this << "[" << r.x() << "," << r.y() << " - " << r.width() << "x" << r.height() \
<< "]"; +    *this << s_rectString( r );
     return *this;
 }
 kdbgstream& kdbgstream::operator<<( const QRegion& reg ) {
@@ -456,7 +515,7 @@
 
     QVector<QRect>rs=reg.rects();
     for (int i=0;i<rs.size();++i)
-        *this << QString("[%1,%2 - %3x%4] \
").arg(rs[i].x()).arg(rs[i].y()).arg(rs[i].width()).arg(rs[i].height() ) ; +        \
*this << s_rectString( rs[i] ) + ' ';  
     *this <<"]";
     return *this;
@@ -466,38 +525,30 @@
     return *this;
 }
 kdbgstream& kdbgstream::operator<<( const QStringList& l ) {
-    *this << "(";
-    *this << l.join(",");
-    *this << ")";
-
-    return *this;
+    if ( !d->print ) return *this;
+    return *this << static_cast<QList<QString> >(l);
 }
-kdbgstream& kdbgstream::operator<<( const QColor& c ) {
+static QString s_makeColorName(const QColor& c) {
+    QString s("(invalid/default)");
     if ( c.isValid() )
-        *this <<c.name();
-    else
-        *this << "(invalid/default)";
-    return *this;
+        s = c.name();
+    return s;
 }
+kdbgstream& kdbgstream::operator<<( const QColor& c ) {
+    return *this << s_makeColorName( c );
+}
 kdbgstream& kdbgstream::operator<<( const QPen& p ) {
     static const char* const s_penStyles[] = {
         "NoPen", "SolidLine", "DashLine", "DotLine", "DashDotLine",
         "DashDotDotLine" };
     static const char* const s_capStyles[] = {
         "FlatCap", "SquareCap", "RoundCap" };
-    *this << "[ style:";
-    *this << s_penStyles[ p.style() ];
-    *this << " width:";
-    *this << p.width();
-    *this << " color:";
-    if ( p.color().isValid() )
-        *this << p.color().name();
-    else
-        *this <<"(invalid/default)";
+    *this << "[ style:" << s_penStyles[ p.style() ];
+    *this << " width:" << p.width();
+    *this << " color:" << s_makeColorName( p.color() );
     if ( p.width() > 0 ) // cap style doesn't matter, otherwise
     {
-        *this << " capstyle:";
-        *this << s_capStyles[ p.capStyle() >> 4 ];
+        *this << " capstyle:" << s_capStyles[ p.capStyle() >> 4 ];
         // join style omitted
     }
     *this <<" ]";
@@ -508,16 +559,12 @@
         "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", \
                "Dense3Pattern",
         "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
         "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
-        "DiagCrossPattern" };
+        "DiagCrossPattern", "LinearGradientPattern", "ConicalGradientPattern",
+        "RadialGradientPattern", "TexturePattern"
+    };
 
-    *this <<"[ style: ";
-    *this <<s_brushStyles[ b.style() ];
-    *this <<" color: ";
-    // can't use operator<<(str, b.color()) because that terminates a kdbgstream \
                (flushes)
-    if ( b.color().isValid() )
-        *this <<b.color().name() ;
-    else
-        *this <<"(invalid/default)";
+    *this <<"[ style: " << s_brushStyles[ b.style() ];
+    *this <<" color: " << s_makeColorName( b.color() );
     if ( b.pixmap() )
         *this <<" has a pixmap";
     *this <<" ]";
@@ -525,36 +572,35 @@
 }
 
 kdbgstream& kdbgstream::operator<<( const QVariant& v) {
-    *this << "[variant: ";
-    *this << v.typeName();
+    *this << "[variant: " << v.typeName();
     // For now we just attempt a conversion to string.
     // Feel free to switch(v.type()) and improve the output.
-    *this << " toString=";
-    *this << v.toString();
+    if ( v.canConvert(QVariant::String) )
+        *this << " toString=" << v.toString();
     *this << "]";
     return *this;
 }
 
 kdbgstream& kdbgstream::operator<<( const QByteArray& data) {
-    if (!print) return *this;
+    if (!d->print) return *this;
     bool isBinary = false;
     for ( int i = 0; i < data.size() && !isBinary ; ++i ) {
-        if ( data[i] < 32 || data[i] > 127 )
+        if ( data[i] < 32 || (unsigned char)data[i] > 127 )
             isBinary = true;
     }
     if ( isBinary ) {
-        output += '[';
+        d->output += '[';
         int sz = QMIN( data.size(), 64 );
         for ( int i = 0; i < sz ; ++i ) {
-            output += QString::number( (unsigned char) data[i], 16 ).rightJustify(2, \
'0'); +            d->output += QString::number( (unsigned char) data[i], 16 \
).rightJustify(2, '0');  if ( i < sz )
-                output += ' ';
+                d->output += ' ';
         }
         if ( sz < data.size() )
-            output += "...";
-        output += ']';
+            d->output += "...";
+        d->output += ']';
     } else {
-        output += QLatin1String( data );
+        d->output += QLatin1String( data );
     }
     return *this;
 }
@@ -584,18 +630,12 @@
     return s;
 }
 
-QString kdBacktrace()
-{
-    return kdBacktrace(-1 /*all*/);
-}
-
 void kdClearDebugConfig()
 {
     delete kDebug_data->config;
     kDebug_data->config = 0;
 }
 
-
 // Needed for --enable-final
 #ifdef NDEBUG
 #define kdDebug kndDebug
Index: kdecore/kdebug.h
===================================================================
--- kdecore/kdebug.h	(revision 455243)
+++ kdecore/kdebug.h	(working copy)
@@ -82,24 +82,19 @@
   /**
    * @internal
    */
-    kdbgstream(unsigned int _area, unsigned int _level, bool _print = true) :
-      area(_area), level(_level),  print(_print) { }
-    kdbgstream(const char * initialString, unsigned int _area, unsigned int _level, \
                bool _print = true) :
-      output(QString::fromLatin1(initialString)), area(_area), level(_level),  \
print(_print) { } +    kdbgstream(unsigned int _area, unsigned int _level, bool \
_print = true); +    kdbgstream(const char * initialString, unsigned int _area, \
unsigned int _level, bool _print = true);  /// Copy constructor
-    kdbgstream(kdbgstream &str);
-    kdbgstream(const kdbgstream &str) :
-      output(str.output), area(str.area), level(str.level), print(str.print) {}
-    ~kdbgstream();
+    kdbgstream(const kdbgstream &str);
+    virtual ~kdbgstream();
+
     /**
      * Prints the given value.
      * @param i the boolean to print (as "true" or "false")
      * @return this stream
      */
     kdbgstream &operator<<(bool i)  {
-	if (!print) return *this;
-	output += QString::fromLatin1(i ? "true" : "false");
-	return *this;
+        return *this << QString::fromLatin1(i ? "true" : "false" );
     }
     /**
      * Prints the given value.
@@ -107,9 +102,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(short i)  {
-	if (!print) return *this;
-	QString tmp; tmp.setNum(i); output += tmp;
-	return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -117,23 +110,23 @@
      * @return this stream
      */
     kdbgstream &operator<<(unsigned short i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
      * @param ch the char to print
      * @return this stream
      */
-    kdbgstream &operator<<(char ch);
+    kdbgstream& operator<<(char ch) {
+        return *this << QChar(ch);
+    }
     /**
      * Prints the given value.
      * @param ch the unsigned char to print
      * @return this stream
      */
     kdbgstream &operator<<(unsigned char ch) {
-        return operator<<( static_cast<char>( ch ) );
+        return *this << QChar(ch);
     }
     /**
      * Prints the given value.
@@ -141,9 +134,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(int i)  {
-	if (!print) return *this;
-	QString tmp; tmp.setNum(i); output += tmp;
-	return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -151,9 +142,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(unsigned int i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -161,9 +150,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(long i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -171,9 +158,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(unsigned long i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -181,9 +166,7 @@
      * @return this stream
      */
     kdbgstream &operator<<(qlonglong i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
     /**
      * Prints the given value.
@@ -191,15 +174,13 @@
      * @return this stream
      */
     kdbgstream &operator<<(qulonglong i) {
-        if (!print) return *this;
-        QString tmp; tmp.setNum(i); output += tmp;
-        return *this;
+        return *this << QString::number( i );
     }
 
     /**
      * Flushes the output.
      */
-    void flush(); //AB: maybe this should be virtual! would save some trouble for \
some 3rd party projects +    virtual void flush(); 
 
     /**
      * Prints the given value.
@@ -213,24 +194,14 @@
      * @param string the string to print
      * @return this stream
      */
-    kdbgstream &operator<<(const QString& string) {
-	if (!print) return *this;
-	output += string;
-	if (output.length() && output.at(output.length() -1 ) == '\n')
-	    flush();
-	return *this;
-    }
+    kdbgstream &operator<<(const QString& string);
     /**
      * Prints the given value.
      * @param string the string to print
      * @return this stream
      */
     kdbgstream &operator<<(const char *string) {
-	if (!print) return *this;
-	output += QString::fromUtf8(string);
-	if (output.length() && output.at(output.length() - 1) == '\n')
-	    flush();
-	return *this;
+        return *this << QString::fromUtf8(string);
     }
     /**
      * Prints the given value.
@@ -238,26 +209,21 @@
      * @return this stream
      */
     kdbgstream& operator<<(const void * p) {
-        form("%p", p);
-        return *this;
+        return form("%p", p);
     }
     /**
      * Invokes the given function.
      * @param f the function to invoke
      * @return the return value of @p f
      */
-    kdbgstream& operator<<(KDBGFUNC f) {
-	if (!print) return *this;
-	return (*f)(*this);
-    }
+    kdbgstream& operator<<(KDBGFUNC f);
     /**
      * Prints the given value.
      * @param d the double to print
      * @return this stream
      */
     kdbgstream& operator<<(double d) {
-      QString tmp; tmp.setNum(d); output += tmp;
-      return *this;
+        return *this << QString::number( d );
     }
     /**
      * Prints the string @p format which can contain
@@ -265,7 +231,7 @@
      * @param format the printf-style format
      * @return this stream
      */
-    kdbgstream &form(const char *format, ...)
+    kdbgstream& form(const char *format, ...)
 #ifdef __GNUC__
       __attribute__ ( ( format ( printf, 2, 3 ) ) )
 #endif
@@ -277,7 +243,6 @@
      * @return this stream
      */
     kdbgstream& operator << (const QWidget* widget);
-    kdbgstream& operator << (QWidget* widget); // KDE4 merge
 
     /**
      * Prints the given value.
@@ -340,7 +305,6 @@
      * @param list the stringlist to print
      * @return this stream
      */
-    // ### KDE4: Remove in favor of template operator for QValueList<T> below
     kdbgstream& operator << ( const QStringList& list);
 
     /**
@@ -391,23 +355,21 @@
     kdbgstream& operator << ( const QList<T> &list );
 
  private:
-    QString output;
-    unsigned int area, level;
-    bool print;
-    kdbgstreamprivate* d;
+    class Private;
+    mutable Private* d;
 };
 
 template <class T>
 kdbgstream &kdbgstream::operator<<( const QList<T> &list )
 {
     *this << "(";
-    typename QList<T>::ConstIterator it = list.begin();
     if ( !list.isEmpty() ) {
-      *this << *it++;
+      typename QList<T>::ConstIterator it = list.begin();
+      *this << *it;
+      while (++it != list.end()) {
+        *this << "," << *it;
+      }
     }
-    for ( ; it != list.end(); ++it ) {
-      *this << "," << *it;
-    }
     *this << ")";
     return *this;
 }
@@ -418,7 +380,7 @@
  * @param s the debug stream to write to
  * @return the debug stream (@p s)
  */
-inline kdbgstream &endl( kdbgstream &s) { s << "\n"; return s; }
+inline kdbgstream &endl( kdbgstream &s) { return s << "\n"; }
 
 /**
  * \relates KGlobal
@@ -428,6 +390,13 @@
  */
 inline kdbgstream &flush( kdbgstream &s) { s.flush(); return s; }
 
+/**
+ * \relates KGlobal
+ * Print a message describing the last system error.
+ * @param s the debug stream to write to
+ * @return the debug stream (@p s)
+ * @see perror(3)
+ */
 KDECORE_EXPORT kdbgstream &perror( kdbgstream &s);
 
 /**
@@ -540,7 +509,6 @@
      * @return this stream
      */
     kndbgstream& operator << (const QWidget*) { return *this; }
-    kndbgstream& operator << (QWidget*) { return *this; } // KDE4 merge
     /**
      * Does nothing.
      * @return this stream
@@ -587,13 +555,20 @@
  * @see kndDebug()
  */
 KDECORE_EXPORT kdbgstream kdDebug(int area = 0);
+/**
+ * \relates KGlobal
+ * Returns a debug stream. You can use it to conditionally
+ * print debug information.
+ * @param cond the condition to test, if true print debugging info
+ * @param area an id to identify the output, 0 for default
+ */
 KDECORE_EXPORT kdbgstream kdDebug(bool cond, int area = 0);
 /**
  * \relates KGlobal
  * Returns a backtrace.
  * @return a backtrace
  */
-KDECORE_EXPORT QString kdBacktrace();
+//KDECORE_EXPORT QString kdBacktrace();
 /**
  * \relates KGlobal
  * Returns a backtrace.
@@ -601,16 +576,15 @@
  * @return a backtrace
  * @since 3.1
  */
-KDECORE_EXPORT QString kdBacktrace(int levels);
+KDECORE_EXPORT QString kdBacktrace(int levels=-1);
 /**
  * Returns a dummy debug stream. The stream does not print anything.
  * @param area an id to identify the output, 0 for default
  * @see kdDebug()
  */
-inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); return kndbgstream(); }
+inline kndbgstream kndDebug(int = 0) { return kndbgstream(); }
 inline kndbgstream kndDebug(bool , int  = 0) { return kndbgstream(); }
-inline QString kndBacktrace() { return QString::null; }
-inline QString kndBacktrace(int) { return QString::null; }
+inline QString kndBacktrace(int = -1) { return QString(); }
 
 /**
  * \relates KGlobal
@@ -619,6 +593,13 @@
  * @param area an id to identify the output, 0 for default
  */
 KDECORE_EXPORT kdbgstream kdWarning(int area = 0);
+/**
+ * \relates KGlobal
+ * Returns a warning stream. You can use it to conditionally
+ * print warning information.
+ * @param cond the condition to test, if true print warning
+ * @param area an id to identify the output, 0 for default
+ */
 KDECORE_EXPORT kdbgstream kdWarning(bool cond, int area = 0);
 /**
  * \relates KGlobal
@@ -627,6 +608,13 @@
  * @param area an id to identify the output, 0 for default
  */
 KDECORE_EXPORT kdbgstream kdError(int area = 0);
+/**
+ * \relates KGlobal
+ * Returns an error stream. You can use it to conditionally
+ * print error information
+ * @param cond the condition to test, if true print error
+ * @param area an id to identify the output, 0 for default
+ */
 KDECORE_EXPORT kdbgstream kdError(bool cond, int area = 0);
 /**
  * \relates KGlobal
@@ -635,6 +623,13 @@
  * @param area an id to identify the output, 0 for default
  */
 KDECORE_EXPORT kdbgstream kdFatal(int area = 0);
+/**
+ * \relates KGlobal
+ * Returns a fatal error stream. You can use it to conditionally
+ * print error information
+ * @param cond the condition to test, if true print error
+ * @param area an id to identify the output, 0 for default
+ */
 KDECORE_EXPORT kdbgstream kdFatal(bool cond, int area = 0);
 
 /**



 =

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscrib=
e <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic