]>
git.saurik.com Git - wxWidgets.git/blob - interface/recguard.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxRecursionGuardFlag
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxRecursionGuardFlag
13 This is a completely opaque class which exists only to be used with
14 wxRecursionGuard, please see the example in that class' documentation.
18 wxRecursionGuardFlag object must be declared @c static or the recursion
19 would never be detected.
24 class wxRecursionGuardFlag
33 @class wxRecursionGuard
36 wxRecursionGuard is a very simple class which can be used to prevent reentrancy
37 problems in a function. It is not thread-safe and so should be used only in
38 single-threaded programs or in combination with some thread synchronization
41 wxRecursionGuard is always used together with the
42 wxRecursionGuardFlag like in this example:
47 static wxRecursionGuardFlag s_flag;
48 wxRecursionGuard guard(s_flag);
49 if ( guard.IsInside() )
51 // don't allow reentrancy
59 As you can see, wxRecursionGuard simply tests the flag value and sets it to
60 @true if it hadn't been already set.
61 IsInside() allows testing the old flag
62 value. The advantage of using this class compared to directly manipulating the
63 flag is that the flag is always reset in the wxRecursionGuard destructor and so
64 you don't risk to forget to do it even if the function returns in an unexpected
65 way (for example because an exception has been thrown).
70 class wxRecursionGuard
74 A wxRecursionGuard object must always be initialized with a @c static
75 wxRecursionGuardFlag. The constructor saves the
76 value of the flag to be able to return the correct value from
79 wxRecursionGuard(wxRecursionGuardFlag
& flag
);
82 The destructor resets the flag value so that the function can be entered again
85 @note This is not virtual, so this class is not meant to be derived
86 from (besides, there is absolutely no reason to do it anyhow).
91 Returns @true if we're already inside the code block "protected" by this
92 wxRecursionGuard (i.e. between this line and the end of current scope).
93 Usually the function using wxRecursionGuard takes some specific actions
94 in such case (may be simply returning) to prevent reentrant calls to itself.
96 If this method returns @false, it is safe to continue.
98 bool IsInside() const;