DUNE-FEM (unstable)

debug.hh
1#ifndef DUNE_FEM_DEBUG_HH
2#define DUNE_FEM_DEBUG_HH
3
4#include <cassert>
5
6namespace 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
74 {
75#ifdef USE_DEBUG_CNT
76 ++count_;
77#endif
78 return *this;
79 }
80
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 DebugLock ( const ThisType& ) = delete;
159 ThisType& operator= ( const ThisType& ) = delete;
160
161 inline bool operator ! () const
162 {
163#ifdef USE_DEBUG_CNT
164 return !lock_;
165#else
166 return true;
167#endif
168 }
169
170 inline void lock ()
171 {
172#ifdef USE_DEBUG_CNT
173 assert( !lock_ );
174 lock_ = true;
175#endif
176 }
177
178 inline void unlock ()
179 {
180#ifdef USE_DEBUG_CNT
181 assert( lock_ );
182 lock_ = false;
183#endif
184 }
185 };
186
187 } // namespace Fem
188
189} // namespace Dune
190
191#endif
A counter only present if NDEBUG is not defined.
Definition: debug.hh:30
DebugCounter(const ThisType &other)
copy constructor
Definition: debug.hh:60
bool operator==(const ThisType &other)
comparison for equality
Definition: debug.hh:107
bool operator!=(const ThisType &other)
comparison for inequality
Definition: debug.hh:128
ThisType & operator++()
increment operator
Definition: debug.hh:73
DebugCounter(const CounterType count=0)
constructor
Definition: debug.hh:51
ThisType & operator--()
decrement operator
Definition: debug.hh:87
CounterImp CounterType
integral type for the actual counting
Definition: debug.hh:33
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)