annotate src/unwind-prot.h @ 11586:12df7854fa7c

strip trailing whitespace from source files
author John W. Eaton <jwe@octave.org>
date Thu, 20 Jan 2011 17:24:59 -0500
parents fd0a3ac60b0e
children f4689107dd8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
11523
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10781
diff changeset
3 Copyright (C) 1993-2011 John W. Eaton
fd0a3ac60b0e update copyright notices
John W. Eaton <jwe@octave.org>
parents: 10781
diff changeset
4 Copyright (C) 2009-2010 VZLU Prague
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
7
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
8 Octave is free software; you can redistribute it and/or modify it
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6109
diff changeset
10 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6109
diff changeset
11 option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
12
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
13 Octave is distributed in the hope that it will be useful, but WITHOUT
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16 for more details.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6109
diff changeset
19 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6109
diff changeset
20 <http://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
21
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
22 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
23
383
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 240
diff changeset
24 #if !defined (octave_unwind_prot_h)
0b52c68ec81f [project @ 1994-03-09 21:19:44 by jwe]
jwe
parents: 240
diff changeset
25 #define octave_unwind_prot_h 1
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26
1342
61bb2bdee11e [project @ 1995-09-04 00:19:22 by jwe]
jwe
parents: 1315
diff changeset
27 #include <cstddef>
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 453
diff changeset
28
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1488
diff changeset
29 #include <string>
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
30 #include <memory>
240
a99f28f5e351 [project @ 1993-11-30 20:24:36 by jwe]
jwe
parents: 164
diff changeset
31
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
32 // This class allows registering cleanup actions.
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
33 class
6109
c68896f193e3 [project @ 2006-10-27 02:16:18 by jwe]
jwe
parents: 5854
diff changeset
34 OCTINTERP_API
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
35 unwind_protect
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
36 {
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
37 public:
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
38
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
39 // A generic unwind_protect element. Knows how to run itself and discard itself.
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
40 // Also, contains a pointer to the next element.
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
41 class elem
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
42 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
43 elem *next;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
44
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
45 public:
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
46 virtual void run (void) { }
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
47 virtual ~elem (void) { }
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
48
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
49 friend class unwind_protect;
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
50 };
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
51
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
52 // An element that merely runs a void (*)(void) function.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
53
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
54 class fcn_elem : public elem
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
55 {
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
56 public:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
57 fcn_elem (void (*fptr) (void))
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
58 : e_fptr (fptr) { }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
59
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
60 void run (void) { e_fptr (); }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
61
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
62 private:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
63 void (*e_fptr) (void);
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
64 };
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
65
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
66 // An element that stores a variable of type T along with a void (*) (T)
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
67 // function pointer, and calls the function with the parameter.
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
68
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
69 template <class T>
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
70 class fcn_arg_elem : public elem
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
71 {
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
72 public:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
73 fcn_arg_elem (void (*fcn) (T), T arg)
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
74 : e_fcn (fcn), e_arg (arg) { }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
75
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
76 void run (void) { e_fcn (e_arg); }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
77
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
78 private:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
79 void (*e_fcn) (T);
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
80 T e_arg;
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
81 };
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
82
10781
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
83 // An element that stores a variable of type T along with a void (*) (const T&)
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
84 // function pointer, and calls the function with the parameter.
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
85
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
86 template <class T>
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
87 class fcn_crefarg_elem : public elem
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
88 {
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
89 public:
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
90 fcn_crefarg_elem (void (*fcn) (const T&), T arg)
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
91 : e_fcn (fcn), e_arg (arg) { }
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
92
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
93 void run (void) { e_fcn (e_arg); }
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
94
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
95 private:
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
96 void (*e_fcn) (const T&);
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
97 T e_arg;
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
98 };
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
99
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
100 // An element for calling a member function.
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
101
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
102 template <class T>
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
103 class method_elem : public elem
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
104 {
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
105 public:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
106 method_elem (T *obj, void (T::*method) (void))
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
107 : e_obj (obj), e_method (method) { }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
108
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
109 void run (void) { (e_obj->*e_method) (); }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
110
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
111 private:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
112 T *e_obj;
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
113 void (T::*e_method) (void);
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
114 };
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
115
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
116 // An element that stores arbitrary variable, and restores it.
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
117
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
118 template <class T>
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
119 class restore_var_elem : public elem
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
120 {
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
121 public:
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
122 restore_var_elem (T& ref, const T& val)
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
123 : e_ptr (&ref), e_val (val) { }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
124
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
125 void run (void) { *e_ptr = e_val; }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
126
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
127 private:
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
128 T *e_ptr, e_val;
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
129 };
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
130
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
131 // Deletes a class allocated using new.
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
132
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
133 template <class T>
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
134 class delete_ptr_elem : public elem
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
135 {
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
136 public:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
137 delete_ptr_elem (T *ptr)
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
138 : e_ptr (ptr) { }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
139
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
140 void run (void) { delete e_ptr; }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
141
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
142 private:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
143 T *e_ptr;
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
144 };
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
145
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
146 unwind_protect (void) : head () { }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
147
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
148 void add (elem *new_elem)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
149 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
150 new_elem->next = head;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
151 head = new_elem;
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
152 }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
153
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
154 // For backward compatibility.
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
155 void add (void (*fcn) (void *), void *ptr = 0)
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
156 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
157 add (new fcn_arg_elem<void *> (fcn, ptr));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
158 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
159
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
160 // Call to void func (void).
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
161 void add_fcn (void (*fcn) (void))
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
162 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
163 add (new fcn_elem (fcn));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
164 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
165
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
166 // Call to void func (T).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
167 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
168 void add_fcn (void (*action) (T), T val)
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
169 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
170 add (new fcn_arg_elem<T> (action, val));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
171 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
172
10781
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
173 // Call to void func (const T&).
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
174 template <class T>
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
175 void add_fcn (void (*action) (const T&), T val)
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
176 {
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
177 add (new fcn_crefarg_elem<T> (action, val));
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
178 }
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
179
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
180 // Call to T::method (void).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
181 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
182 void add_method (T *obj, void (T::*method) (void))
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
183 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
184 add (new method_elem<T> (obj, method));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
185 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
186
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
187 // Call to delete (T*).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
188
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
189 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
190 void add_delete (T *obj)
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
191 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
192 add (new delete_ptr_elem<T> (obj));
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
193 }
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
194
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
195 // Protect any variable.
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
196 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
197 void protect_var (T& var)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
198 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
199 add (new restore_var_elem<T> (var, var));
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
200 }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
201
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
202 // Protect any variable, value given.
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
203 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
204 void protect_var (T& var, const T& val)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
205 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
206 add (new restore_var_elem<T> (var, val));
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
207 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
208
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
209 operator bool (void) const
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
210 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
211 return head != 0;
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
212 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
213
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
214 void run_top (void)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
215 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
216 if (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
217 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
218 // No leak on exception!
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
219 std::auto_ptr<elem> ptr (head);
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
220 head = ptr->next;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
221 ptr->run ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
222 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
223 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
224
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
225 void run_top (int num)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
226 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
227 while (num-- > 0)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
228 run_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
229 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
230
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
231 void discard_top (void)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
232 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
233 if (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
234 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
235 elem *ptr = head;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
236 head = ptr->next;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
237 delete ptr;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
238 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
239 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
240
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
241 void discard_top (int num)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
242 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
243 while (num-- > 0)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
244 discard_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
245 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
246
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
247 void run (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
248 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
249 while (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
250 run_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
251 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
252
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
253 void discard (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
254 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
255 while (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
256 discard_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
257 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
258
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
259 // Destructor should not raise an exception, so all actions registered should
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
260 // be exception-safe (but setting error_state is allowed). If you're not sure,
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
261 // see unwind_protect_safe.
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
262 ~unwind_protect (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
263 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
264 run ();
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
265 }
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
266
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
267 private:
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
268
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
269 elem *head;
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
270 };
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
271
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
272 // Like unwind_protect, but this one will guard against the possibility of seeing
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
273 // an exception (or interrupt) in the cleanup actions. Not that we can do much about
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
274 // it, but at least we won't crash.
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
275
10343
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
276 class
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
277 OCTINTERP_API
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
278 unwind_protect_safe : public unwind_protect
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
279 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
280 static void gripe_exception (void);
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
281
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
282 public:
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
283 ~unwind_protect_safe (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
284 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
285 while (*this)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
286 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
287 try
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
288 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
289 run_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
290 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
291 catch (...) // Yes, the black hole. Remember we're in a dtor.
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
292 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
293 gripe_exception ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
294 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
295 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
296 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
297 };
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
298
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
299 #endif