]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/recguard.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxRecursionGuardFlag
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 @class wxRecursionGuardFlag
11 This is a completely opaque class which exists only to be used with
12 wxRecursionGuard, please see the example in that class' documentation.
16 wxRecursionGuardFlag object must be declared @c static or the recursion
17 would never be detected.
22 class wxRecursionGuardFlag
31 @class wxRecursionGuard
33 wxRecursionGuard is a very simple class which can be used to prevent reentrancy
34 problems in a function. It is not thread-safe and so should be used only in
35 single-threaded programs or in combination with some thread synchronization
38 wxRecursionGuard is always used together with the
39 wxRecursionGuardFlag like in this example:
44 static wxRecursionGuardFlag s_flag;
45 wxRecursionGuard guard(s_flag);
46 if ( guard.IsInside() )
48 // don't allow reentrancy
56 As you can see, wxRecursionGuard simply tests the flag value and sets it to
57 @true if it hadn't been already set.
58 IsInside() allows testing the old flag
59 value. The advantage of using this class compared to directly manipulating the
60 flag is that the flag is always reset in the wxRecursionGuard destructor and so
61 you don't risk to forget to do it even if the function returns in an unexpected
62 way (for example because an exception has been thrown).
67 class wxRecursionGuard
71 A wxRecursionGuard object must always be initialized with a @c static
72 wxRecursionGuardFlag. The constructor saves the
73 value of the flag to be able to return the correct value from
76 wxRecursionGuard(wxRecursionGuardFlag
& flag
);
79 The destructor resets the flag value so that the function can be entered again
82 @note This is not virtual, so this class is not meant to be derived
83 from (besides, there is absolutely no reason to do it anyhow).
88 Returns @true if we're already inside the code block "protected" by this
89 wxRecursionGuard (i.e. between this line and the end of current scope).
90 Usually the function using wxRecursionGuard takes some specific actions
91 in such case (may be simply returning) to prevent reentrant calls to itself.
93 If this method returns @false, it is safe to continue.
95 bool IsInside() const;