Define _CRT_NONSTDC_NO_WARNINGS for zlib compilation with MSVC.
[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 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_RECGUARD_H_
12 #define _WX_RECGUARD_H_
13
14 #include "wx/defs.h"
15
16 // ----------------------------------------------------------------------------
17 // wxRecursionGuardFlag is used with wxRecursionGuard
18 // ----------------------------------------------------------------------------
19
20 typedef int wxRecursionGuardFlag;
21
22 // ----------------------------------------------------------------------------
23 // wxRecursionGuard is the simplest way to protect a function from reentrancy
24 // ----------------------------------------------------------------------------
25
26 class WXDLLIMPEXP_BASE wxRecursionGuard
27 {
28 public:
29 wxRecursionGuard(wxRecursionGuardFlag& flag)
30 : m_flag(flag)
31 {
32 m_isInside = flag++ != 0;
33 }
34
35 ~wxRecursionGuard()
36 {
37 wxASSERT_MSG( m_flag > 0, wxT("unbalanced wxRecursionGuards!?") );
38
39 m_flag--;
40 }
41
42 bool IsInside() const { return m_isInside; }
43
44 private:
45 wxRecursionGuardFlag& m_flag;
46
47 // true if the flag had been already set when we were created
48 bool m_isInside;
49 };
50
51 #endif // _WX_RECGUARD_H_
52