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