2003-08-13 20:09:36 -04:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% Name: recguard.tex
|
|
|
|
%% Purpose: wxRecursionGuard documentation
|
|
|
|
%% Author: Vadim Zeitlin
|
|
|
|
%% Modified by:
|
|
|
|
%% Created: 14.08.03
|
|
|
|
%% RCS-ID: $Id$
|
|
|
|
%% Copyright: (c) Vadim Zeitlin
|
2005-02-22 10:09:56 -05:00
|
|
|
%% License: wxWindows license
|
2003-08-13 20:09:36 -04:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
\section{\class{wxRecursionGuard}}\label{wxrecursionguard}
|
|
|
|
|
|
|
|
wxRecursionGuard is a very simple class which can be used to prevent reentrancy
|
2006-05-28 19:56:51 -04:00
|
|
|
problems in a function. It is not thread-safe and so should be used only in
|
2003-08-13 20:09:36 -04:00
|
|
|
single-threaded programs or in combination with some thread synchronization
|
|
|
|
mechanisms.
|
|
|
|
|
2003-08-15 12:17:40 -04:00
|
|
|
wxRecursionGuard is always used together with the
|
2003-08-13 20:09:36 -04:00
|
|
|
\helpref{wxRecursionGuardFlag}{wxrecursionguardflag} like in this example:
|
|
|
|
\begin{verbatim}
|
|
|
|
void Foo()
|
|
|
|
{
|
|
|
|
static wxRecursionGuardFlag s_flag;
|
|
|
|
wxRecursionGuard guard(s_flag);
|
|
|
|
if ( guard.IsInside() )
|
|
|
|
{
|
|
|
|
// don't allow reentrancy
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
}
|
|
|
|
\end{verbatim}
|
|
|
|
|
|
|
|
As you can see, wxRecursionGuard simply tests the flag value and sets it to
|
|
|
|
true if it hadn't been already set.
|
2003-08-15 12:17:40 -04:00
|
|
|
\helpref{IsInside()}{wxrecursionguardisinside} allows testing the old flag
|
2003-08-13 20:09:36 -04:00
|
|
|
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).
|
|
|
|
|
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
No base class
|
|
|
|
|
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/recguard.h>
|
|
|
|
|
2007-07-28 08:21:03 -04:00
|
|
|
\wxheading{Library}
|
|
|
|
|
|
|
|
\helpref{wxBase}{librarieslist}
|
|
|
|
|
2003-08-13 20:09:36 -04:00
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
|
|
|
\membersection{wxRecursionGuard::wxRecursionGuard}\label{wxrecursionguardctor}
|
|
|
|
|
|
|
|
\func{}{wxRecursionGuard}{\param{wxRecursionGuardFlag\& }{flag}}
|
|
|
|
|
|
|
|
A wxRecursionGuard object must always be initialized with a (static)
|
|
|
|
\helpref{wxRecursionGuardFlag}{wxrecursionguardflag}. The constructor saves the
|
|
|
|
value of the flag to be able to return the correct value from
|
|
|
|
\helpref{IsInside}{wxrecursionguardisinside}.
|
|
|
|
|
|
|
|
|
|
|
|
\membersection{wxRecursionGuard::\destruct{wxRecursionGuard}}\label{wxrecursionguarddtor}
|
|
|
|
|
|
|
|
\func{}{\destruct{wxRecursionGuard}}{\void}
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
|
|
|
|
|
|
\membersection{wxRecursionGuard::IsInside}\label{wxrecursionguardisinside}
|
|
|
|
|
|
|
|
\constfunc{bool}{IsInside}{\void}
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
\section{\class{wxRecursionGuardFlag}}\label{wxrecursionguardflag}
|
|
|
|
|
|
|
|
This is a completely opaque class which exists only to be used with
|
|
|
|
\helpref{wxRecursionGuard}{wxrecursionguard}, please see the example in that
|
|
|
|
class documentation.
|
|
|
|
|
|
|
|
Please notice that wxRecursionGuardFlag object \emph{must} be declared
|
|
|
|
\texttt{static} or the recursion would never be detected.
|
|
|
|
|
|
|
|
\wxheading{Derived from}
|
|
|
|
|
|
|
|
No base class
|
|
|
|
|
|
|
|
\wxheading{Include files}
|
|
|
|
|
|
|
|
<wx/recguard.h>
|
|
|
|
|