annotate src/DLD-FUNCTIONS/onCleanup.cc @ 10846:a4f482e66b65

Grammarcheck more of the documentation. Use @noindent macro appropriately. Limit line length to 80 characters.
author Rik <octave@nomad.inbox5.com>
date Sun, 01 Aug 2010 20:22:17 -0700
parents 89f4d7e294cc
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
1 /*
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
2
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
3 Copyright (C) 2010 VZLU Prague
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
4
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
5 This file is part of Octave.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
6
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
10 option) any later version.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
11
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
15 for more details.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
16
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
20
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
21 */
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
22
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
24 #include <config.h>
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
25 #endif
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
26
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
27 #include "defun-dld.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
28 #include "ov-base.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
29 #include "ov.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
30 #include "ov-fcn.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
31 #include "ov-usr-fcn.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
32 #include "pt-misc.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
33 #include "toplev.h"
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
34
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
35 static void gripe_internal (void)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
36 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
37 error ("onCleanup: internal error: cloning nonempty object");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
38 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
39
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
40 class octave_oncleanup : public octave_base_value, octave_auto_shlib
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
41 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
42 public:
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
43 octave_oncleanup (void) : fcn () { }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
44 octave_oncleanup (const octave_value& fcn);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
45
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
46 octave_base_value *clone (void) const
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
47 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
48 if (fcn.is_defined ())
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
49 gripe_internal ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
50 return empty_clone ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
51 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
52
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
53 octave_base_value *empty_clone (void) const { return new octave_oncleanup (); }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
54
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
55 ~octave_oncleanup (void);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
56
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
57 bool is_defined (void) const { return true; }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
58
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
59 bool is_object (void) const { return true; } // do we want this?
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
60
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
61 octave_map map_value (void) const
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
62 { return scalar_map_value (); }
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
63
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
64 octave_scalar_map scalar_map_value (void) const;
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
65
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
66 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
67
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
68 bool save_ascii (std::ostream& os);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
69
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
70 bool load_ascii (std::istream& is);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
71
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
72 bool save_binary (std::ostream& os, bool& save_as_floats);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
73
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
74 bool load_binary (std::istream& is, bool swap,
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
75 oct_mach_info::float_format fmt);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
76
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
77 #if defined (HAVE_HDF5)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
78 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
79
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
80 bool load_hdf5 (hid_t loc_id, const char *name);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
81 #endif
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
82
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
83 void print (std::ostream& os, bool pr_as_read_syntax = false) const;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
84
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
85 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
86
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
87 private:
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
88
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
89 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
90
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
91 protected:
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
92
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
93 octave_value fcn;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
94
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
95 };
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
96
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
97 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_oncleanup, "onCleanup", "onCleanup");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
98
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
99 octave_oncleanup::octave_oncleanup (const octave_value& f)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
100 : fcn (f)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
101 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
102 if (f.is_function_handle ())
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
103 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
104 octave_function *fptr = f.function_value (true);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
105 if (fptr)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
106 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
107 octave_user_function *uptr = dynamic_cast<octave_user_function *> (fptr);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
108 if (uptr != 0)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
109 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
110 tree_parameter_list *pl = uptr->parameter_list ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
111 if (pl != 0 && pl->length () > 0)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
112 warning ("onCleanup: cleanup action takes parameters");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
113 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
114 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
115 else
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
116 error ("onCleanup: no default dispatch for function handle");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
117 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
118 else
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
119 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
120 fcn = octave_value ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
121 error ("onCleanup: argument must be a function handle");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
122 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
123 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
124
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
125 octave_oncleanup::~octave_oncleanup (void)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
126 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
127 if (fcn.is_undefined ())
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
128 return;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
129
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
130 unwind_protect frame;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
131
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
132 // Clear interrupts.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
133 frame.protect_var (octave_interrupt_state);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
134 octave_interrupt_state = 0;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
135
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
136 // Disallow quit().
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
137 frame.protect_var (quit_allowed);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
138 quit_allowed = false;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
139
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
140 // Clear errors.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
141 frame.protect_var (error_state);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
142 error_state = 0;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
143
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
144 try
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
145 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
146 // Run the actual code.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
147 fcn.do_multi_index_op (0, octave_value_list ());
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
148 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
149 catch (octave_interrupt_exception)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
150 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
151 // Swallow the interrupt.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
152 warning ("onCleanup: interrupt occured in cleanup action");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
153 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
154 catch (std::bad_alloc)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
155 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
156 // Swallow the exception.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
157 warning ("onCleanup: out of memory occured in cleanup action");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
158 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
159 catch (...) // Yes, the black hole. We're in a d-tor.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
160 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
161 // This shouldn't happen, in theory.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
162 error ("onCleanup: internal error: unhandled exception in cleanup action");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
163 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
164
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
165 // We don't want to ignore errors that occur in the cleanup code, so
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
166 // if an error is encountered there, leave error_state alone.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
167 // Otherwise, set it back to what it was before.
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
168 if (error_state)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
169 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
170 frame.discard_top ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
171 octave_call_stack::backtrace_error_message ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
172 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
173 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
174
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
175 octave_scalar_map
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
176 octave_oncleanup::scalar_map_value (void) const
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
177 {
10742
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
178 octave_scalar_map retval;
604e13a89c7f initial code for structs rewrite
Jaroslav Hajek <highegg@gmail.com>
parents: 10711
diff changeset
179 retval.setfield ("task", fcn);
10642
2a9f059758bd omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10641
diff changeset
180 return retval;
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
181 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
182
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
183 static void
10642
2a9f059758bd omission from last patch
Jaroslav Hajek <highegg@gmail.com>
parents: 10641
diff changeset
184 warn_save_load (void)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
185 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
186 warning ("onCleanup: load and save not supported");
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
187 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
188
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
189 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
190 octave_oncleanup::save_ascii (std::ostream& /* os */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
191 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
192 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
193 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
194 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
195
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
196 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
197 octave_oncleanup::load_ascii (std::istream& /* is */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
198 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
199 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
200 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
201 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
202
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
203 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
204 octave_oncleanup::save_binary (std::ostream& /* os */, bool& /* save_as_floats */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
205 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
206 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
207 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
208 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
209
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
210
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
211 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
212 octave_oncleanup::load_binary (std::istream& /* is */, bool /* swap */,
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
213 oct_mach_info::float_format /* fmt */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
214 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
215 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
216 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
217 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
218
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
219 #if defined (HAVE_HDF5)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
220 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
221 octave_oncleanup::save_hdf5 (hid_t /* loc_id */, const char * /* name */,
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
222 bool /* save_as_floats */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
223 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
224 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
225 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
226 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
227
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
228 bool
10644
45b72e631cb5 avoid unused param warnings in onCleanup
Jaroslav Hajek <highegg@gmail.com>
parents: 10642
diff changeset
229 octave_oncleanup::load_hdf5 (hid_t /* loc_id */, const char * /* name */)
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
230 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
231 warn_save_load ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
232 return true;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
233 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
234 #endif
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
235
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
236 void
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
237 octave_oncleanup::print (std::ostream& os, bool pr_as_read_syntax) const
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
238 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
239 print_raw (os, pr_as_read_syntax);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
240 newline (os);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
241 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
242
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
243 void
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
244 octave_oncleanup::print_raw (std::ostream& os, bool pr_as_read_syntax) const
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
245 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
246 os << "onCleanup (";
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
247 if (fcn.is_defined ())
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
248 fcn.print_raw (os, pr_as_read_syntax);
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
249 os << ")";
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
250 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
251
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
252 DEFUN_DLD (onCleanup, args, ,
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
253 "-*- texinfo -*-\n\
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
254 @deftypefn {Loadable Function} {@var{c} =} onCleanup (@var{action})\n\
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
255 Creates a special object that executes a given function upon destruction.\n\
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
256 If the object is copied to multiple variables (or cell or struct array\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
257 elements) or returned from a function, @var{action} will be executed after\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
258 clearing the last copy of the object. Note that if multiple local onCleanup\n\
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10840
diff changeset
259 variables are created, the order in which they are called is unspecified.\n\
10641
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
260 @seealso{unwind_protect}\n\
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
261 @end deftypefn")
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
262 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
263 octave_value retval;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
264
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
265 if (args.length () == 1)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
266 {
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
267 if (octave_oncleanup::static_type_id () < 0)
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
268 octave_oncleanup::register_type ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
269
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
270 retval = new octave_oncleanup (args(0));
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
271 }
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
272 else
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
273 print_usage ();
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
274
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
275 return retval;
ed6969880316 preliminary onCleanup support
Jaroslav Hajek <highegg@gmail.com>
parents:
diff changeset
276 }