dune-fem  2.4.1-rc
debug.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DEBUG_HH
2 #define DUNE_FEM_DEBUG_HH
3 
4 #include <cassert>
5 
6 namespace Dune
7 {
8 
9  namespace Fem
10  {
11 
12 #if not defined NDEBUG
13 #define USE_DEBUG_CNT
14 #endif
15 
28  template< class CounterImp = unsigned int >
30  {
31  public:
33  typedef CounterImp CounterType;
34 
35  private:
37 
38  protected:
39 #ifdef USE_DEBUG_CNT
40  CounterType count_;
41 #endif
42 
43  public:
51  inline DebugCounter ( const CounterType count = 0 )
52 #ifdef USE_DEBUG_CNT
53  : count_( count )
54 #endif
55  {
56  }
57 
60  inline DebugCounter ( const ThisType &other )
61 #ifdef USE_DEBUG_CNT
62  : count_( other.count_ )
63 #endif
64  {
65  }
66 
73  inline ThisType &operator++ ()
74  {
75 #ifdef USE_DEBUG_CNT
76  ++count_;
77 #endif
78  return *this;
79  }
80 
87  inline ThisType &operator-- ()
88  {
89 #ifdef USE_DEBUG_CNT
90  --count_;
91 #endif
92  return *this;
93  }
94 
107  inline bool operator== ( const ThisType &other )
108  {
109 #ifdef USE_DEBUG_CNT
110  return count_ == other.count_;
111 #else
112  return true;
113 #endif
114  }
115 
128  inline bool operator!= ( const ThisType &other )
129  {
130 #ifdef USE_DEBUG_CNT
131  return count_ != other.count_;
132 #else
133  return true;
134 #endif
135  }
136  };
137 
138 
139 
140  class DebugLock
141  {
142  private:
143  typedef DebugLock ThisType;
144 
145  protected:
146 #ifdef USE_DEBUG_CNT
147  bool lock_;
148 #endif
149 
150  public:
151  inline DebugLock ()
152 #ifdef USE_DEBUG_CNT
153  : lock_( false )
154 #endif
155  {
156  }
157 
158  private:
159  // prohibit copying
160  DebugLock ( const ThisType & );
161 
162  // prohibit copying
163  ThisType &operator= ( const ThisType & );
164 
165  public:
166  inline bool operator ! () const
167  {
168 #ifdef USE_DEBUG_CNT
169  return !lock_;
170 #else
171  return true;
172 #endif
173  }
174 
175  inline void lock ()
176  {
177 #ifdef USE_DEBUG_CNT
178  assert( !lock_ );
179  lock_ = true;
180 #endif
181  }
182 
183  inline void unlock ()
184  {
185 #ifdef USE_DEBUG_CNT
186  assert( lock_ );
187  lock_ = false;
188 #endif
189  }
190  };
191 
192  } // namespace Fem
193 
194 } // namespace Dune
195 
196 #endif
void lock()
Definition: debug.hh:175
ThisType & operator++()
increment operator
Definition: debug.hh:73
DebugCounter(const CounterType count=0)
constructor
Definition: debug.hh:51
CounterImp CounterType
integral type for the actual counting
Definition: debug.hh:33
Definition: debug.hh:140
ThisType & operator--()
decrement operator
Definition: debug.hh:87
bool operator==(const ThisType &other)
comparison for equality
Definition: debug.hh:107
Definition: coordinate.hh:4
DebugCounter(const ThisType &other)
copy constructor
Definition: debug.hh:60
A counter only present if NDEBUG is not defined.
Definition: debug.hh:29
DebugLock()
Definition: debug.hh:151
bool operator!=(const ThisType &other)
comparison for inequality
Definition: debug.hh:128
void unlock()
Definition: debug.hh:183