annotate libinterp/octave-value/ov-fcn-handle.cc @ 30337:eff73c13fcf3

remove functions deprecated in version 6 * runtests.m: Delete. * scripts/deprecated/module.mk: Update. * error.h, error.cc (error_state, reset_error_handler): Delete. * errwarn.h (warn_divide_by_zero): Delete. * file-io.cc (mark_for_deletion, cleanup_tmp_files): Delete from global namespace. * interpreter.cc, toplev.cc: Don't include file-io.h. * graphics-toolkit.h (graphics_toolkit, base_graphics_toolkit): Delete from global namespace. * input.h, input.cc (Vtrack_line_num): Delete. * interpreter.h, interpreter.cc (interpreter::add_atexit_function, interpreter::remove_atexit_function, interpreter::add_atexit_function_deprecated, interpreter::remove_atexit_function_deprecated): Delete. * symtab.h, symtab.cc (symbol_table::at_top_level_deprecated, symbol_table::varval_deprecated, symbol_table::global_varval_deprecated, symbol_table::top_level_varval_deprecated, symbol_table::global_variable_names_deprecated, symbol_table::top_level_variable_names_deprecated, symbol_table::variable_names_deprecated, symbol_table::assign_deprecated, symbol_table::clear_all_deprecated, symbol_table::clear_global_deprecated, symbol_table::clear_global_pattern_deprecated, symbol_table::clear_symbol_deprecated, symbol_table::clear_symbol_pattern_deprecated, symbol_table::global_assign_deprecated, symbol_table::top_level_assign_deprecated, symbol_table::at_top_level, symbol_table::varval, symbol_table::global_varval, symbol_table::top_level_varval, symbol_table::global_variable_names, symbol_table::top_level_variable_names, symbol_table::variable_names, symbol_table::assign, symbol_table::clear_all, symbol_table::clear_global, symbol_table::clear_global_pattern, symbol_table::clear_symbol, symbol_table::clear_symbol_pattern, symbol_table::global_assign, symbol_table::top_level_assign): Delete. * variables.h, variables.cc (extract_function): Delete. * ov-fcn-handle.h, ov-fcn-handle.cc (make_fcn_handle): Delete. * lo-array-errwarn.h, lo-array-errwarn.cc (err_index_out_of_range): Delete. * quit.h, quit.cc (octave_exception_state, internal_exception_state, octave_bad_alloc_hook, enum octave_internal_exception, octave_throw_interrupt_exception, octave_throw_execution_exception, octave_throw_bad_alloc, octave_rethrow_exception): Delete.
author John W. Eaton <jwe@octave.org>
date Wed, 24 Nov 2021 10:26:19 -0500
parents 75dff8f2de2e
children 91c6288781ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
29358
0a5b15007766 update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29207
diff changeset
3 // Copyright (C) 2003-2021 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
27 # include "config.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
28 #endif
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
29
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25383
diff changeset
30 #include <istream>
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
31 #include <list>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25383
diff changeset
32 #include <ostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
33 #include <sstream>
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
34 #include <string>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5105
diff changeset
35 #include <vector>
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
36
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
37 #include "file-ops.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
38 #include "oct-locbuf.h"
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
39
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
40 #include "defaults.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
41 #include "defun.h"
4654
a9b22513b7a6 [project @ 2003-11-24 18:56:35 by jwe]
jwe
parents: 4649
diff changeset
42 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21079
diff changeset
43 #include "errwarn.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
44 #include "file-stat.h"
5663
775e065f7dc4 [project @ 2006-03-13 21:30:06 by jwe]
jwe
parents: 5313
diff changeset
45 #include "input.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
46 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
47 #include "interpreter.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
48 #include "load-path.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
49 #include "oct-env.h"
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
50 #include "oct-hdf5.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
51 #include "oct-map.h"
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
52 #include "ov-base.h"
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
53 #include "ov-cell.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
54 #include "ov-fcn-handle.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
55 #include "ov-usr-fcn.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
56 #include "parse.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
57 #include "pr-output.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
58 #include "pt-arg-list.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
59 #include "pt-assign.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
60 #include "pt-cmd.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23433
diff changeset
61 #include "pt-eval.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
62 #include "pt-exp.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
63 #include "pt-idx.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
64 #include "pt-misc.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
65 #include "pt-pr-code.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
66 #include "pt-stmt.h"
28430
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
67 #include "stack-frame.h"
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
68 #include "syminfo.h"
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
69 #include "symscope.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
70 #include "unwind-prot.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
71 #include "variables.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
72
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
73 #include "byte-swap.h"
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
74 #include "ls-ascii-helper.h"
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
75 #include "ls-hdf5.h"
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20435
diff changeset
76 #include "ls-oct-text.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
77 #include "ls-oct-binary.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
78 #include "ls-utils.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
79
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
80
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4346
diff changeset
81 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_fcn_handle,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
82 "function handle",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
83 "function_handle");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
84
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
85 const std::string octave_fcn_handle::anonymous ("@<anonymous>");
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
86
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
87 OCTAVE_NAMESPACE_BEGIN
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
88
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
89 class invalid_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
90 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
91 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
92
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
93 invalid_fcn_handle (void) : base_fcn_handle ("<invalid>") { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
94
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
95 invalid_fcn_handle (const invalid_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
96
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
97 ~invalid_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
98
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
99 invalid_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
100 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
101 return new invalid_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
102 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
103
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
104 std::string type (void) const { return "<invalid>"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
105
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
106 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
107 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
108
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
109 // Create a handle to an unnamed internal function. There will be no
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
110 // way to save and reload it. See, for example, the F__fltk_check__
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
111 // function in __init_fltk__.cc.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
112
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
113 class internal_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
114 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
115 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
116
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
117 internal_fcn_handle (const octave_value& fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
118 : base_fcn_handle ("<internal>"), m_fcn (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
119 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
120
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
121 internal_fcn_handle (const internal_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
122
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
123 ~internal_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
124
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
125 internal_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
126 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
127 return new internal_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
128 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
129
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
130 std::string type (void) const { return "<internal>"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
131
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
132 bool is_internal (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
133
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
134 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
135
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
136 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
137 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
138 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
139 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
140 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
141 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
142
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
143 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
144 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
145 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
146 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
147
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
148 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
149
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
150 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
151 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
152
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
153 friend bool is_equal_to (const internal_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
154 const internal_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
155
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
156 private:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
157
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
158 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
159 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
160
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
161 class simple_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
162 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
163 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
164
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
165 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
166 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
167
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
168 simple_fcn_handle (const std::string& name = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
169 const std::string& file = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
170 const std::string& /*octaveroot*/ = "")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
171 : base_fcn_handle (name, file), m_fcn ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
172 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
173
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
174 simple_fcn_handle (const octave_value& fcn, const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
175 : base_fcn_handle (name), m_fcn (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
176 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
177 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
178 {
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
179 octave_function *oct_fcn = m_fcn.function_value ();
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
180
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
181 if (oct_fcn)
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
182 m_file = oct_fcn->fcn_file_name ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
183 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
184 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
185
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
186 simple_fcn_handle (const simple_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
187
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
188 ~simple_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
189
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
190 simple_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
191 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
192 return new simple_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
193 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
194
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
195 std::string type (void) const { return "simple"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
196
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
197 bool is_simple (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
198
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
199 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
200
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
201 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
202 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
203 octave_function * function_value (bool);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
204
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
205 octave_user_function * user_function_value (bool);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
206
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
207 octave_value fcn_val (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
208
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
209 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
210 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
211
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
212 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
213
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
214 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
215
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
216 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
217
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
218 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
219
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
220 bool save_hdf5 (octave_hdf5_id loc_hid, const char *name, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
221
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
222 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
223 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
224
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
225 void print_raw (std::ostream& os, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
226 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
227
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
228 friend bool is_equal_to (const simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
229 const simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
230
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
231 private:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
232
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
233 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
234 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
235
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
236 class scoped_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
237 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
238 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
239
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
240 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
241 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
242
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
243 scoped_fcn_handle (const std::string& name = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
244 const std::string& file = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
245 const std::string& /*octaveroot*/ = "")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
246 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
247 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
248
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
249 scoped_fcn_handle (const octave_value& fcn, const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
250 const std::list<std::string>& parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
251
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
252 scoped_fcn_handle (const scoped_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
253
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
254 ~scoped_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
255
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
256 scoped_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
257 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
258 return new scoped_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
259 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
260
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
261 std::string type (void) const { return "scopedfunction"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
262
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
263 bool is_scoped (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
264
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
265 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
266
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
267 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
268 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
269 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
270 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
271 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
272 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
273
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
274 octave_user_function * user_function_value (bool = false)
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
275 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
276 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
277 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
278
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
279 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
280
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
281 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
282 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
283
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
284 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
285
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
286 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
287
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
288 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
289
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
290 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
291
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
292 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
293
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
294 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
295 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
296
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
297 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
298 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
299
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
300 friend bool is_equal_to (const scoped_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
301 const scoped_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
302
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
303 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
304
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
305 void find_function (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
306
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
307 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
308 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
309
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
310 // List of parent function names. The first element is the name of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
311 // m_fcn.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
312 std::list<std::string> m_parentage;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
313 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
314
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
315 class base_nested_fcn_handle : public base_fcn_handle
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
316 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
317 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
318
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
319 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
320 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
321
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
322 base_nested_fcn_handle (const std::string& name = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
323 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
324 const std::string& /*octaveroot*/ = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
325 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
326 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
327
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
328 base_nested_fcn_handle (const octave_value& fcn, const std::string& name)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
329 : base_fcn_handle (name), m_fcn (fcn)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
330 { }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
331
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
332 std::string type (void) const { return "nested"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
333
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
334 using base_fcn_handle::is_nested;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
335
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
336 bool is_nested (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
337
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
338 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
339 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
340 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
341 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
342 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
343 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
344
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
345 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
346 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
347 return m_fcn.user_function_value ();
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
348 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
349
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
350 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
351
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
352 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
353
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
354 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
355 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
356
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
357 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
358
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
359 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
360
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
361 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
362
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
363 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
365 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
366
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
367 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
368 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
369
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
370 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
371 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
372
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
373 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
374
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
375 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
376 octave_value m_fcn;
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
377 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
378
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
379 class nested_fcn_handle : public base_nested_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
380 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
381 public:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
382
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
383 // FIXME: octaveroot is temporary information used when loading
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
384 // handles. Can we avoid using it in the constructor?
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
385
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
386 nested_fcn_handle (const std::string& name = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
387 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
388 const std::string& octaveroot = "")
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
389 : base_nested_fcn_handle (name, file, octaveroot)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
390 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
391
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
392 nested_fcn_handle (const octave_value& fcn, const std::string& name,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
393 const std::shared_ptr<stack_frame>& stack_context)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
394 : base_nested_fcn_handle (fcn, name), m_stack_context (stack_context)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
395 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
396 m_stack_context->mark_closure_context ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
397 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
398
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
399 nested_fcn_handle (const nested_fcn_handle&) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
400
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
401 ~nested_fcn_handle (void) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
402
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
403 using base_nested_fcn_handle::is_nested;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
404
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
405 bool is_nested (const std::shared_ptr<stack_frame>& frame) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
406 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
407 return frame == m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
408 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
409
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
410 nested_fcn_handle * clone (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
411 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
412 return new nested_fcn_handle (*this);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
413 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
414
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
415 octave_value make_weak_nested_handle (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
416
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
417 octave_value_list call (int nargout, const octave_value_list& args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
418
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
419 octave_value workspace (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
420
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
421 friend bool is_equal_to (const nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
422 const nested_fcn_handle& fh2);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
423
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
424 std::shared_ptr<stack_frame> stack_context (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
425 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
426 return m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
427 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
428
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
429 protected:
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
430
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
431 // Pointer to closure stack frames.
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
432 std::shared_ptr<stack_frame> m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
433 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
434
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
435 class weak_nested_fcn_handle : public base_nested_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
436 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
437 public:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
438
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
439 weak_nested_fcn_handle (const nested_fcn_handle& nfh)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
440 : base_nested_fcn_handle (nfh), m_stack_context (nfh.stack_context ())
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
441 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
442
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
443 weak_nested_fcn_handle (const weak_nested_fcn_handle&) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
444
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
445 ~weak_nested_fcn_handle (void) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
446
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
447 weak_nested_fcn_handle * clone (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
448 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
449 return new weak_nested_fcn_handle (*this);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
450 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
451
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
452 bool is_weak_nested (void) const { return true; }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
453
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
454 octave_value_list call (int nargout, const octave_value_list& args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
455
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
456 octave_value workspace (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
457
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
458 friend bool is_equal_to (const weak_nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
459 const weak_nested_fcn_handle& fh2);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
460
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
461 protected:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
462
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
463 // Pointer to closure stack frames.
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
464 std::weak_ptr<stack_frame> m_stack_context;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
465 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
466
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
467 class class_simple_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
468 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
469 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
470
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
471 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
472 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
473
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
474 class_simple_fcn_handle (const std::string& name,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
475 const std::string& file,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
476 const std::string& /*octaveroot*/)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
477 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
478 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
479
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
480 // FIXME: is the method name supposed to be just the method name or
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
481 // also contain the object name?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
482
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
483 class_simple_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
484 const std::string& meth_nm);
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
485
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
486 class_simple_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
487 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
488 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
489
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
490 class_simple_fcn_handle (const octave_value& obj, const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
491 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
492 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
493
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
494 class_simple_fcn_handle (const class_simple_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
495
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
496 ~class_simple_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
497
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
498 class_simple_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
499 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
500 return new class_simple_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
501 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
502
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
503 std::string type (void) const { return "classsimple"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
504
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
505 bool is_class_simple (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
506
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
507 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
508
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
509 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
510 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
511 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
512 {
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
513 // FIXME: Shouldn't the lookup rules here match those used in the
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
514 // call method?
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
515
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
516 if (m_fcn.is_defined ())
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
517 return m_fcn.function_value ();
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
518
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
519 symbol_table& symtab
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
520 = __get_symbol_table__ ("class_simple_fcn_handle::function_value");
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
521
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
522 // FIXME: is caching the correct thing to do?
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
523 // Cache this value so that the pointer will be valid as long as the
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
524 // function handle object is valid.
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
525
29207
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
526 // FIXME: This should probably dispatch to the respective class method.
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
527 // But that breaks if a function handle is used in a class method with
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
528 // e.g. bsxfun with arguments of a different class (see bug #59661).
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
529 // m_fcn = symtab.find_method (m_name, m_dispatch_class);
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
530 m_fcn = symtab.find_function (m_name, octave_value_list ());
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
531
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
532 return m_fcn.is_defined () ? m_fcn.function_value () : nullptr;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
533 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
534
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
535 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
536 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
537 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
538 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
539
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
540 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
541
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
542 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
543 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
544
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
545 std::string dispatch_class (void) const { return m_dispatch_class; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
546
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
547 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
548
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
549 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
550
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
551 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
552
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
553 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
554
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
555 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
556
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
557 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
558 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
559
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
560 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
561 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
562
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
563 friend bool is_equal_to (const class_simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
564 const class_simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
565
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
566 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
567
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
568 // The object containing the method we are handing.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
569 octave_value m_obj;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
570
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
571 // The method we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
572 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
573
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
574 // Name of the class that m_fcn belongs to.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
575 std::string m_dispatch_class;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
576 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
577
29541
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
578 // Handles to anonymous functions are similar to handles to nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
579 // functions. If they are created in a context that contains nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
580 // functions, then they store a link to the parent call stack frames
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
581 // that are active when they are created. These call stack frames
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
582 // (closure frames) provide access to variables needed by any nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
583 // functions that are called from the anonymous function. Anonymous
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
584 // functions also store a list of values from their parent scope
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
585 // corresponding to the symbols in the anonymous function. This list
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
586 // of values captures the variable values that are visible in the
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
587 // scope where they are created.
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
588 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
589 // Note that because handles to anonymous and nested functions capture
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
590 // call stack frames when they are created, they will cause deletion
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
591 // of the values in those frames to be deferred until the handles to
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
592 // the anonymous or nested functions are deleted.
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
593 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
594 // Would it be possible to avoid storing the closure frames for
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
595 // handles to anonymous functions if we can determine that the
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
596 // anonymous function has no unbound variables (or parameters, which
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
597 // could be handles to nested functions?) or if it is not created in a
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
598 // context that contains nested functions?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
599 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
600 // Would it be possible to define anonymous functions as a special
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
601 // type of nested function object that also has an variable
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
602 // initialization list associated with it?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
603
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
604 class base_anonymous_fcn_handle : public base_fcn_handle
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
605 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
606 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
607
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
608 static const std::string anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
609
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
610 // Setting NAME here is a bit of a kluge to cope with a bad choice
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
611 // made to append the number of local variables to the @<anonymous>
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
612 // tag in the binary file format. See also the save_binary and
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
613 // load_binary functions.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
614
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
615 base_anonymous_fcn_handle (const std::string& name = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
616 : base_fcn_handle (name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
617 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
618
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
619 base_anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
620 const stack_frame::local_vars_map& local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
621 : base_fcn_handle (anonymous), m_fcn (fcn), m_local_vars (local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
622 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
623
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
624 base_anonymous_fcn_handle (const base_anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
625
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
626 ~base_anonymous_fcn_handle (void) = default;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
627
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
628 std::string type (void) const { return "anonymous"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
629
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
630 bool is_anonymous (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
631
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
632 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
633 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
634 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
635 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
636 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
637 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
638
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
639 octave_user_function * user_function_value (bool = false)
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
640 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
641 return m_fcn.user_function_value ();
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
642 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
643
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
644 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
645
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
646 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
647
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
648 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
649 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
650
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
651 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
652
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
653 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
654
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
655 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
656
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
657 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
658
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
659 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
660
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
661 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
662 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
663
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
664 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
665 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
666
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
667 // Anonymous function handles are printed without a newline.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
668 bool print_as_scalar (void) const { return false; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
669
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
670 bool parse (const std::string& fcn_text);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
671
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
672 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
673
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
674 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
675 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
677 // List of captured variable values for anonymous fucntions.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
678 stack_frame::local_vars_map m_local_vars;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
679 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
680
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
681 class anonymous_fcn_handle : public base_anonymous_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
682 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
683 public:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
684
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
685 using base_anonymous_fcn_handle::anonymous;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
686
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
687 // Setting NAME here is a bit of a kluge to cope with a bad choice
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
688 // made to append the number of local variables to the @<anonymous>
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
689 // tag in the binary file format. See also the save_binary and
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
690 // load_binary functions.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
691
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
692 anonymous_fcn_handle (const std::string& name = "")
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
693 : base_anonymous_fcn_handle (name), m_stack_context ()
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
694 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
695
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
696 anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
697 const stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
698 const std::shared_ptr<stack_frame>& stack_context = std::shared_ptr<stack_frame> ());
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
699
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
700 anonymous_fcn_handle (const anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
701
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
702 ~anonymous_fcn_handle (void) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
703
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
704 anonymous_fcn_handle * clone (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
705 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
706 return new anonymous_fcn_handle (*this);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
707 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
708
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
709 octave_value make_weak_anonymous_handle (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
710
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
711 octave_value_list call (int nargout, const octave_value_list& args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
712
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
713 octave_value workspace (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
714
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
715 friend bool is_equal_to (const anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
716 const anonymous_fcn_handle& fh2);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
717
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
718 std::shared_ptr<stack_frame> stack_context (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
719 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
720 return m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
721 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
722
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
723 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
724
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
725 // Pointer to closure stack frames.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
726 std::shared_ptr<stack_frame> m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
727 };
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
728
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
729 class weak_anonymous_fcn_handle : public base_anonymous_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
730 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
731 public:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
732
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
733 using base_anonymous_fcn_handle::anonymous;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
734
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
735 weak_anonymous_fcn_handle (const anonymous_fcn_handle& afh)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
736 : base_anonymous_fcn_handle (afh), m_stack_context (afh.stack_context ())
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
737 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
738
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
739 weak_anonymous_fcn_handle (const weak_anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
740
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
741 ~weak_anonymous_fcn_handle (void) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
742
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
743 weak_anonymous_fcn_handle * clone (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
744 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
745 return new weak_anonymous_fcn_handle (*this);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
746 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
747
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
748 bool is_weak_anonymous (void) const { return true; }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
749
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
750 octave_value_list call (int nargout, const octave_value_list& args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
751
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
752 octave_value workspace (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
753
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
754 friend bool is_equal_to (const weak_anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
755 const weak_anonymous_fcn_handle& fh2);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
756
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
757 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
758
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
759 // Pointer to closure stack frames.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
760 std::weak_ptr<stack_frame> m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
761 };
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
762
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
763 extern bool is_equal_to (const anonymous_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
764 const anonymous_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
765
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
766 static void err_invalid_fcn_handle (const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
767 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
768 error ("invalid function handle, unable to find function for @%s",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
769 name.c_str ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
770 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
771
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
772 octave_value base_fcn_handle::make_weak_nested_handle (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
773 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
774 std::string type_str = type ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
775 error ("invalid conversion from %s handle to weak nestead handle",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
776 type_str.c_str ());
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
777 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
778
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
779 octave_value base_fcn_handle::make_weak_anonymous_handle (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
780 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
781 std::string type_str = type ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
782 error ("invalid conversion from %s handle to weak anonymous handle",
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
783 type_str.c_str ());
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
784 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
785
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
786 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
787 base_fcn_handle::subsref (const std::string& type,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
788 const std::list<octave_value_list>& idx,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
789 int nargout)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
790 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
791 octave_value_list retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
792
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
793 switch (type[0])
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
794 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
795 case '(':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
796 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
797 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
798
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
799 retval = call (tmp_nargout, idx.front ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
800 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
801 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
802
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
803 case '{':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
804 case '.':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
805 error ("function handle cannot be indexed with %c", type[0]);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
806
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
807 default:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
808 panic_impossible ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
809 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
810
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
811 // FIXME: perhaps there should be an
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
812 // octave_value_list::next_subsref member function? See also
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
813 // octave_builtin::subsref.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
814
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
815 if (idx.size () > 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
816 retval = retval(0).next_subsref (nargout, type, idx);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
817
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
818 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
819 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
820
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
821 octave_value
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
822 base_fcn_handle::convert_to_str_internal (bool, bool, char type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
823 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
824 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
825 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
826 return octave_value (buf.str (), type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
827 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
828
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
829 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
830 base_fcn_handle::save_ascii (std::ostream&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
831 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
832 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
833
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
834 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
835 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
836
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
837 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
838 base_fcn_handle::load_ascii (std::istream&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
839 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
840 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
841
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
842 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
843 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
844
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
845 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
846 base_fcn_handle::save_binary (std::ostream&, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
847 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
848 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
849
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
850 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
851 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
852
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
853 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
854 base_fcn_handle::load_binary (std::istream&, bool, mach_info::float_format)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
855 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
856 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
857
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
858 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
859 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
860
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
861 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
862 base_fcn_handle::save_hdf5 (octave_hdf5_id, const char *, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
863 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
864 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
865
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
866 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
867 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
868
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
869 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
870 base_fcn_handle::load_hdf5 (octave_hdf5_id&, octave_hdf5_id&, octave_hdf5_id&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
871 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
872 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
873
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
874 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
875 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
876
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
877 void base_fcn_handle::warn_load (const char *file_type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
878 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
879 std::string obj_type = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
880
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
881 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
882 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
883 "%s: loading %s files not available in this version of Octave",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
884 obj_type.c_str (), file_type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
885 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
886
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
887 void base_fcn_handle::warn_save (const char *file_type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
888 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
889 std::string obj_type = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
890
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
891 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
892 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
893 "%s: saving %s files not available in this version of Octave",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
894 obj_type.c_str (), file_type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
895 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
896
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
897 void base_fcn_handle::unimplemented (const char *op, const char *fmt) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
898 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
899 std::string htype = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
900
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
901 warning ("%s for %s handles with %s format is not implemented",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
902 op, htype.c_str (), fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
903 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
904
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
905 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
906 invalid_fcn_handle::call (int, const octave_value_list&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
907 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
908 error ("invalid call to invalid function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
909 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
910
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
911 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
912 internal_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
913 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
914 interpreter& interp = __get_interpreter__ ("internal_fcn_handle::call");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
915
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
916 return interp.feval (m_fcn, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
917 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
918
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
919 octave_scalar_map internal_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
920 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
921 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
922
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
923 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
924 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
925 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
926
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
927 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
928 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
929
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
930 bool is_equal_to (const internal_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
931 const internal_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
932 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
933 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
934 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
935 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
936 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
937 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
938 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
939
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
940 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
941 simple_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
942 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
943 // FIXME: if m_name has a '.' in the name, lookup first component. If
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
944 // it is a classdef meta object, then build TYPE and IDX arguments and
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
945 // make a subsref call using them.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
946
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
947 interpreter& interp = __get_interpreter__ ("simple_fcn_handle::call");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
948
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
949 octave_value fcn_to_call;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
950
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
951 // The following code is similar to part of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
952 // tree_evaluator::visit_index_expression but simpler because it
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
953 // handles a more restricted case.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
954
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
955 symbol_table& symtab = interp.get_symbol_table ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
956
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
957 std::size_t pos = m_name.find ('.');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
958
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
959 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
960 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
961 // FIXME: check to see which of these cases actually work in
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
962 // Octave and Matlab. For the last two, assume handle is
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
963 // created before object is defined as an object.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
964 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
965 // We can have one of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
966 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
967 // pkg-list . fcn (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
968 // pkg-list . cls . meth (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
969 // class-name . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
970 // class-name . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
971 // object . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
972 // object . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
973
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
974 // Evaluate package elements until we find a function,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
975 // classdef object, or classdef_meta object that is not a
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
976 // package. An object may only appear as the first element,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
977 // then it must be followed directly by a function name.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
978
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
979 std::size_t beg = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
980 std::size_t end = pos;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
981
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
982 std::vector<std::string> idx_elts;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
983
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
984 while (true)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
985 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
986 end = m_name.find ('.', beg);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
987
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
988 idx_elts.push_back (m_name.substr (beg, end-beg));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
989
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
990 if (end == std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
991 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
992
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
993 beg = end+1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
994 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
995
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
996 std::size_t n_elts = idx_elts.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
998 bool have_object = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
999 octave_value partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1000
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1001 // Lazy evaluation. The first element was not known to be defined
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1002 // as an object in the scope where the handle was created. See if
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1003 // there is a definition in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1004
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1005 partial_expr_val = interp.varval (idx_elts[0]);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1006
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1007 if (partial_expr_val.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1008 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1009 if (! partial_expr_val.is_classdef_object () || n_elts != 2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1010 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1011
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1012 have_object = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1013 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1014 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1015 partial_expr_val = symtab.find_function (idx_elts[0], ovl ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1016
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1017 std::string type;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1018 std::list<octave_value_list> arg_list;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1019
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
1020 for (std::size_t i = 1; i < n_elts; i++)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1021 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1022 if (partial_expr_val.is_package ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1023 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1024 if (have_object)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1025 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1026
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1027 type = ".";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1028 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1029
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1030 try
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1031 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1032 // Silently ignore extra output values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1033
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1034 octave_value_list tmp_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1035 = partial_expr_val.subsref (type, arg_list, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1036
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1037 partial_expr_val
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1038 = tmp_list.length () ? tmp_list(0) : octave_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1039
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1040 if (partial_expr_val.is_cs_list ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1041 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1042
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1043 arg_list.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1044 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29063
diff changeset
1045 catch (const index_exception&)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1046 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1047 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1048 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1049 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1050 else if (have_object || partial_expr_val.is_classdef_meta ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1051 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1052 // Object or class name must be the next to the last
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1053 // element (it was the previous one, so if this is the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1054 // final element, it should be a classdef method,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1055 // but we'll let the classdef or classdef_meta subsref
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1056 // function sort that out.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1057
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1058 if (i != n_elts-1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1059 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1060
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1061 type = ".(";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1062 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1063 arg_list.push_back (args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1064
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1065 return partial_expr_val.subsref (type, arg_list, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1066 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1067 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1068 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1069 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1070
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1071 // If we get here, we must have a function to call.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1072
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1073 if (! partial_expr_val.is_function ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1074 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1075
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1076 fcn_to_call = partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1077 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1078 else
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1079 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1080 // No "." in the name.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1081
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1082 // Perform function lookup given current arguments. We'll need
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1083 // to do this regardless of whether a function was found when
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1084 // the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1085
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1086 octave_value ov_fcn = symtab.find_function (m_name, args);
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1087
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1088 if (m_fcn.is_defined ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1089 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1090 // A simple function was found when the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1091 // Use that unless we find a class method to override it.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1092
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1093 fcn_to_call = m_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1094
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1095 if (ov_fcn.is_defined ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1096 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1097 octave_function *fcn = ov_fcn.function_value ();
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1098
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1099 std::string dispatch_class = fcn->dispatch_class ();
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1100
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1101 if (fcn->is_class_method ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1102 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1103 // Function found through lookup is a class method
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1104 // so use it instead of the simple one found when
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1105 // the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1106
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1107 fcn_to_call = ov_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1108 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1109 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1110 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1111 else
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1112 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1113 // There was no simple function found when the handle was
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1114 // created so use the one found here (if any).
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1115
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1116 fcn_to_call = ov_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1117 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1118 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1119
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1120 if (! fcn_to_call.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1121 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1122
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1123 return interp.feval (fcn_to_call, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1124 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1125
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1126 octave_function * simple_fcn_handle::function_value (bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1127 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1128 // FIXME: Shouldn't the lookup rules here match those used in the
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1129 // call method?
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1130
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1131 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1132 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1133
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1134 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1135 = __get_symbol_table__ ("simple_fcn_handle::function_value");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1136
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1137 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1138 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1139 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1140
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1141 m_fcn = symtab.find_function (m_name, octave_value_list ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1142
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1143 return m_fcn.is_defined () ? m_fcn.function_value () : nullptr;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1144 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1145
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1146 octave_user_function * simple_fcn_handle::user_function_value (bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1147 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1148 // FIXME: Shouldn't the lookup rules here match those used in the
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1149 // call method?
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1150
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1151 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1152 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1153
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1154 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1155 = __get_symbol_table__ ("simple_fcn_handle::user_function_value");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1156
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1157 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1158 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1159 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1160
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1161 m_fcn = symtab.find_user_function (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1162
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1163 return m_fcn.is_defined () ? m_fcn.user_function_value () : nullptr;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1164 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1165
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1166 octave_value simple_fcn_handle::fcn_val (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1167 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1168 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1169 return m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1170
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1171 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1172 = __get_symbol_table__ ("simple_fcn_handle::user_function_value");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1173
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1174 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1175 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1176 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1177
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1178 m_fcn = symtab.find_user_function (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1179
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1180 return m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1181 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1182
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1183 octave_scalar_map simple_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1184 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1185 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1186
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1187 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1188 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1189 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1190 m.setfield ("file", file ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1191
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1192 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1193 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1194
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1195 bool simple_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1196 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1197 os << "# octaveroot: " << config::octave_exec_home () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1198
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1199 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1200 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1201 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1202
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1203 os << "# subtype: " << type () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1204
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1205 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1206
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1207 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1208 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1209
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1210 bool simple_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1211 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1212 // FIXME: If m_file is not empty, try to load the file and define
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1213 // the function? Is it an error if that fails? Or should this job
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1214 // always be deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1215
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1216 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1217 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1218
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1219 bool simple_fcn_handle::save_binary (std::ostream& os, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1220 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1221 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1222
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1223 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1224 std::string fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1225
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1226 nmbuf << m_name << "@<simple>\n" << config::octave_exec_home ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1227 << "\n" << fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1228
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1229 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1230 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1231 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1232 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1233
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1234 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1235 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1236
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1237 bool simple_fcn_handle::load_binary (std::istream& is, bool,
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1238 mach_info::float_format)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1239 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1240 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1241 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1242
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1243 bool simple_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1244 bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1245 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1246 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1247
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1248 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1249
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1250 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1251 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1252 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1253 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1254 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1255 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1256 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1257 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1258 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1259
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1260 octave_hdf5_id space_hid, data_hid, type_hid;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1261 space_hid = data_hid = type_hid = -1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1262
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1263 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1264 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1265 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1266 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1267 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1268 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1269 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1270 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1271
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1272 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1273 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1274 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1275 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1276 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1277 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1278 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1279 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1280 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1281 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1282 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1283 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1284 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1285 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1286 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1287 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1288 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1289 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1290 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1291 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1292 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1293 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1294 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1295 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1296 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1297 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1298 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1299 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1300
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1301 std::string octaveroot = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1302
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1303 // When is FILE defined for simple fucntion handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1304 std::string fpath;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1305
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1306 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1307 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1308 hdims[1] = octaveroot.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1309 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1310 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1311 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1312 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1313 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1314 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1315 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1316
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1317 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1318 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1319 H5Tset_size (type_hid, octaveroot.length () + 1);
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1320 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1321 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1322 a_id = H5Acreate (group_hid, "OCTAVEROOT", type_hid, space_hid,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1323 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1324 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1325 a_id = H5Acreate (group_hid, "OCTAVEROOT", type_hid, space_hid,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1326 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1327 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1328
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1329 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1330 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1331 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1332
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1333 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1334 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1335 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1336 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1337 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1338 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1339 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1340 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1341 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1342
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1343 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1344 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1345 hdims[1] = fpath.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1346 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1347 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1348 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1349 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1350 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1351 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1352 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1353
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1354 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1355 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1356 H5Tset_size (type_hid, fpath.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1357
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1358 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1359 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1360 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1361 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1362 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1363 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1365 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1366 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1367 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1368
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1369 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1370 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1371 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1372 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1373
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1374 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1375 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1376 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1377
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1378 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1379
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1380 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1381
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1382 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1383 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1384
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1385 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1386
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1387 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1388
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1389 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1390 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1391
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1392 bool simple_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1393 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1394 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1395 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1396 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1397
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1398 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1399
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1400 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1401 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1402 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1403
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1404 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1405
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1406 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1407
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1408 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1409 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1410 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1411
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1412 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1413
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1414 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1415 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1416
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1417 void simple_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1418 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1419 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1420 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1421 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1422 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1423
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1424 bool is_equal_to (const simple_fcn_handle& fh1, const simple_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1425 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1426 if (fh1.m_name == fh2.m_name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1427 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1428 if (fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1429 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1430
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1431 if (fh1.m_fcn.is_undefined () && fh2.m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1432 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1433 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1434
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1435 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1436 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1437
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1438 scoped_fcn_handle::scoped_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1439 const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1440 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1441 : base_fcn_handle (name), m_fcn (fcn), m_parentage (parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1442 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1443 // FIXME: should it be an error if FCN is undefined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1444
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1445 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1446 {
28450
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1447 octave_function *oct_fcn = m_fcn.function_value ();
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1448
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1449 if (oct_fcn)
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1450 m_file = oct_fcn->fcn_file_name ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1451 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1452
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1453 m_parentage.push_front (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1454 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1455
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1456 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1457 scoped_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1458 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1459 // FIXME: we aren't really using the scope yet. Hmm.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1460
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1461 interpreter& interp = __get_interpreter__ ("simple_fcn_handle::call");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1462
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1463 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1464 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1465 // Try to find it?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1466
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1467 find_function ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1468 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1469
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1470 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1471 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1472
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1473 return interp.feval (m_fcn, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1474 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1475
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1476 octave_scalar_map scoped_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1477 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1478 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1479
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1480 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1481 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1482 m.setfield ("file", file ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1483
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1484 m.setfield ("parentage", Cell (m_parentage));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1485
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1486 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1487 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1488
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1489 bool scoped_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1490 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1491 os << "# octaveroot: " << config::octave_exec_home () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1492
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1493 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1494 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1495 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1496
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1497 os << "# subtype: " << type () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1498
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1499 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1500
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1501 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1502 tmp.save_ascii (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1503
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1504 return os.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1505 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1506
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1507 bool scoped_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1508 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1509 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1510 ov_cell.load_ascii (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1511
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1512 if (ov_cell.iscellstr ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1513 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1514 Array<std::string> cellstr_val = ov_cell.cellstr_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1515
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1516 for (octave_idx_type i = 0; i < cellstr_val.numel (); i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1517 m_parentage.push_back (cellstr_val(i));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1518 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1519
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1520 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1521 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1522
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1523 bool scoped_fcn_handle::save_binary (std::ostream& os, bool save_as_floats)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1524 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1525 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1526
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1527 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1528
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1529 nmbuf << m_name << "@<scopedfunction>\n" << config::octave_exec_home ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1530 << "\n" << fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1531
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1532 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1533 int32_t len = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1534 os.write (reinterpret_cast<char *> (&len), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1535 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1536
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1537 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1538 tmp.save_binary (os, save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1539
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1540 return os.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1541 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1542
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1543 bool scoped_fcn_handle::load_binary (std::istream& is, bool swap,
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1544 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1545 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1546 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1547 ov_cell.load_binary (is, swap, fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1548
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1549 if (ov_cell.iscellstr ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1550 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1551 Array<std::string> cellstr_val = ov_cell.cellstr_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1552
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1553 for (octave_idx_type i = 0; i < cellstr_val.numel (); i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1554 m_parentage.push_back (cellstr_val(i));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1555 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1556
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1557 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1558 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1559
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1560 bool scoped_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1561 bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1562 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1563 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1564
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1565 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1566
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1567 // FIXME: save parentage.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1568
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1569 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1570 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1572 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1573
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1574 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1575
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1576 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1577 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1578
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1579 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1580
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1581 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1582
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1583 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1584 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1585
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1586 bool scoped_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1587 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1588 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1589 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1590 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1591
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1592 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1593
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1594 // FIXME: load parentage.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1595
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1596 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1597 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1598 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1599
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1600 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1601
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1602 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1603
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1604 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1605 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1606 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1607
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1608 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1609
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1610 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1611 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1612
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1613 void scoped_fcn_handle::print_raw (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1614 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1615 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1616 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1617 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1618 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1619 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1620
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1621 bool is_equal_to (const scoped_fcn_handle& fh1, const scoped_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1622 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1623 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1624 && fh2.m_parentage == fh2.m_parentage
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1625 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1626 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1627 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1628 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1629 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1630
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1631 void scoped_fcn_handle::find_function (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1632 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1633 // Since a scoped function is not visible by itself, try to load the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1634 // file named in m_file then find and define the scoped function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1635 // It is not an error if this fails. We can report later that the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1636 // handle is invalid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1637
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1638 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1639 = __get_symbol_table__ ("scoped_fcn_handle::find_function");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1640
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1641 if (m_parentage.size () == 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1642 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1643 std::string dir_name = sys::file_ops::dirname (m_file);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1644
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
1645 std::size_t pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1646
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1647 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1648 dir_name = dir_name.substr (0, pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1649 else if (dir_name == "private")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1650 dir_name = ".";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1651
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1652 std::string fcn_name = m_parentage.front ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1653
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1654 // FIXME: Does dir_name need to be in the load path for this to work?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1655
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1656 m_fcn = symtab.find_private_function (dir_name, m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1657
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1658 // FIXME: Verify that it is a private function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1659 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1660 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1661 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1662 std::string primary_parent_name = m_parentage.back ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1663
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1664 octave_value ov_parent_fcn
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1665 = symtab.find_user_function (primary_parent_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1666
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1667 if (ov_parent_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1668 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1669 octave_user_function *fcn = ov_parent_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1670
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1671 if (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1672 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1673 std::string file_name = fcn->fcn_file_name ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1674
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1675 std::string oct_home = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1677 if (file_name.substr (0, oct_home.size ()) == oct_home)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1678 file_name = file_name.substr (oct_home.size ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1679
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1680 octave_value subfun = fcn->find_subfunction (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1681
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1682 if (subfun.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1683 m_fcn = subfun;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1684 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1685 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1686 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1687 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1688
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1689 octave_scalar_map base_nested_fcn_handle::info (void)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1690 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1691 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1692
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1693 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1694 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1695 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1696 m.setfield ("workspace", workspace ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1697
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1698 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1699 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1700
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1701 // FIXME: For save, we need a way to save the (possibly shared)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1702 // workspace. For load, we need a way to load and link to the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1703 // (possibly shared) workspace that was saved.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1704 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1705 // Since a nested function is not visible by itself, do we need to try
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1706 // to load the file named in m_file then find and define the function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1707 // Is it an error if that fails? Or should this job always be
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1708 // deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1709
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1710 bool base_nested_fcn_handle::save_ascii (std::ostream& os)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1711 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1712 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1713
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1714 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1715
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1716 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1717 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1718
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1719 bool base_nested_fcn_handle::load_ascii (std::istream& is)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1720 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1721 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1722
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1723 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1724
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1725 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1726 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1727
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1728 bool base_nested_fcn_handle::save_binary (std::ostream& os,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1729 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1730 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1731 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1732
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1733 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1734 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1735
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1736 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1737 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1738
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1739 bool base_nested_fcn_handle::load_binary (std::istream& is, bool swap,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1740 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1741 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1742 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1743
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1744 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1745 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1746 octave_unused_parameter (fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1747
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1748 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1749 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1750
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1751 bool base_nested_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1752 const char *name, bool)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1753 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1754 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1755
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1756 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1757
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1758 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1759 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1760
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1761 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1762
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1763 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1764
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1765 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1766 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1767
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1768 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1769
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1770 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1771
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1772 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1773 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1774
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1775 bool base_nested_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1776 octave_hdf5_id& space_hid,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1777 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1778 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1779 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1780
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1781 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1782
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1783 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1784 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1785 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1786
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1787 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1788
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1789 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1790
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1791 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1792 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1793 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1794
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1795 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1796
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1797 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1798 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1799
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1800 void base_nested_fcn_handle::print_raw (std::ostream& os,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1801 bool pr_as_read_syntax,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1802 int current_print_indent_level) const
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1803 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1804 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1805 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1806 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1807
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1808 octave_value nested_fcn_handle::make_weak_nested_handle (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1809 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1810 return octave_value (new octave_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1811 (new weak_nested_fcn_handle (*this)));
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1812 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1813
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1814 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1815 nested_fcn_handle::call (int nargout, const octave_value_list& args)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1816 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1817 tree_evaluator& tw = __get_evaluator__ ("nested_fcn_handle::call");
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1818
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1819 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1820
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1821 tw.push_stack_frame (oct_usr_fcn, m_stack_context);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1822
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1823 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1824
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1825 return oct_usr_fcn->execute (tw, nargout, args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1826 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1827
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1828 octave_value nested_fcn_handle::workspace (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1829 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1830 return m_stack_context->workspace ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1831 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1832
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1833 bool is_equal_to (const nested_fcn_handle& fh1, const nested_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1834 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1835 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1836 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1837 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1838 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1839 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1840 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1841
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1842 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1843 weak_nested_fcn_handle::call (int nargout, const octave_value_list& args)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1844 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1845 tree_evaluator& tw = __get_evaluator__ ("weak_nested_fcn_handle::call");
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1846
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1847 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1848
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1849 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1850
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1851 tw.push_stack_frame (oct_usr_fcn, frames);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1852
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1853 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1854
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1855 return oct_usr_fcn->execute (tw, nargout, args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1856 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1857
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1858 octave_value weak_nested_fcn_handle::workspace (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1859 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1860 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1861
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1862 return frames ? frames->workspace () : octave_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1863 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1864
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1865 bool is_equal_to (const weak_nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1866 const weak_nested_fcn_handle& fh2)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1867 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1868 if (fh1.m_name == fh2.m_name
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1869 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1870 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1871 else
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1872 return false;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1873 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1874
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1875 class_simple_fcn_handle::class_simple_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1876 const std::string& meth_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1877 : base_fcn_handle (meth_nm), m_obj (), m_fcn (),
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1878 m_dispatch_class (class_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1879 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1880
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1881 class_simple_fcn_handle::class_simple_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1882 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1883 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1884 : base_fcn_handle (meth_nm), m_obj (), m_fcn (fcn),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1885 m_dispatch_class (class_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1886 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1887
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1888 class_simple_fcn_handle::class_simple_fcn_handle (const octave_value& obj,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1889 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1890 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1891 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1892 : base_fcn_handle (meth_nm), m_obj (obj), m_fcn (fcn),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1893 m_dispatch_class (class_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1894 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1895
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1896 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1897 class_simple_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1898 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1899 interpreter& interp = __get_interpreter__ ("class_simple_fcn_handle::call");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1900
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1901 if (m_obj.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1902 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1903 octave_value_list tmp_args = args;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1904 tmp_args.prepend (m_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1905
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1906 return interp.feval (m_fcn, tmp_args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1907 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1908
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1909 // FIXME: is this the best approach? Should we be saving current
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1910 // dispatch class and restoring that value instead of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1911 // unconditionally setting it to "" when we return from this
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1912 // function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1913
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1914 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1915
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1916 unwind_action act ([&tw] () { tw.set_dispatch_class (""); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1917
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1918 tw.set_dispatch_class (m_dispatch_class);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1919
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1920 if (m_fcn.is_defined ())
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1921 return interp.feval (m_fcn, args, nargout);
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1922
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1923 return interp.feval (fcn_name (), args, nargout);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1924 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1925
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1926 octave_scalar_map class_simple_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1927 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1928 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1929
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1930 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1931 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1932 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1933 m.setfield ("class", dispatch_class ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1934
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1935 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1936 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1937
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1938 // FIXME: Since a class method is not visible by itself, do we need to
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1939 // try to load the file named in m_file then find and define the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1940 // function? Is it an error if that fails? Or should this job always
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1941 // be deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1942
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1943 bool class_simple_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1944 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1945 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1946
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1947 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1948
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1949 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1950 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1951
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1952 bool class_simple_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1953 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1954 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1955
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1956 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1957
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1958 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1959 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1960
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1961 bool class_simple_fcn_handle::save_binary (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1962 bool save_as_floats)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1963 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1964 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1965
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1966 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1967 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1968
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1969 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1970 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1971
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1972 bool class_simple_fcn_handle::load_binary (std::istream& is, bool swap,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1973 mach_info::float_format fmt)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1974 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1975 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1976
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1977 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1978 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1979 octave_unused_parameter (fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1980
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1981 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1982 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1983
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1984 bool class_simple_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1985 const char *name, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1986 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1987 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1988
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1989 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1990
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1991 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1992 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1993
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1994 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1995
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1996 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1998 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1999 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2000
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2001 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2002
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2003 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2004
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2005 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2006 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2007
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2008 bool class_simple_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2009 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2010 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2011 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2012 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2013
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2014 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2015
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2016 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2017 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2018 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2019
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2020 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2021
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2022 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2023
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2024 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2025 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2026 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2027
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2028 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2029
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2030 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2031 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2032
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2033 void class_simple_fcn_handle::print_raw (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2034 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2035 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2036 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2037 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2038 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2039 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2040
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2041 bool is_equal_to (const class_simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2042 const class_simple_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2043 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2044 // FIXME: Also need to check object values are equivalent?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2045
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2046 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2047 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2048 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2049 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2050 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2051 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2052
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2053 const std::string base_anonymous_fcn_handle::anonymous ("@<anonymous>");
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2054
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2055 octave_scalar_map base_anonymous_fcn_handle::info (void)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2056 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2057 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2058
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2059 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2060 print_raw (buf, true, 0);
28455
925c169a4958 use "function" instead of "name" as field name returned from functions
John W. Eaton <jwe@octave.org>
parents: 28450
diff changeset
2061 m.setfield ("function", buf.str ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2062
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2063 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2064 m.setfield ("file", "");
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2065 m.setfield ("workspace", workspace ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2066 m.setfield ("within_file_path", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2067
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2068 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2069 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2070
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2071 bool base_anonymous_fcn_handle::save_ascii (std::ostream& os)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2072 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2073 // FIXME: can we ensure that m_fcn is always defined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2074
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2075 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2076 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2077
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2078 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2079
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2080 print_raw (os, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2081 os << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2082
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2083 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2084
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2085 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2086 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2087 os << "# length: " << varlen << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2088
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2089 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2090 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2091 if (! save_text_data (os, nm_val.second, nm_val.first, false, 0))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2092 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2093 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2094 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2095
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2096 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2097 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2098
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2099 bool base_anonymous_fcn_handle::load_ascii (std::istream& is)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2100 {
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2101 octave::skip_preceeding_newline (is);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2102
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2103 std::string buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2104
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2105 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2106 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2107 // Get a line of text whitespace characters included, leaving
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2108 // newline in the stream.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2109
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2110 buf = octave::read_until_newline (is, true);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2111 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2112
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2113 std::streampos pos = is.tellg ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2114
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2115 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2116 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2117
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2118 interpreter& interp
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2119 = __get_interpreter__ ("base_anonymous_fcn_handle::load_ascii");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2120
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2121 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2122
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2123 tw.push_dummy_scope (buf);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2124 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2125
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2126 octave_idx_type len = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2127
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2128 if (extract_keyword (is, "length", len, true) && len >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2129 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2130 if (len > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2131 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2132 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2133 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2134 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2135 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2136
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2137 std::string name = read_text_data (is, "", dummy, t2, i);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2138
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2139 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2140 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2141
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2142 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2143 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2144 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2145 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2146 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2147 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2148 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2149 is.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2150 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2151
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2152 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2153 return parse (buf);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2154
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2155 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2156 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2157
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2158 bool base_anonymous_fcn_handle::save_binary (std::ostream& os,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2159 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2160 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2161 // FIXME: can we ensure that m_fcn is always defined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2162
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2163 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2164 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2165
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2166 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2167
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2168 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2169
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2170 nmbuf << anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2171 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2172 nmbuf << ' ' << varlen;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2173
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2174 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2175 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2176 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2177 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2178
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2179 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2180 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2181 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2182 tmp = stmp.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2183 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2184 os.write (stmp.c_str (), stmp.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2185
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2186 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2187 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2188 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2189 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2190 if (! save_binary_data (os, nm_val.second, nm_val.first,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2191 "", 0, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2192 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2193 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2194 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2195
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2196 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2197 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2198
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2199 bool base_anonymous_fcn_handle::load_binary (std::istream& is, bool swap,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2200 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2201 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2202 // Read extra characters in m_name as the number of local variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2203 // values in this anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2204
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2205 octave_idx_type len = 0;
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2206 std::size_t anl = anonymous.length ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2207 if (m_name.length () > anl)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2208 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2209 std::istringstream nm_is (m_name.substr (anl));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2210 nm_is >> len;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2211
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2212 // Anonymous functons don't have names. We just used this
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2213 // string as temporary storage to pass the number of local
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2214 // variable values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2215
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2216 m_name = "";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2217 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2218
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2219 int32_t tmp;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2220
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2221 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2222 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2223 if (swap)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2224 swap_bytes<4> (&tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2225
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2226 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2227 // is.get (ctmp2, tmp+1, 0); caused is.eof () to be true though
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2228 // effectively not reading over file end
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2229 is.read (ctmp2, tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2230 ctmp2[tmp] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2231
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2232 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2233 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2234
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2235 interpreter& interp
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2236 = __get_interpreter__ ("base_anonymous_fcn_handle::load_binary");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2237
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2238 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2239
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2240 tw.push_dummy_scope (ctmp2);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2241 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2242
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2243 if (len > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2244 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2245 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2246 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2247 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2248 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2249 std::string doc;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2250
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2251 std::string name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2252 = read_binary_data (is, swap, fmt, "", dummy, t2, doc);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2253
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2254 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2255 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2256
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2257 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2258 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2259 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2260
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2261 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2262 return parse (ctmp2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2263
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2264 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2265 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2266
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2267 bool base_anonymous_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2268 const char *name,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2269 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2270 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2271 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2272
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2273 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2274
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2275 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2276 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2277 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2278 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2279 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2280 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2281 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2282 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2283 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2284
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2285 octave_hdf5_id space_hid, data_hid, type_hid;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2286 space_hid = data_hid = type_hid = -1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2287
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2288 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2289 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2290 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2291 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2292 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2293 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2294 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2295 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2296
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2297 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2298 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2299 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2300 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2301 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2302 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2303 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2304 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2305 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2306 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2307 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2308 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2309 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2310 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2311 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2312 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2313 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2314 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2315 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2316 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2317 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2318 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2319 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2320 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2321 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2322 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2323 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2324 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2325
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2326 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2327 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2328 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2329
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2330 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2331 H5Tset_size (type_hid, stmp.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2332 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2333 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2334 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2335 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2336 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2337 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2338
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2339 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2340 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2341 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2342 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2343 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2344 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2345 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2346 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2347 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2348 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2349 octave_H5P_DEFAULT, stmp.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2350 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2351 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2352 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2353 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2354 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2355 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2356
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2357 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2358
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2359 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2360
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2361 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2362 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2363 octave_hdf5_id as_id = H5Screate (H5S_SCALAR);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2365 if (as_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2366 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2367 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2368 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2369 a_id = H5Acreate (group_hid, "SYMBOL_TABLE", H5T_NATIVE_IDX, as_id,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2370 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2371
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2372 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2373 a_id = H5Acreate (group_hid, "SYMBOL_TABLE", H5T_NATIVE_IDX, as_id,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2374 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2375 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2376
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2377 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2378 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2379 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2380
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2381 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2382 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2383 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2384 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2385
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2386 H5Sclose (as_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2387 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2388 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2389 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2390 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2391 data_hid = H5Gcreate (group_hid, "symbol table",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2392 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2393 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2394 data_hid = H5Gcreate (group_hid, "symbol table", 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2395 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2396 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2397 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2398 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2399 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2400 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2401 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2402 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2403
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2404 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2405 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2406 if (! add_hdf5_data (data_hid, nm_val.second, nm_val.first,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2407 "", false, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2408 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2409 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2410
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2411 H5Gclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2412 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2413
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2414 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2415 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2416 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2417
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2418 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2419
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2420 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2421
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2422 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2423 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2424 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2425
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2426 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2427
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2428 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2429
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2430 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2431 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2432
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2433 bool base_anonymous_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2434 octave_hdf5_id& space_hid,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2435 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2436 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2437 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2438
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2439 bool success = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2440
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2441 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2442 octave_hdf5_id data_hid = H5Dopen (group_hid, "fcn", octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2443 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2444 octave_hdf5_id data_hid = H5Dopen (group_hid, "fcn");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2445 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2446
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2447 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2448 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2449 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2450 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2451 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2452 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2453 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2454
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2455 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2456 type_hid = H5Dget_type (data_hid);
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2457 octave_hdf5_id type_class_hid = H5Tget_class (type_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2458
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2459 if (type_class_hid != H5T_STRING)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2460 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2461 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2462 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2463 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2464 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2465 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2466 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2467
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2468 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2469 space_hid = H5Dget_space (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2470 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2471
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2472 if (rank != 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2473 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2474 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2475 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2476 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2477 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2478 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2479 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2480
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2481 int slen = H5Tget_size (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2482 if (slen < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2483 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2484 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2485 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2486 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2487 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2488 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2489 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2490
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2491 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2492
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2493 // create datatype for (null-terminated) string to read into:
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2494 octave_hdf5_id st_id = H5Tcopy (H5T_C_S1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2495 H5Tset_size (st_id, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2496
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2497 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2498 octave_H5P_DEFAULT, fcn_tmp)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2499 < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2500 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2501 H5Tclose (st_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2502 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2503 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2504 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2505 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2506 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2507 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2508 H5Tclose (st_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2509 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2510
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2511 octave_idx_type len = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2512
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2513 // we have to pull some shenanigans here to make sure
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2514 // HDF5 doesn't print out all sorts of error messages if we
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2515 // call H5Aopen for a non-existing attribute
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2516
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2517 H5E_auto_t err_func;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2518 void *err_func_data;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2519
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2520 // turn off error reporting temporarily, but save the error
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2521 // reporting function:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2522 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2523 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2524 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2525 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2526 H5Eget_auto (&err_func, &err_func_data);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2527 H5Eset_auto (nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2528 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2529
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2530 octave_hdf5_id attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2531
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2532 if (attr_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2533 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2534 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2535 success = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2536
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2537 H5Aclose (attr_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2538 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2539
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2540 // restore error reporting:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2541 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2542 H5Eset_auto (octave_H5E_DEFAULT, err_func, err_func_data);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2543 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2544 H5Eset_auto (err_func, err_func_data);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2545 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2546
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2547 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2548 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2549
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2550 interpreter& interp
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2551 = __get_interpreter__ ("base_anonymous_fcn_handle::load_hdf5");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2552
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2553 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2554
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2555 tw.push_dummy_scope (fcn_tmp);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2556 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2557
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2558 if (len > 0 && success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2559 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2560 hsize_t num_obj = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2561 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2562 data_hid = H5Gopen (group_hid, "symbol table", octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2563 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2564 data_hid = H5Gopen (group_hid, "symbol table");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2565 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2566 H5Gget_num_objs (data_hid, &num_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2567 H5Gclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2568
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2569 if (num_obj != static_cast<hsize_t> (len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2570 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2572 hdf5_callback_data dsub;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2573 int current_item = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2574 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2575 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2576 if (hdf5_h5g_iterate (group_hid, "symbol table", &current_item,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2577 &dsub) <= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2578 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2579
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2580 m_local_vars[dsub.name] = dsub.tc;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2581 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2582 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2583
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2584 if (success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2585 return parse (fcn_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2586
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2587 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2588
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2589 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2590
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2591 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2592 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2593 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2594
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2595 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2596
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2597 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2598 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2599
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2600 void base_anonymous_fcn_handle::print_raw (std::ostream& os, bool, int) const
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2601 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2602 tree_print_code tpc (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2603
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2604 octave_user_function *f = m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2605
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2606 if (! f)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2607 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2608
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2609 os << "@";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2610
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2611 // The parameter list should always be valid for anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2612 // functions, so we should always call accept for it, and it will
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2613 // print the parens for us.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2614
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2615 tree_parameter_list *p = f->parameter_list ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2616
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2617 if (p)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2618 p->accept (tpc);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2619
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2620 os << " ";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2621
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2622 tree_statement_list *b = f->body ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2623
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2624 assert (b->length () == 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2625
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2626 tree_statement *s = b->front ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2627
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2628 if (! s)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2629 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2630
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2631 assert (s->is_expression ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2632
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2633 tree_expression *e = s->expression ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2634
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2635 if (! e)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2636 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2637
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2638 tpc.print_fcn_handle_body (e);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2639 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2640
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2641 bool base_anonymous_fcn_handle::parse (const std::string& fcn_text)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2642 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2643 // FIXME: If evaluation of the string gives us an anonymous function
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2644 // handle object, then why extract the function and create a new
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2645 // anonymous function object? Why not just attach the workspace
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2646 // values to the object returned by eval_string? This code is also is
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2647 // duplicated in read_mat5_binary_element in ls-mat5.cc.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2648
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2649 interpreter& interp
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2650 = __get_interpreter__ ("base_anonymous_fcn_handle::parse");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2651
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2652 // Set up temporary scope to use for evaluating the text that defines
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2653 // the anonymous function so that we don't pick up values of random
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2654 // variables that might be in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2655
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2656 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2657 tw.push_dummy_scope ("read_mat5_binary_element");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2658
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2659 unwind_action act ([&tw] () { tw.pop_scope (); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2660
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2661 int parse_status;
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2662 octave_value anonymous_fcn_hdl
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2663 = interp.eval_string (fcn_text, true, parse_status);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2664
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2665 if (parse_status != 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2666 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2667
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2668 octave_fcn_handle *fh = anonymous_fcn_hdl.fcn_handle_value ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2669
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2670 if (! fh)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2671 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2672
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2673 m_fcn = fh->fcn_val ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2674
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2675 octave_user_function *uf = m_fcn.user_function_value (true);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2677 if (uf)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2678 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2679 symbol_scope uf_scope = uf->scope ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2680
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2681 if (uf_scope)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2682 uf_scope.cache_name (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2683 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2684
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2685 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2686 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2687
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2688 anonymous_fcn_handle::anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2689 const stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2690 const std::shared_ptr<stack_frame>& stack_context)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2691 : base_anonymous_fcn_handle (fcn, local_vars),
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2692 m_stack_context (stack_context)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2693 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2694
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2695 octave_value anonymous_fcn_handle::make_weak_anonymous_handle (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2696 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2697 return octave_value (new octave_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2698 (new weak_anonymous_fcn_handle (*this)));
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2699 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2700
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2701 octave_value_list
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2702 anonymous_fcn_handle::call (int nargout, const octave_value_list& args)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2703 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2704 tree_evaluator& tw = __get_evaluator__ ("anonymous_fcn_handle::call");
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2705
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2706 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2707
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2708 tw.push_stack_frame (oct_usr_fcn, m_local_vars, m_stack_context);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2709
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2710 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2711
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2712 return oct_usr_fcn->execute (tw, nargout, args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2713 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2714
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2715 octave_value anonymous_fcn_handle::workspace (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2716 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2717 octave_scalar_map local_vars_map;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2718
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2719 for (const auto& nm_val : m_local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2720 local_vars_map.assign (nm_val.first, nm_val.second);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2721
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2722 // FIXME: it would be more convenient if stack_frame::workspace
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2723 // returned a Cell object directly instead of a Cell in an
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2724 // octave_value object.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2725
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2726 Cell cell_frames;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2727
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2728 if (m_stack_context)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2729 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2730 octave_value ov_frames = m_stack_context->workspace ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2731 cell_frames = ov_frames.cell_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2732 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2733
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2734 octave_idx_type num_frames = cell_frames.numel ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2735 // FIXME: It seems there should be a simple way to concatenate cells...
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2736 Cell retval = Cell (num_frames+1, 1);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2737 retval(0) = m_local_vars;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2738 for (octave_idx_type i = 0; i < num_frames; i++)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2739 retval(i+1) = cell_frames(i);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2740
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2741 return retval;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2742 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2743
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2744 bool is_equal_to (const anonymous_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2745 const anonymous_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2746 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2747 if (fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2748 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2749 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2750 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2751 }
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2752
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2753 octave_value_list
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2754 weak_anonymous_fcn_handle::call (int nargout, const octave_value_list& args)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2755 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2756 tree_evaluator& tw = __get_evaluator__ ("anonymous_fcn_handle::call");
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2757
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2758 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2759
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2760 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2761
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2762 tw.push_stack_frame (oct_usr_fcn, m_local_vars, frames);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2763
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2764 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2765
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2766 return oct_usr_fcn->execute (tw, nargout, args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2767 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2768
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2769 octave_value weak_anonymous_fcn_handle::workspace (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2770 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2771 octave_scalar_map local_vars_map;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2772
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2773 for (const auto& nm_val : m_local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2774 local_vars_map.assign (nm_val.first, nm_val.second);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2775
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2776 // FIXME: it would be more convenient if stack_frame::workspace
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2777 // returned a Cell object directly instead of a Cell in an
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2778 // octave_value object.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2779
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2780 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2781
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2782 Cell cell_frames;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2783
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2784 if (frames)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2785 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2786 octave_value ov_frames = frames->workspace ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2787 cell_frames = ov_frames.cell_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2788 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2789
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2790 octave_idx_type num_frames = cell_frames.numel ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2791
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2792 // FIXME: It seems there should be a simple way to concatenate
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2793 // cells...
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2794 Cell retval = Cell (num_frames+1, 1);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2795 retval(0) = m_local_vars;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2796 for (octave_idx_type i = 0; i < num_frames; i++)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2797 retval(i+1) = cell_frames(i);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2798
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2799 return retval;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2800 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2801
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2802 bool is_equal_to (const weak_anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2803 const weak_anonymous_fcn_handle& fh2)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2804 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2805 if (fh1.m_name == fh2.m_name
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2806 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2807 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2808 else
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2809 return false;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2810 }
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2811
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2812 OCTAVE_NAMESPACE_END
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
2813
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2814 octave_fcn_handle::octave_fcn_handle (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2815 : octave_base_value (), m_rep (new octave::invalid_fcn_handle ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2816 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2817
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2818 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2819 : octave_base_value (), m_rep (new octave::internal_fcn_handle (fcn))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2820 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2821
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2822 octave_fcn_handle::octave_fcn_handle (const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2823 : octave_base_value (), m_rep (new octave::simple_fcn_handle (name))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2824 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2825
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2826 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2827 const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2828 : octave_base_value (), m_rep (new octave::simple_fcn_handle (fcn, name))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2829 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2830
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2831 octave_fcn_handle::octave_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2832 const std::string& meth_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2833 : octave_base_value (),
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2834 m_rep (new octave::class_simple_fcn_handle (class_nm, meth_nm))
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2835 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2836
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2837 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2838 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2839 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2840 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2841 m_rep (new octave::class_simple_fcn_handle (fcn, class_nm, meth_nm))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2842 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2843
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2844 octave_fcn_handle::octave_fcn_handle (const octave_value& obj,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2845 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2846 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2847 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2848 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2849 m_rep (new octave::class_simple_fcn_handle (obj, fcn, class_nm, meth_nm))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2850 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2851
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2852 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2853 const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2854 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2855 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2856 m_rep (new octave::scoped_fcn_handle (fcn, name, parentage))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2857 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2858
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2859 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2860 const std::string& name,
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
2861 const std::shared_ptr<octave::stack_frame>& stack_context)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2862 : octave_base_value (),
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
2863 m_rep (new octave::nested_fcn_handle (fcn, name, stack_context))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2864 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2865
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2866 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2867 const octave::stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2868 const std::shared_ptr<octave::stack_frame>& stack_context)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2869 : octave_base_value (),
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2870 m_rep (new octave::anonymous_fcn_handle (fcn, local_vars, stack_context))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2871 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2872
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2873 octave_fcn_handle::octave_fcn_handle (octave::base_fcn_handle *rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2874 : octave_base_value (), m_rep (rep)
28430
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2875 { }
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2876
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2877 octave_fcn_handle::octave_fcn_handle (const octave_fcn_handle& fh)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2878 : octave_base_value (fh)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
2879 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2880 m_rep.reset (fh.m_rep->clone ());
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2881 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2882
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2883 dim_vector
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2884 octave_fcn_handle::dims (void) const
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2885 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2886 static dim_vector dv (1, 1);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2887 return dv;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2888 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2889
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2890 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6695
diff changeset
2891 octave_fcn_handle::save_ascii (std::ostream& os)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2892 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2893 return m_rep->save_ascii (os);
24108
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2894 }
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2895
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2896 bool
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2897 octave_fcn_handle::load_ascii (std::istream& is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2898 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2899 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2900
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2901 // Read enough to detect type then create new rep object and dispatch
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2902 // to finish loading object.
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2903
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2904 std::streampos pos = is.tellg ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2905
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2906 std::string octaveroot = extract_keyword (is, "octaveroot", true);
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21867
diff changeset
2907 if (octaveroot.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2908 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2909 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2910 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2911 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2912
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2913 pos = is.tellg ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2914
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2915 std::string fpath = extract_keyword (is, "path", true);
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21867
diff changeset
2916 if (fpath.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2917 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2918 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2919 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2920 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2921
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2922 if (! (octaveroot.empty () || fpath.empty ()))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2923 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2924 std::size_t len = octaveroot.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2925 if (octaveroot == fpath.substr (0, len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2926 fpath = octave::config::octave_exec_home () + fpath.substr (len);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2927 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2928
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2929 pos = is.tellg ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2930
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2931 std::string subtype = extract_keyword (is, "subtype", true);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2932 if (subtype.empty ())
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2933 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2934 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2935 is.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2936
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2937 // We have a legacy file that can contain either an anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2938 // function or a simple function handle.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2939
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2940 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2941 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2942
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2943 if (name == anonymous)
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2944 new_rep.reset (new octave::anonymous_fcn_handle ());
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
2945 else
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2946 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2947 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2948 else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2949 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2950 // Load individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2951
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2952 if (subtype == "simple")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2953 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2954 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2955 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2956
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2957 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2958 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2959 else if (subtype == "scopedfunction")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2960 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2961 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2962 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2963
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2964 new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2965 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2966 else if (subtype == "anonymous")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2967 new_rep.reset (new octave::anonymous_fcn_handle ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2968 else if (subtype == "nested")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2969 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2970 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2971 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2972
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2973 new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2974 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2975 else if (subtype == "classsimple")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2976 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2977 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2978 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2979
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2980 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2981 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2982 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2983
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2984 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2985 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2986
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2987 if (! new_rep->load_ascii (is))
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2988 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2989
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2990 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2991
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2992 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2993 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2994
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2995 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
2996 octave_fcn_handle::save_binary (std::ostream& os, bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2997 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2998 return m_rep->save_binary (os, save_as_floats);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2999 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3000
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3001 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3002 octave_fcn_handle::load_binary (std::istream& is, bool swap,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
3003 octave::mach_info::float_format fmt)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3004 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3005 // Read enough to detect type then create new rep object and dispatch
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3006 // to finish loading object.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3007
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
3008 int32_t tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
3009 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3010 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3011 if (swap)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3012 swap_bytes<4> (&tmp);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3013
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3014 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1);
12714
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
3015 // is.get (ctmp1, tmp+1, 0); caused is.eof () to be true though
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
3016 // effectively not reading over file end
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
3017 is.read (ctmp1, tmp);
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
3018 ctmp1[tmp] = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3019 std::string name (ctmp1);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3020
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3021 if (! is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3022 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3023
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3024 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3025
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3026 std::size_t anl = anonymous.length ();
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
3027
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3028 if (name.length () >= anl && name.substr (0, anl) == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3029 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3030 // Even with extra info stored in the function name, anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3031 // functions look the same. Note that NAME here may have the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3032 // number of local variables appended. We decode that inside the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3033 // load_binary function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3034
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3035 new_rep.reset (new octave::anonymous_fcn_handle (name));
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3036 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3037 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3038 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3039 // Unpack extra info stored with the function name and load
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3040 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3041 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3042
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3043 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3044 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3045 std::string subtype = "simple";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3046
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3047 if (name.find_first_of ('\n') != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3048 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3049 std::size_t pos1 = name.find_first_of ('\n');
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3050 std::size_t pos2 = name.find_first_of ('\n', pos1 + 1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3051 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3052 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3053 name = name.substr (0, pos1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3054 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3055
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3056 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3057 if (pos1 != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3058 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3059 if (name[pos1+1] == '<')
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3060 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3061 std::size_t pos2 = name.find ('>', pos1 + 2);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3062
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3063 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3064 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3065 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3066
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3067 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3068 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3069
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3070 // Anonymous should have been handled above so it is not in the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3071 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3072
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3073 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3074 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3075 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3076 new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3077 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3078 new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3079 else if (subtype == "classsimple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3080 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3081 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3082
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3083 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3084 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3085
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3086 if (! new_rep->load_binary (is, swap, fmt))
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3087 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3088
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3089 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3090
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3091 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3092 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3093
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3094 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
3095 octave_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3096 bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3097 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3098 return m_rep->save_hdf5 (loc_id, name, save_as_floats);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3099 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3100
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3101 bool
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3102 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name_arg)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3103 {
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
3104 #if defined (HAVE_HDF5)
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
3105
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
3106 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3107 octave_hdf5_id group_hid = H5Gopen (loc_id, name_arg, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
3108 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3109 octave_hdf5_id group_hid = H5Gopen (loc_id, name_arg);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
3110 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3111 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3112 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3113
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
3114 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3115 octave_hdf5_id data_hid = H5Dopen (group_hid, "nm", octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
3116 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3117 octave_hdf5_id data_hid = H5Dopen (group_hid, "nm");
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
3118 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3119
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3120 if (data_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3121 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3122 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3123 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3124 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3125
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3126 octave_hdf5_id type_hid = H5Dget_type (data_hid);
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3127 octave_hdf5_id type_class_hid = H5Tget_class (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3128
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3129 if (type_class_hid != H5T_STRING)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3130 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3131 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3132 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3133 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3134 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3135 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3136
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3137 octave_hdf5_id space_hid = H5Dget_space (data_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3138 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3139
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3140 if (rank != 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3141 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3142 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3143 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3144 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3145 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3146 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3147 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3148
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3149 int slen = H5Tget_size (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3150 if (slen < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3151 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3152 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3153 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3154 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3155 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3156 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3157 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3158
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3159 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3160
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3161 // create datatype for (null-terminated) string to read into:
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3162 octave_hdf5_id st_id = H5Tcopy (H5T_C_S1);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3163 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3164
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3165 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3166 octave_H5P_DEFAULT, nm_tmp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3167 < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3168 {
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3169 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3170 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3171 H5Tclose (type_hid);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3172 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3173 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3174 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3175 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3176 H5Tclose (st_id);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3177 H5Dclose (data_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3178
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3179 std::string name (nm_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3180
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3181 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3182
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3183 if (name == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3184 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3185 // Even with extra info stored in the function name, anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3186 // functions look the same.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3187
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3188 new_rep.reset (new octave::anonymous_fcn_handle ());
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3189 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3190 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3191 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3192 // Unpack extra info stored with the function name and load
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3193 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3194 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3195
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3196 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3197 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3198 std::string subtype = "simple";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3199
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3200 if (name.find_first_of ('\n') != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3201 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3202 std::size_t pos1 = name.find_first_of ('\n');
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3203 std::size_t pos2 = name.find_first_of ('\n', pos1 + 1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3204 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3205 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3206 name = name.substr (0, pos1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3207 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3208
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3209 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3210 if (pos1 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3211 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3212 if (name[pos1+1] == '<')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3213 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3214 std::size_t pos2 = name.find ('>', pos1 + 2);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3215
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3216 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3217 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3218 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3219
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3220 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3221 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3222
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3223 // Anonymous should have been handled above so it is not in the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3224 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3225
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3226 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3227 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3228 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3229 new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3230 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3231 new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3232 else if (subtype == "classsimple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3233 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3234 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3235
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3236 bool status = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3237
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3238 if (new_rep && new_rep->load_hdf5 (group_hid, space_hid, type_hid))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3239 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3240 m_rep = new_rep;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3241 status = true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3242 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3243
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3244 // FIXME: manage these with an unwind_action object?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3245
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3246 H5Tclose (type_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3247 H5Sclose (space_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3248 H5Gclose (group_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3249
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3250 return status;
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
3251
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
3252 #else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3253
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3254 octave_unused_parameter (loc_id);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3255 octave_unused_parameter (name_arg);
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3256
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
3257 warn_load ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3258
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
3259 return false;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3260
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
3261 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3262 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3263
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3264 /*
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3265 %!test <*33857>
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3266 %! a = 2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3267 %! f = @(x) a + x;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3268 %! g = @(x) 2 * x;
11541
28bae9cd7ea9 ov-fcn-handle.cc: use version instead of flops in test
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
3269 %! hm = @version;
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
3270 %! hdld = @svd;
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3271 %! hbi = @log2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3272 %! f2 = f;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3273 %! g2 = g;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3274 %! hm2 = hm;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3275 %! hdld2 = hdld;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3276 %! hbi2 = hbi;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3277 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3278 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3279 %! && __octave_config_info__ ("HAVE_HDF5"))
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3280 %! modes(end+1) = "-hdf5";
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3281 %! endif
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3282 %! for i = 1:numel (modes)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3283 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3284 %! nm = tempname ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3285 %! unwind_protect
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22417
diff changeset
3286 %! f2 (1);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3287 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3288 %! clear f2 g2 hm2 hdld2 hbi2
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3289 %! load (nm);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3290 %! assert (f (2), f2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3291 %! assert (g (2), g2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3292 %! assert (g (3), g2 (3));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3293 %! unlink (nm);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3294 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3295 %! unwind_protect_cleanup
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3296 %! unlink (nm);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3297 %! end_unwind_protect
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3298 %! endfor
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3299 */
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3300
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3301 /*
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3302 %!function fcn_handle_save_recurse (n, mode, nm, f2, g2, hm2, hdld2, hbi2)
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16442
diff changeset
3303 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3304 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3305 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3306 %! fcn_handle_save_recurse (n - 1, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3307 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3308 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3309 %!function [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n, nm)
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16442
diff changeset
3310 %! if (n == 0)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21574
diff changeset
3311 %! load (nm);
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3312 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3313 %! [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n - 1, nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3314 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3315 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3316
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3317 %!test <*35876>
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3318 %! a = 2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3319 %! f = @(x) a + x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3320 %! g = @(x) 2 * x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3321 %! hm = @version;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3322 %! hdld = @svd;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3323 %! hbi = @log2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3324 %! f2 = f;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3325 %! g2 = g;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3326 %! hm2 = hm;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3327 %! hdld2 = hdld;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3328 %! hbi2 = hbi;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3329 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3330 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3331 %! && __octave_config_info__ ("HAVE_HDF5"))
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3332 %! modes(end+1) = "-hdf5";
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3333 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3334 %! for i = 1:numel (modes)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3335 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3336 %! nm = tempname ();
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3337 %! unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3338 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3339 %! clear f2 g2 hm2 hdld2 hbi2
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3340 %! [f2, f2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (2, nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3341 %! load (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3342 %! assert (f (2), f2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3343 %! assert (g (2), g2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3344 %! assert (g (3), g2 (3));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3345 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3346 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3347 %! unwind_protect_cleanup
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3348 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3349 %! end_unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3350 %! endfor
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3351 */
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3352
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3353 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
3354 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3355 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3356 print_raw (os, pr_as_read_syntax);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3357 newline (os);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3358 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3359
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3360 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3361 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3362 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3363 m_rep->print_raw (os, pr_as_read_syntax, current_print_indent_level ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3364 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3365
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3366 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3367 is_equal_to (const octave_fcn_handle& fh1, const octave_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3368 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3369 // FIXME: Maybe there is a better way? Possibly by using typeid or
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3370 // typeindex?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3371
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3372 // Don't include invalid_fcn_handle in the list of types to compare.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3373 // Consider them to be like NaN values so comparisons between any two
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3374 // invalid handles are always false.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3375
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3376 if (fh1.is_internal () && fh2.is_internal ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3377 return is_equal_to (*dynamic_cast<octave::internal_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3378 *dynamic_cast<octave::internal_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3379 else if (fh1.is_simple () && fh2.is_simple ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3380 return is_equal_to (*dynamic_cast<octave::simple_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3381 *dynamic_cast<octave::simple_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3382 else if (fh1.is_scoped () && fh2.is_scoped ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3383 return is_equal_to (*dynamic_cast<octave::scoped_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3384 *dynamic_cast<octave::scoped_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3385 else if (fh1.is_nested () && fh2.is_nested ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3386 return is_equal_to (*dynamic_cast<octave::nested_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3387 *dynamic_cast<octave::nested_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3388 else if (fh1.is_class_simple () && fh2.is_class_simple ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3389 return is_equal_to (*dynamic_cast<octave::class_simple_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3390 *dynamic_cast<octave::class_simple_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3391 else if (fh1.is_anonymous () && fh2.is_anonymous ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3392 return is_equal_to (*dynamic_cast<octave::anonymous_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3393 *dynamic_cast<octave::anonymous_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3394 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3395 return false;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3396 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3397
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3398 OCTAVE_NAMESPACE_BEGIN
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3399
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3400 DEFUN (functions, args, ,
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3401 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3402 @deftypefn {} {@var{s} =} functions (@var{fcn_handle})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3403 Return a structure containing information about the function handle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3404 @var{fcn_handle}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3405
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3406 The structure @var{s} always contains these three fields:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3407
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3408 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3409 @item function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3410 The function name. For an anonymous function (no name) this will be the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3411 actual function definition.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3412
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3413 @item type
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3414 Type of the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3415
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3416 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3417 @item anonymous
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3418 The function is anonymous.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3419
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3420 @item private
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3421 The function is private.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3422
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3423 @item overloaded
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3424 The function overloads an existing function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3425
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3426 @item simple
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3427 The function is a built-in or m-file function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3428
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3429 @item subfunction
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3430 The function is a subfunction within an m-file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3431 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3432
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3433 @item nested
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3434 The function is nested.
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3435
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3436 @item file
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3437 The m-file that will be called to perform the function. This field is empty
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3438 for anonymous and built-in functions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3439 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3440
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3441 In addition, some function types may return more information in additional
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3442 fields.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3443
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3444 @strong{Warning:} @code{functions} is provided for debugging purposes only.
22982
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3445 Its behavior may change in the future and programs should not depend on any
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3446 particular output format.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3447
22982
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3448 @seealso{func2str, str2func}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3449 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3450 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3451 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3452 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3453
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3454 octave_fcn_handle *fh = args(0).xfcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object");
4649
f7ce581b27fb [project @ 2003-11-23 21:46:44 by jwe]
jwe
parents: 4612
diff changeset
3455
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3456 return ovl (fh->info ());
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3457 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3458
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
3459 DEFUN (func2str, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3460 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3461 @deftypefn {} {} func2str (@var{fcn_handle})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3462 Return a string containing the name of the function referenced by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3463 function handle @var{fcn_handle}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3464 @seealso{str2func, functions}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3465 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3466 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3467 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3468 print_usage ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4925
diff changeset
3469
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3470 octave_fcn_handle *fh = args(0).xfcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object");
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3471
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3472 if (! fh)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3473 error ("func2str: FCN_HANDLE must be a valid function handle");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3474
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3475 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3476
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3477 std::string fh_nm = fh->fcn_name ();
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3478
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3479 if (fh->is_anonymous ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3480 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3481 std::ostringstream buf;
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3482
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3483 fh->print_raw (buf);
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3484
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3485 retval = buf.str ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3486 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3487 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3488 retval = fh_nm;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3489
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3490 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3491 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3492
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3493 DEFMETHOD (str2func, interp, args, ,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3494 doc: /* -*- texinfo -*-
26294
3c5863948bb3 doc: grammarcheck C++ and txi files.
Rik <rik@octave.org>
parents: 26119
diff changeset
3495 @deftypefn {} {} str2func (@var{fcn_name})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3496 Return a function handle constructed from the string @var{fcn_name}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3497
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3498 Previous versions of Octave accepted an optional second argument,
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3499 @qcode{"global"}, that caused str2func to ignore locally visible
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3500 functions. This option is no longer supported.
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28430
diff changeset
3501 @seealso{func2str, functions}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3502 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3503 {
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
3504 int nargin = args.length ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3505
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3506 if (nargin < 1 || nargin > 2)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3507 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3508
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3509 std::string nm
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3510 = args(0).xstring_value ("str2func: FCN_NAME must be a string");
20580
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
3511
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3512 if (nm.empty ())
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3513 error ("str2func: invalid function name");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3514
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3515 if (nm[0] == '@')
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3516 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3517 // Unlike the anonymous_fcn_handle::parse method, don't set up
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3518 // temporary scope to use for evaluating the text that defines
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3519 // the anonymous function. Here we want
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3520 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3521 // str2fun ("@(args) expr")
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3522 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3523 // to behave the same as if
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3524 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3525 // @(args) expr
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3526 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3527 // were evaluated in the current scope.
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3528
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3529 int parse_status;
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3530 octave_value afh = interp.eval_string (nm, true, parse_status);
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3531
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3532 if (parse_status == 0)
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3533 return afh;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3534 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3535 else
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3536 {
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3537 if (nargin == 2)
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3538 warning_with_id ("Octave:str2func-global-argument",
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3539 "str2func: second argument ignored");
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3540
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
3541 tree_evaluator& tw = interp.get_evaluator ();
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3542
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3543 return tw.make_fcn_handle (nm);
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3544 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3545
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3546 return ovl ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3547 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3548
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3549 /*
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3550 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3551 %! f = str2func ("<");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3552 %! assert (class (f), "function_handle");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3553 %! assert (func2str (f), "lt");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3554 %! assert (f (1, 2), true);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3555 %! assert (f (2, 1), false);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3556
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3557 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3558 %! f = str2func ("@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3559 %! assert (func2str (f), "@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3560 %! assert (f (0:3), sin (0:3));
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3561
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3562 %!error <FCN_NAME must be a string> str2func ({"sin"})
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3563 */
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3564
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3565 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3566 %!function y = __testrecursionfunc (f, x, n)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3567 %! if (nargin < 3)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3568 %! n = 0;
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3569 %! endif
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3570 %! if (n > 2)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3571 %! y = f (x);
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3572 %! else
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3573 %! n++;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3574 %! y = __testrecursionfunc (@(x) f (2*x), x, n);
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3575 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3576 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3577 %!
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3578 %!assert (__testrecursionfunc (@(x) x, 1), 8)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3579 */
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
3580
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3581 DEFUN (is_function_handle, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3582 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3583 @deftypefn {} {} is_function_handle (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3584 Return true if @var{x} is a function handle.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3585 @seealso{isa, typeinfo, class, functions}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3586 @end deftypefn */)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3587 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20797
diff changeset
3588 if (args.length () != 1)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3589 print_usage ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3590
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3591 return ovl (args(0).is_function_handle ());
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3592 }
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3593
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3594 /*
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 28426
diff changeset
3595 %!shared fh
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3596 %! fh = @(x) x;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3597
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3598 %!assert (is_function_handle (fh))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3599 %!assert (! is_function_handle ({fh}))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3600 %!assert (! is_function_handle (1))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3601
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3602 %!error is_function_handle ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3603 %!error is_function_handle (1, 2)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3604 */
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3605
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3606 /*
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3607 %!test
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3608 %! f = @(t) eval ('2*t');
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3609 %! assert (f (21), 42);
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3610 */
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3611
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3612 /*
28317
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3613 %!test <*58389>
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3614 %! s = "x";
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3615 %! a.(s) = [e, pi];
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3616 %! f = @(x) a.(s)(x);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3617 %! assert (f(1), e);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3618 %! assert (f(2), pi);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3619 %! assert (f([2,1]), [pi, e]);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3620 */
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3621
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3622 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3623 %!function r = __f (g, i)
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3624 %! r = g(i);
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3625 %!endfunction
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3626 %!test
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3627 %! x = [1,2;3,4];
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3628 %! assert (__f (@(i) x(:,i), 1), [1;3]);
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3629 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3630
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3631 OCTAVE_NAMESPACE_END