annotate libinterp/octave-value/ov-oncleanup.cc @ 23075:4e3d47dc7e25

move parse tree classes inside octave namespace * lex.h, lex.ll, oct-parse.in.yy, parse.h, pt-all.h, pt-arg-list.cc, pt-arg-list.h, pt-array-list.cc, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt.cc, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.cc, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-funcall.cc, pt-funcall.h, pt.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.cc, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-stmt.cc, pt-stmt.h, pt-unop.cc, pt-unop.h, pt-walk.h, token.cc, token.h: Move classes and most functions inside octave namespace. Change all uses.
author John W. Eaton <jwe@octave.org>
date Thu, 19 Jan 2017 23:41:54 -0500
parents b443bfa3bfea
children ef4d915df748
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 /*
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 22295
diff changeset
3 Copyright (C) 2010-2016 VZLU Prague
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 This file is part of Octave.
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 */
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
24 # include "config.h"
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25 #endif
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #include "defun.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 21966
diff changeset
28 #include "interpreter.h"
14015
77adde2e79ac fix include file name
John W. Eaton <jwe@octave.org>
parents: 14013
diff changeset
29 #include "ov-oncleanup.h"
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include "ov-fcn.h"
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include "ov-usr-fcn.h"
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include "pt-misc.h"
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_oncleanup, "onCleanup",
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 "onCleanup");
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 octave_oncleanup::octave_oncleanup (const octave_value& f)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 : fcn (f)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 if (f.is_function_handle ())
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 octave_function *fptr = f.function_value (true);
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
43 if (! fptr)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
44 error ("onCleanup: no default dispatch for function handle");
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
45
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
46 octave_user_function *uptr
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
47 = dynamic_cast<octave_user_function *> (fptr);
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
49 if (uptr != 0)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
50 {
23075
4e3d47dc7e25 move parse tree classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23053
diff changeset
51 octave::tree_parameter_list *pl = uptr->parameter_list ();
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
53 if (pl != 0 && pl->length () > 0)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20939
diff changeset
54 warning ("onCleanup: cleanup action takes parameters");
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 else
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 fcn = octave_value ();
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 error ("onCleanup: argument must be a function handle");
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 octave_oncleanup::~octave_oncleanup (void)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 if (fcn.is_undefined ())
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 return;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
69 octave::unwind_protect frame;
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 // Clear interrupts.
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 frame.protect_var (octave_interrupt_state);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 octave_interrupt_state = 0;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 // Disallow quit().
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76 frame.protect_var (quit_allowed);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 quit_allowed = false;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
22159
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
79 interpreter_try (frame);
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
80
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 try
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83 // Run the actual code.
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 fcn.do_multi_index_op (0, octave_value_list ());
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
86 catch (const octave::interrupt_exception&)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
88 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
89
21004
f7e416862e90 doc: fix spelling of "occurred".
Rafael Laboissiere <rafael@laboissiere.net>
parents: 20163
diff changeset
90 warning ("onCleanup: interrupt occurred in cleanup action");
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
92 catch (const octave::execution_exception&)
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20467
diff changeset
93 {
22159
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
94 std::string msg = last_error_message ();
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
95 warning ("onCleanup: error caught while executing cleanup function:\n%s\n",
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
96 msg.c_str ());
22295
12f1d273d22a maint: Remove trailing spaces from code.
Rik <rik@octave.org>
parents: 22159
diff changeset
97
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20467
diff changeset
98 }
23049
7351f2c93389 rethrow octave::exit_exception (bug #49304)
Olaf Till <i7tiol@t-online.de>
parents: 22407
diff changeset
99 catch (const octave::exit_exception&)
7351f2c93389 rethrow octave::exit_exception (bug #49304)
Olaf Till <i7tiol@t-online.de>
parents: 22407
diff changeset
100 {
23051
7f91376af4d3 don't rethrow exception in destructor (bug #49304)
John W. Eaton <jwe@octave.org>
parents: 23049
diff changeset
101 // This shouldn't happen since we disabled quit above.
7f91376af4d3 don't rethrow exception in destructor (bug #49304)
John W. Eaton <jwe@octave.org>
parents: 23049
diff changeset
102 warning ("onCleanup: exit disabled while executing cleanup function");
23049
7351f2c93389 rethrow octave::exit_exception (bug #49304)
Olaf Till <i7tiol@t-online.de>
parents: 22407
diff changeset
103 }
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21743
diff changeset
104 catch (...) // Yes, the black hole. We're in a d-tor.
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 // This shouldn't happen, in theory.
22159
63c806042c27 convert errors in onCleanup destructor to warnings (bug #48574)
John W. Eaton <jwe@octave.org>
parents: 22094
diff changeset
107 warning ("onCleanup: internal error: unhandled exception in cleanup action");
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 octave_scalar_map
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 octave_oncleanup::scalar_map_value (void) const
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 octave_scalar_map retval;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 retval.setfield ("task", fcn);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 return retval;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 bool
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 octave_oncleanup::save_ascii (std::ostream& /* os */)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
122 warning ("save: unable to save onCleanup variables, skipping");
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
123
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 bool
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 octave_oncleanup::load_ascii (std::istream& /* is */)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
130 // Silently skip object that was not saved
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 bool
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
135 octave_oncleanup::save_binary (std::ostream& /* os */,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
136 bool& /* save_as_floats */)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
138 warning ("save: unable to save onCleanup variables, skipping");
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
139
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 bool
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 octave_oncleanup::load_binary (std::istream& /* is */, bool /* swap */,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
145 octave::mach_info::float_format /* fmt */)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
147 // Silently skip object that was not saved
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
152 octave_oncleanup::save_hdf5 (octave_hdf5_id /* loc_id */,
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
153 const char * /* name */,
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154 bool /* save_as_floats */)
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
156 warning ("save: unable to save onCleanup variables, skipping");
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
157
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
162 octave_oncleanup::load_hdf5 (octave_hdf5_id /* loc_id */,
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
163 const char * /* name */)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 {
20467
4bef1880098c More specific warning messages when saving onCleanup variables.
Rik <rik@octave.org>
parents: 20163
diff changeset
165 // Silently skip object that was not saved
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 return true;
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 17787
diff changeset
170 octave_oncleanup::print (std::ostream& os, bool pr_as_read_syntax)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 print_raw (os, pr_as_read_syntax);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 newline (os);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 void
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 octave_oncleanup::print_raw (std::ostream& os, bool pr_as_read_syntax) const
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 {
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179 os << "onCleanup (";
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 if (fcn.is_defined ())
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 fcn.print_raw (os, pr_as_read_syntax);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182 os << ")";
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 DEFUN (onCleanup, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
186 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
187 @deftypefn {} {@var{obj} =} onCleanup (@var{function})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
188 Create a special object that executes a given function upon destruction.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
189
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
190 If the object is copied to multiple variables (or cell or struct array
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
191 elements) or returned from a function, @var{function} will be executed after
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
192 clearing the last copy of the object. Note that if multiple local onCleanup
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
193 variables are created, the order in which they are called is unspecified.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
194 For similar functionality @xref{The unwind_protect Statement}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
195 @end deftypefn */)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
197 if (args.length () != 1)
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 print_usage ();
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
200 return ovl (new octave_oncleanup (args(0)));
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 /*
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204 %!test
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 %! old_wstate = warning ("query");
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 %! unwind_protect
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 %! trigger = onCleanup (@() warning ("on", "__MY_WARNING__"));
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 %! warning ("off", "__MY_WARNING__");
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209 %! assert ((warning ("query", "__MY_WARNING__")).state, "off");
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
210 %! clear trigger;
14013
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211 %! assert ((warning ("query", "__MY_WARNING__")).state, "on");
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 %! unwind_protect_cleanup
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 %! warning (old_wstate);
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 %! end_unwind_protect
1734ebe27134 move onCleanup function and class to liboctinterp
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 */
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
216