annotate src/unwind-prot.h @ 13294:7dce7e110511

make concatenation of class objects work * data.h: New file. * src/Makefile.am (octinclude_HEADERS): Add it to the list. * data.cc (attempt_type_conversion): New static function. (do_class_concat): New function. (do_cat): Use it if any elements of the list are objects. Check whether any elements of the list are objects or cells. Check whether all elements of the list are complex. Check whether the first element of the list is a struct. Maybe convert elements of the list to cells. New tests for horzcat and vertcat. * data.h (do_class_concat): Provide decl. * ov-class.h (octave_class::octave_class): Allow optional parent list. * ov.h, ov.h (octave_value::octave_value (const Octave_map&, const std::string&)): Likewise. * pt-mat.cc (do_class_concat): New static function. (tree_matrix::rvalue1): Use it to concatenate objects.
author John W. Eaton <jwe@octave.org>
date Fri, 07 Oct 2011 22:16:07 -0400
parents e0e50f48df37
children 72c96de7a403
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:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
46 elem (void) : next (0) { }
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
47
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
48 virtual void run (void) { }
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
49
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
50 virtual ~elem (void) { }
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
51
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
52 friend class unwind_protect;
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
53
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
54 private:
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
55
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
56 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
57
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
58 elem (const elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
59
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
60 elem& operator = (const elem&);
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
61 };
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
62
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
63 // 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
64
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
65 class fcn_elem : public elem
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
66 {
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
67 public:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
68 fcn_elem (void (*fptr) (void))
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
69 : e_fptr (fptr) { }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
70
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
71 void run (void) { e_fptr (); }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
72
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
73 private:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
74 void (*e_fptr) (void);
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
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
77 // 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
78 // function pointer, and calls the function with the parameter.
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
79
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
80 template <class T>
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
81 class fcn_arg_elem : public elem
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
82 {
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
83 public:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
84 fcn_arg_elem (void (*fcn) (T), T arg)
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
85 : e_fcn (fcn), e_arg (arg) { }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
86
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
87 void run (void) { e_fcn (e_arg); }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
88
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
89 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
90
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
91 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
92
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
93 fcn_arg_elem (const fcn_arg_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
94
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
95 fcn_arg_elem& operator = (const fcn_arg_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
96
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
97 void (*e_fcn) (T);
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
98 T e_arg;
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
99 };
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
100
10781
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
101 // 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
102 // 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
103
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
104 template <class T>
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
105 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
106 {
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
107 public:
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
108 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
109 : 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
110
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
111 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
112
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
113 private:
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
114 void (*e_fcn) (const T&);
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
115 T e_arg;
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
116 };
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
117
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
118 // An element for calling a member function.
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
119
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
120 template <class T>
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
121 class method_elem : public elem
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
122 {
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
123 public:
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
124 method_elem (T *obj, void (T::*method) (void))
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
125 : e_obj (obj), e_method (method) { }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
126
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
127 void run (void) { (e_obj->*e_method) (); }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
128
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
129 private:
12153
e0e50f48df37 Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12122
diff changeset
130
e0e50f48df37 Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12122
diff changeset
131 T *e_obj;
e0e50f48df37 Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12122
diff changeset
132 void (T::*e_method) (void);
e0e50f48df37 Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12122
diff changeset
133
e0e50f48df37 Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 12122
diff changeset
134 // No copying!
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
135
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
136 method_elem (const method_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
137
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
138 method_elem operator = (const method_elem&);
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
139 };
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
140
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
141 // 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
142
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
143 template <class T>
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
144 class restore_var_elem : public elem
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
145 {
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
146 public:
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
147 restore_var_elem (T& ref, const T& val)
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
148 : e_ptr (&ref), e_val (val) { }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
149
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
150 void run (void) { *e_ptr = e_val; }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
151
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
152 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
153
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
154 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
155
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
156 restore_var_elem (const restore_var_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
157
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
158 restore_var_elem& operator = (const restore_var_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
159
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
160 T *e_ptr, e_val;
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
161 };
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
162
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
163 // Deletes a class allocated using new.
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
164
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
165 template <class T>
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
166 class delete_ptr_elem : public elem
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
167 {
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
168 public:
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
169 delete_ptr_elem (T *ptr)
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
170 : e_ptr (ptr) { }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
171
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
172 void run (void) { delete e_ptr; }
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
173
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
174 private:
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
175
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
176 T *e_ptr;
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
177
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
178 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
179
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
180 delete_ptr_elem (const delete_ptr_elem&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
181
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
182 delete_ptr_elem operator = (const delete_ptr_elem&);
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
183 };
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
184
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
185 unwind_protect (void) : head () { }
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
186
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
187 void add (elem *new_elem)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
188 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
189 new_elem->next = head;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
190 head = new_elem;
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
191 }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
192
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
193 // For backward compatibility.
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
194 void add (void (*fcn) (void *), void *ptr = 0)
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
195 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
196 add (new fcn_arg_elem<void *> (fcn, ptr));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
197 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
198
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
199 // Call to void func (void).
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
200 void add_fcn (void (*fcn) (void))
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
201 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
202 add (new fcn_elem (fcn));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
203 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
204
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
205 // Call to void func (T).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
206 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
207 void add_fcn (void (*action) (T), T val)
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
208 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
209 add (new fcn_arg_elem<T> (action, val));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
210 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
211
10781
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
212 // 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
213 template <class T>
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
214 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
215 {
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
216 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
217 }
f7584d0ba5d3 allow unwind_protect register actions with const T& args
Jaroslav Hajek <highegg@gmail.com>
parents: 10343
diff changeset
218
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
219 // Call to T::method (void).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
220 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
221 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
222 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
223 add (new method_elem<T> (obj, method));
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
224 }
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
225
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
226 // Call to delete (T*).
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
227
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
228 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
229 void add_delete (T *obj)
9396
17af7cce7d1b yet more unwind_protect improvements
Jaroslav Hajek <highegg@gmail.com>
parents: 9394
diff changeset
230 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
231 add (new delete_ptr_elem<T> (obj));
9394
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
232 }
b3ab22ee8544 further improve unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 9384
diff changeset
233
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
234 // Protect any variable.
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
235 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
236 void protect_var (T& var)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
237 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
238 add (new restore_var_elem<T> (var, var));
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
239 }
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
240
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
241 // Protect any variable, value given.
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
242 template <class T>
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
243 void protect_var (T& var, const T& val)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
244 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
245 add (new restore_var_elem<T> (var, val));
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
248 operator bool (void) const
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
249 {
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
250 return head != 0;
10066
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
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
253 void run_top (void)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
254 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
255 if (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
256 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
257 // No leak on exception!
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
258 std::auto_ptr<elem> ptr (head);
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
259 head = ptr->next;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
260 ptr->run ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
261 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
262 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
263
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
264 void run_top (int num)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
265 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
266 while (num-- > 0)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
267 run_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
268 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
269
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
270 void discard_top (void)
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
271 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
272 if (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
273 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
274 elem *ptr = head;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
275 head = ptr->next;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
276 delete ptr;
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
277 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
278 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
279
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
280 void discard_top (int num)
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
281 {
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
282 while (num-- > 0)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
283 discard_top ();
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
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
286 void run (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
287 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
288 while (head)
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
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
292 void discard (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
293 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
294 while (head)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
295 discard_top ();
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
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
298 // 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
299 // 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
300 // see unwind_protect_safe.
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
301 ~unwind_protect (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
302 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
303 run ();
9376
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
304 }
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
305
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
306 private:
d58086453171 refactor unwind_protect
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
307
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
308 elem *head;
12122
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
309
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
310 // No copying!
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
311
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
312 unwind_protect (const unwind_protect&);
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
313
f4689107dd8c Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents: 11586
diff changeset
314 unwind_protect& operator = (const unwind_protect&);
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
315 };
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
316
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
317 // 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
318 // 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
319 // it, but at least we won't crash.
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
320
10343
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
321 class
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
322 OCTINTERP_API
2ef5144ccb0d Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 10160
diff changeset
323 unwind_protect_safe : public unwind_protect
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
324 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
325 static void gripe_exception (void);
7752
40c428ea3408 initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents: 7336
diff changeset
326
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
327 public:
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
328 ~unwind_protect_safe (void)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
329 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
330 while (*this)
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
331 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
332 try
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
333 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
334 run_top ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
335 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
336 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
337 {
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
338 gripe_exception ();
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
339 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
340 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
341 }
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9396
diff changeset
342 };
2985
aa9d0c0e0458 [project @ 1997-05-16 06:54:18 by jwe]
jwe
parents: 2847
diff changeset
343
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
344 #endif