Demonstrates the usage of debug levels.
The new concept avoids multiple definitions of debug levels.
Example:
file baseclass.hh #define DL_BASE 0x1 class baseclass { foo() { BIASCDOUT(DL_BASE, "output of base class");} }; file subclass.hh #include "baseclass.hh" #define DL_SUB 0x1 class subclass : public baseclass { foo2() { foo(); BIASCDOUT(DL_SUB, "output of subclass"); } };
Now calling
subclass sc; sc.SetDebugLevel(DL_SUB); sc.foo2();
results in the unexpected debug output "output of base class".
To avoid this use the new debug level concept presented here.
- Author
- woelk 09/2006
#include <Base/Debug/Debug.hh>
using namespace BIAS;
using namespace std;
class MyDebugClass :
public Debug
{
public:
MyDebugClass() : myInt(0)
{
NewDebugLevel("DL1");
NewDebugLevel("DL2");
}
inline ~MyDebugClass() {}
void foo(int arg) {
BCDOUT(DL1, "MyDebugClass::foo() : arg = " << arg << endl);
myInt += arg;
BCDOUT(DL2, "MyDebugClass::foo() : myInt = " << myInt << endl);
}
protected:
int myInt;
};
int main(int argc, char *argv[])
{
MyDebugClass mc;
cout << "Show me the available debug levels: " << endl;
mc.ShowDebugLevel();
cout << "Without debug output: " << endl;
mc.foo(5);
cout << "With debuglevel \"DL1\": " << endl;
mc.AddDebugLevel("DL1");
mc.foo(7);
cout << "With debuglevel \"DL1\" and \"DL2\": " << endl;
mc.AddDebugLevel("DL2");
mc.foo(-42);
cout << "Again without debug output: " << endl;
mc.SetDebugLevel(0);
mc.foo(666);
cout << "With debuglevel \"DL2\": " << endl;
mc.AddDebugLevel("DL2");
mc.foo(-42);
cout << "Print current debug level: " << endl;
mc.PrintDebugLevel();
return 0;
}