Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDebug.cpp

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
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/** @example ExampleDebug.cpp
@relates Debug
@brief 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.
@ingroup g_examples
@author woelk 09/2006
*/
#include <Base/Debug/Debug.hh>
using namespace BIAS;
using namespace std;
/** \cond HIDDEN_SYMBOLS*/
class MyDebugClass : public Debug
{
public:
MyDebugClass() : myInt(0)
{
// tell the class abouts its debug levels
NewDebugLevel("DL1");
NewDebugLevel("DL2");
}
inline ~MyDebugClass() {}
void foo(int arg) {
// use new debug output macro
BCDOUT(DL1, "MyDebugClass::foo() : arg = " << arg << endl);
myInt += arg;
BCDOUT(DL2, "MyDebugClass::foo() : myInt = " << myInt << endl);
}
protected:
int myInt; // some internal variable
};
/** \endcond */
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;
}