$szTitle = "wxrecursionguard"; include "./_header.inc"; ?>
wxrecursionguard is a very simple class which can be used to prevent reentrancy problems in a function. it is not thread-safe and so should be used only in single-threaded programs or in combination with some thread synchronization mechanisms.
wxrecursionguard is always used together with the wxrecursionguardflag like in this example:
void foo() { static wxrecursionguardflag s_flag; wxrecursionguard guard(s_flag); if ( guard.isinside() ) { // don't allow reentrancy return; } ... }as you can see, wxrecursionguard simply tests the flag value and sets it to true if it hadn't been already set. isinside() allows testing the old flag value. the advantage of using this class compared to directly manipulating the flag is that the flag is always reset in the wxrecursionguard destructor and so you don't risk to forget to do it even if the function returns in an unexpected way (for example because an exception has been thrown).
derived from
no base class
include files
<wx/recguard.h>
members
wxrecursionguard::wxrecursionguard
wxrecursionguard::~wxrecursionguard
wxrecursionguard::isinside
wxrecursionguard(wxrecursionguardflag& flag)
a wxrecursionguard object must always be initialized with a (static) wxrecursionguardflag. the constructor saves the value of the flag to be able to return the correct value from isinside.
~wxrecursionguard()
the destructor resets the flag value so that the function can be entered again the next time.
note that it is not virtual and so this class is not meant to be derived from (besides, there is absolutely no reason to do it anyhow).
bool isinside() const
returns true if we're already inside the code block "protected'' by this wxrecursionguard (i.e. between this line and the end of current scope). usually the function using wxrecursionguard takes some specific actions in such case (may be simply returning) to prevent reentrant calls to itself.
if this method returns false, it is safe to continue.
include "./_footer.inc"; ?>