/src/wxwidgets/include/wx/recguard.h
Line | Count | Source (jump to first uncovered line) |
1 | | /////////////////////////////////////////////////////////////////////////////// |
2 | | // Name: wx/recguard.h |
3 | | // Purpose: declaration and implementation of wxRecursionGuard class |
4 | | // Author: Vadim Zeitlin |
5 | | // Created: 14.08.2003 |
6 | | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
7 | | // Licence: wxWindows licence |
8 | | /////////////////////////////////////////////////////////////////////////////// |
9 | | |
10 | | #ifndef _WX_RECGUARD_H_ |
11 | | #define _WX_RECGUARD_H_ |
12 | | |
13 | | #include "wx/defs.h" |
14 | | |
15 | | // ---------------------------------------------------------------------------- |
16 | | // wxRecursionGuardFlag is used with wxRecursionGuard |
17 | | // ---------------------------------------------------------------------------- |
18 | | |
19 | | typedef int wxRecursionGuardFlag; |
20 | | |
21 | | // ---------------------------------------------------------------------------- |
22 | | // wxRecursionGuard is the simplest way to protect a function from reentrancy |
23 | | // ---------------------------------------------------------------------------- |
24 | | |
25 | | class WXDLLIMPEXP_BASE wxRecursionGuard |
26 | | { |
27 | | public: |
28 | | wxRecursionGuard(wxRecursionGuardFlag& flag) |
29 | 0 | : m_flag(flag) |
30 | 0 | { |
31 | 0 | m_isInside = flag++ != 0; |
32 | 0 | } |
33 | | |
34 | | ~wxRecursionGuard() |
35 | 0 | { |
36 | 0 | wxASSERT_MSG( m_flag > 0, wxT("unbalanced wxRecursionGuards!?") ); |
37 | |
|
38 | 0 | m_flag--; |
39 | 0 | } |
40 | | |
41 | 0 | bool IsInside() const { return m_isInside; } |
42 | | |
43 | | private: |
44 | | wxRecursionGuardFlag& m_flag; |
45 | | |
46 | | // true if the flag had been already set when we were created |
47 | | bool m_isInside; |
48 | | }; |
49 | | |
50 | | #endif // _WX_RECGUARD_H_ |
51 | | |