[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: [RFC] kdebug patch
From: Thomas Braxton <brax108 () cox ! net>
Date: 2005-08-29 6:42:38
Message-ID: 200508290142.38304.brax108 () cox ! net
[Download RAW message or body]
This patch cleans up kdebug.{cpp,h}. It removes all Qt3 classes and removes
all functions specified with KDE4: remove/merge, except
operator<<(QStringList) because it is a subclass of QList<QString>,
so I reimplemented it as such. It also moves all member variables into a
d-pointer.
["kdelibs-kdebug.diff" (text/x-diff)]
Index: kdecore/kdebug.cpp
===================================================================
--- kdecore/kdebug.cpp (revision 454155)
+++ 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);
@@ -309,117 +304,179 @@
}
// check if we should abort
- if( ( nLevel == KDEBUG_FATAL )
- && ( !kDebug_data->config || kDebug_data->config->readNumEntry( "AbortFatal", \
1 ) ) ) + if( ( nLevel == KDEBUG_FATAL ) &&
+ ( !kDebug_data->config ||
+ kDebug_data->config->readNumEntry( "AbortFatal", 1 ) ) )
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 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)))
+{
+}
+
kdbgstream::kdbgstream(kdbgstream &str)
- : output(str.output), area(str.area), level(str.level), print(str.print)
+ : d(new Private(*(str.d)))
{
- str.output.truncate(0);
+ 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->name(0)==0) {
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->name());
+ }
+ 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
@@ -439,122 +496,151 @@
*this << time.toString();
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QPoint& p ) {
- *this << "(" << p.x() << ", " << p.y() << ")";
+kdbgstream& kdbgstream::operator<<(KDBGFUNC f)
+{
+ if (!d->print)
+ return *this;
+
+ return (*f)(*this);
+}
+kdbgstream& kdbgstream::operator<<( const QPoint& p )
+{
+ *this << QString("(%1, $2)").arg(p.x()).arg(p.y());
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QSize& s ) {
- *this << "[" << s.width() << "x" << s.height() << "]";
+kdbgstream& kdbgstream::operator<<( const QSize& s )
+{
+ *this << QString("[%1x%2]").arg(s.width()).arg(s.height());
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QRect& r ) {
- *this << "[" << r.x() << "," << r.y() << " - " << r.width() << "x" << r.height() \
<< "]"; +kdbgstream& kdbgstream::operator<<( const QRect& r )
+{
+ *this << QString("[%1,%2 - %3x%4] ").arg(r.x()).arg(r.y())
+ .arg(r.width()).arg(r.height() ) ;
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QRegion& reg ) {
- *this<< "[ ";
+kdbgstream& kdbgstream::operator<<( const QRegion& reg )
+{
+ if (!d->print)
+ return *this;
+ QString tmp("[ ");
+
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 <<"]";
- return *this;
+ for (int i=0;i<rs.size();i++) {
+ QRect r(rs[i]);
+ tmp += QString("[%1,%2 - %3x%4] ").arg(r.x()).arg(r.y())
+ .arg(r.width()).arg(r.height()) ;
+ }
+ tmp += ']';
+ return *this << tmp;
}
kdbgstream& kdbgstream::operator<<( const KURL& u ) {
*this << u.prettyURL();
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QStringList& l ) {
- *this << "(";
- *this << l.join(",");
- *this << ")";
+kdbgstream& kdbgstream::operator<<( const QStringList& l )
+{
+ if (!d->print)
+ return *this;
+ *this << static_cast<QList<QString> >(l);
return *this;
}
-kdbgstream& kdbgstream::operator<<( const QColor& c ) {
- if ( c.isValid() )
- *this <<c.name();
- else
- *this << "(invalid/default)";
- return *this;
+
+static QString s_makeColorName(const QColor& c)
+{
+ QString s("(invalid/default)");
+ if (c.isValid())
+ s = c.name();
+
+ return s;
}
-kdbgstream& kdbgstream::operator<<( const QPen& p ) {
+
+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" };
+ "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)";
+ "FlatCap", "SquareCap", "RoundCap"
+ };
+ QString tmp = QString("[ style:%1 width:%2 color: %3")
+ .arg(s_penStyles[p.style()])
+ .arg(p.width())
+ .arg(s_makeColorName(p.color()));
+
if ( p.width() > 0 ) // cap style doesn't matter, otherwise
{
- *this << " capstyle:";
- *this << s_capStyles[ p.capStyle() >> 4 ];
+ tmp += QString(" capstyle:%1").arg(s_capStyles[ p.capStyle() >> 4 ]);
// join style omitted
}
- *this <<" ]";
- return *this;
+ tmp += " ]";
+
+ return *this << tmp;
}
-kdbgstream& kdbgstream::operator<<( const QBrush& b) {
+kdbgstream& kdbgstream::operator<<( const QBrush& b)
+{
static const char* const s_brushStyles[] = {
- "NoBrush", "SolidPattern", "Dense1Pattern", "Dense2Pattern", \
"Dense3Pattern",
- "Dense4Pattern", "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
- "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern", "FDiagPattern",
- "DiagCrossPattern" };
+ "NoBrush", "SolidPattern", "Dense1Pattern",
+ "Dense2Pattern", "Dense3Pattern", "Dense4Pattern",
+ "Dense5Pattern", "Dense6Pattern", "Dense7Pattern",
+ "HorPattern", "VerPattern", "CrossPattern", "BDiagPattern",
+ "FDiagPattern", "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)";
+ QString tmp = QString("[ style: %1 color: %2")
+ .arg(s_brushStyles[ b.style() ])
+ .arg(s_makeColorName(b.color()));
if ( b.pixmap() )
- *this <<" has a pixmap";
- *this <<" ]";
- return *this;
+ tmp += " has a pixmap";
+ tmp += " ]";
+
+ return *this << tmp;
}
-kdbgstream& kdbgstream::operator<<( const QVariant& v) {
+kdbgstream& kdbgstream::operator<<( const QVariant& v)
+{
*this << "[variant: ";
*this << 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;
+kdbgstream& kdbgstream::operator<<( const QByteArray& data)
+{
+ if (!d->print)
+ return *this;
+
bool isBinary = false;
for ( int i = 0; i < data.size() && !isBinary ; ++i ) {
if ( data[i] < 32 )
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 +670,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 454155)
+++ kdecore/kdebug.h (working copy)
@@ -82,24 +82,20 @@
/**
* @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 +103,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 +111,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 +135,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 +143,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 +151,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 +159,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 +167,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 +175,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 +195,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 +210,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 +232,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 +244,6 @@
* @return this stream
*/
kdbgstream& operator << (const QWidget* widget);
- kdbgstream& operator << (QWidget* widget); // KDE4 merge
/**
* Prints the given value.
@@ -340,7 +306,7 @@
* @param list the stringlist to print
* @return this stream
*/
- // ### KDE4: Remove in favor of template operator for QValueList<T> below
+ // ### KDE4: Remove in favor of template operator for QList<T> below
kdbgstream& operator << ( const QStringList& list);
/**
@@ -391,23 +357,21 @@
kdbgstream& operator << ( const QList<T> &list );
private:
- QString output;
- unsigned int area, level;
- bool print;
- kdbgstreamprivate* d;
+ class Private;
+ 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 +382,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
@@ -540,7 +504,6 @@
* @return this stream
*/
kndbgstream& operator << (const QWidget*) { return *this; }
- kndbgstream& operator << (QWidget*) { return *this; } // KDE4 merge
/**
* Does nothing.
* @return this stream
@@ -587,13 +550,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,7 +571,7 @@
* @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
@@ -609,8 +579,7 @@
*/
inline kndbgstream kndDebug(int area = 0) { Q_UNUSED(area); 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::null; }
/**
* \relates KGlobal
@@ -619,6 +588,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 +603,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 +618,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