]> git.saurik.com Git - wxWidgets.git/blame - interface/recguard.h
remove misleading documentation of minPage in GetPageInfo() (see ticket #9502)
[wxWidgets.git] / interface / recguard.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: recguard.h
e54c96f1 3// Purpose: interface of wxRecursionGuardFlag
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxRecursionGuardFlag
11 @wxheader{recguard.h}
7c913512
FM
12
13 This is a completely opaque class which exists only to be used with
3ed3a1c8 14 wxRecursionGuard, please see the example in that class' documentation.
7c913512 15
3ed3a1c8
BP
16 @remarks
17
18 wxRecursionGuardFlag object must be declared @c static or the recursion
19 would never be detected.
7c913512 20
23324ae1
FM
21 @library{wxbase}
22 @category{FIXME}
23*/
7c913512 24class wxRecursionGuardFlag
23324ae1
FM
25{
26public:
7c913512 27
23324ae1
FM
28};
29
30
e54c96f1 31
23324ae1
FM
32/**
33 @class wxRecursionGuard
34 @wxheader{recguard.h}
7c913512 35
23324ae1
FM
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
39 mechanisms.
7c913512
FM
40
41 wxRecursionGuard is always used together with the
23324ae1 42 wxRecursionGuardFlag like in this example:
7c913512 43
23324ae1
FM
44 @code
45 void Foo()
3ed3a1c8
BP
46 {
47 static wxRecursionGuardFlag s_flag;
48 wxRecursionGuard guard(s_flag);
49 if ( guard.IsInside() )
23324ae1 50 {
3ed3a1c8
BP
51 // don't allow reentrancy
52 return;
23324ae1 53 }
3ed3a1c8
BP
54
55 ...
56 }
23324ae1 57 @endcode
7c913512 58
23324ae1 59 As you can see, wxRecursionGuard simply tests the flag value and sets it to
7c913512 60 @true if it hadn't been already set.
3ed3a1c8 61 IsInside() allows testing the old flag
23324ae1
FM
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).
7c913512 66
23324ae1
FM
67 @library{wxbase}
68 @category{FIXME}
69*/
7c913512 70class wxRecursionGuard
23324ae1
FM
71{
72public:
73 /**
3ed3a1c8 74 A wxRecursionGuard object must always be initialized with a @c static
23324ae1 75 wxRecursionGuardFlag. The constructor saves the
7c913512 76 value of the flag to be able to return the correct value from
23324ae1
FM
77 IsInside().
78 */
79 wxRecursionGuard(wxRecursionGuardFlag& flag);
80
81 /**
82 The destructor resets the flag value so that the function can be entered again
83 the next time.
3ed3a1c8
BP
84
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).
23324ae1
FM
87 */
88 ~wxRecursionGuard();
89
90 /**
cdbcf4c2 91 Returns @true if we're already inside the code block "protected" by this
3ed3a1c8
BP
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.
95
23324ae1
FM
96 If this method returns @false, it is safe to continue.
97 */
328f5751 98 bool IsInside() const;
23324ae1 99};
e54c96f1 100