]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/scopeguard.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of global functions
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 /** @ingroup group_funcmacro_misc */
12 This macro ensures that the global @a function with 0, 1, 2 or more
13 parameters (up to some implementation-defined limit) is executed on scope
14 exit, whether due to a normal function return or because an exception has
15 been thrown. A typical example of its usage:
18 void *buf = malloc(size);
19 wxON_BLOCK_EXIT1(free, buf);
22 Please see the original article by Andrei Alexandrescu and Petru Marginean
23 published in December 2000 issue of C/C++ Users Journal for more details.
25 @see wxON_BLOCK_EXIT_OBJ0()
27 @header{wx/scopeguard.h}
29 #define wxON_BLOCK_EXIT0(function)
30 #define wxON_BLOCK_EXIT1(function, p1)
31 #define wxON_BLOCK_EXIT2(function, p1, p2)
34 /** @ingroup group_funcmacro_misc */
37 This family of macros is similar to wxON_BLOCK_EXIT0(), but calls a method
38 of the given object instead of a free function.
40 @header{wx/scopeguard.h}
42 #define wxON_BLOCK_EXIT_OBJ0(object, method)
43 #define wxON_BLOCK_EXIT_OBJ1(object, method, p1)
44 #define wxON_BLOCK_EXIT_OBJ2(object, method, p1, p2)
47 /** @ingroup group_funcmacro_misc */
50 This family of macros is similar to wxON_BLOCK_OBJ0(), but calls a method
51 of @c this object instead of a method of the specified object.
53 @header{wx/scopeguard.h}
55 #define wxON_BLOCK_EXIT_THIS0(method)
56 #define wxON_BLOCK_EXIT_THIS1(method, p1)
57 #define wxON_BLOCK_EXIT_THIS2(method, p1, p2)
60 /** @ingroup group_funcmacro_misc */
63 This macro sets a variable to the specified value on scope exit.
69 bool isDoingSomething = true;
71 wxON_BLOCK_EXIT_SET(isDoingSomething, false);
74 ... isDoingSomething is false now ...
78 @see wxON_BLOCK_EXIT_OBJ0(), wxON_BLOCK_EXIT_NULL()
80 @header{wx/scopeguard.h}
82 #define wxON_BLOCK_EXIT_SET(var, value)
85 This macro sets the pointer passed to it as argument to NULL on scope exit.
87 It must be used instead of wxON_BLOCK_EXIT_SET() when the value being set
90 @header{wx/scopeguard.h}
92 #define wxON_BLOCK_EXIT_NULL(ptr)