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

List:       kde-core-devel
Subject:    kDebug idea
From:       Simon Hausmann <hausmann () kde ! org>
Date:       2002-03-31 17:35:51
[Download RAW message or body]

Hi,

There are quite a few places where people use code like this:

// #define DEBUG_FOO

...

#if DEBUG_FOO
kdDebug() << "bleh" << endl;
#endif

A bit like an additional level of control of debug output, on top of
debug areas and kdebugdialog. I think it definitely makes sense to
have/use this. But I think the #ifdef's are ugly and don't
necessarily help to make the code easier to read. So here's a rather
simple idea to provide the same flexibility without the need of
#ifdef:

using namespace KDE::Debug;

...

kDebug() << "bleh" << endl;

If you want to disable kDebug() (notice the missing 'd' :) instead
just import

using namespace KDE::NoDebug;

It's as simple as that:

Index: kdebug.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kdebug.h,v
retrieving revision 1.58
diff -u -p -r1.58 kdebug.h
--- kdebug.h	2002/03/08 21:47:25	1.58
+++ kdebug.h	2002/03/31 17:26:51
@@ -189,5 +189,20 @@ kdbgstream kdFatal(bool cond, int area =
 #define kdBacktrace kndBacktrace
 #endif
 
+namespace KDE
+{
+    namespace Debug
+    {
+        kdbgstream kDebug(int area = 0) { return ::kdDebug( area ); }
+        kdbgstream kDebug(bool cond, int area = 0) { return ::kdDebug( cond, area ); }
+    };
+
+    namespace NoDebug
+    {
+        kndbgstream kDebug(int area = 0) { return ::kndDebug( area ); }
+        kndbgstream kDebug(bool cond, int area = 0) { return ::kndDebug( cond, area ); }
+    };
+};
+
 #endif
 
What do you think?


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

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