Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDebug.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 /** @example ExampleDebug.cpp
26  @relates Debug
27  @brief Demonstrates the usage of debug levels.
28 
29  The new concept avoids multiple definitions of debug levels.
30 
31  Example:
32 
33  // file baseclass.hh
34  #define DL_BASE 0x1
35  class baseclass {
36  foo() { BIASCDOUT(DL_BASE, "output of base class");}
37  };
38  // file subclass.hh
39  #include "baseclass.hh"
40  #define DL_SUB 0x1
41  class subclass : public baseclass
42  {
43  foo2() { foo(); BIASCDOUT(DL_SUB, "output of subclass"); }
44  };
45 
46  Now calling
47 
48  subclass sc;
49  sc.SetDebugLevel(DL_SUB);
50  sc.foo2();
51 
52  results in the unexpected debug output "output of base class".
53 
54  To avoid this use the new debug level concept presented here.
55  @ingroup g_examples
56  @author woelk 09/2006
57 */
58 
59 #include <Base/Debug/Debug.hh>
60 
61 using namespace BIAS;
62 using namespace std;
63 
64 /** \cond HIDDEN_SYMBOLS*/
65 class MyDebugClass : public Debug
66 {
67 public:
68 
69  MyDebugClass() : myInt(0)
70  {
71  // tell the class abouts its debug levels
72  NewDebugLevel("DL1");
73  NewDebugLevel("DL2");
74  }
75 
76  inline ~MyDebugClass() {}
77 
78  void foo(int arg) {
79  // use new debug output macro
80  BCDOUT(DL1, "MyDebugClass::foo() : arg = " << arg << endl);
81  myInt += arg;
82  BCDOUT(DL2, "MyDebugClass::foo() : myInt = " << myInt << endl);
83  }
84 
85 protected:
86 
87  int myInt; // some internal variable
88 
89 };
90 
91 /** \endcond */
92 
93 int main(int argc, char *argv[])
94 {
95  MyDebugClass mc;
96  cout << "Show me the available debug levels: " << endl;
97  mc.ShowDebugLevel();
98  cout << "Without debug output: " << endl;
99  mc.foo(5);
100  cout << "With debuglevel \"DL1\": " << endl;
101  mc.AddDebugLevel("DL1");
102  mc.foo(7);
103  cout << "With debuglevel \"DL1\" and \"DL2\": " << endl;
104  mc.AddDebugLevel("DL2");
105  mc.foo(-42);
106  cout << "Again without debug output: " << endl;
107  mc.SetDebugLevel(0);
108  mc.foo(666);
109  cout << "With debuglevel \"DL2\": " << endl;
110  mc.AddDebugLevel("DL2");
111  mc.foo(-42);
112  cout << "Print current debug level: " << endl;
113  mc.PrintDebugLevel();
114  return 0;
115 }