]> git.saurik.com Git - wxWidgets.git/blob - include/wx/recguard.h
Regenerate to add the new file toucan.png.
[wxWidgets.git] / include / wx / recguard.h
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$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
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)
32 {
33 m_isInside = flag++ != 0;
34 }
35
36 ~wxRecursionGuard()
37 {
38 wxASSERT_MSG( m_flag > 0, _T("unbalanced wxRecursionGuards!?") );
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