annotate libinterp/octave-value/ov-fcn-handle.cc @ 30896:c9788d7f6e65

maint: Use "fcn" as preferred abbreviation for "function" in libinterp/. * __eigs__.cc, bsxfun.cc, cellfun.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, error.cc, graphics.cc, graphics.in.h, gzfstream.h, ls-hdf5.cc, lsode.cc, max.cc, oct-opengl.h, quad.cc, strfns.cc, utils.cc, utils.h, variables.cc, __ode15__.cc, gzip.cc, cdef-manager.cc, ov-fcn-handle.cc, ov-java.cc, ov-usr-fcn.cc, bp-table.cc, bp-table.h, lex.h, lex.ll, oct-parse.yy, pt-eval.cc: Replace "func", "fun", "fn" in documentation and variable names with "fcn".
author Rik <rik@octave.org>
date Tue, 05 Apr 2022 08:33:58 -0700
parents 32d2b6604a9f
children a4a010d40459
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 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30006
diff changeset
3 // Copyright (C) 2003-2022 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
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
220 bool save_hdf5 (octave_hdf5_id loc_hid, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
221 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
222
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
223 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
224 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
225
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
226 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
227 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
228
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
229 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
230 const simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
231
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
232 private:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
233
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
234 octave_value m_fcn;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
237 class scoped_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
238 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
239 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
240
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
241 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
242 // 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
243
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
244 scoped_fcn_handle (const std::string& name = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
245 const std::string& file = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
246 const std::string& /*octaveroot*/ = "")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
247 : base_fcn_handle (name, file)
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
250 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
251 const std::list<std::string>& parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
252
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
253 scoped_fcn_handle (const scoped_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
254
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
255 ~scoped_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
256
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
257 scoped_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
258 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
259 return new scoped_fcn_handle (*this);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
262 std::string type (void) const { return "scopedfunction"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
263
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
264 bool is_scoped (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
265
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
266 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
267
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
268 // 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
269 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
270 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
271 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
272 return m_fcn.function_value ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
275 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
276 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
277 return m_fcn.user_function_value ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
280 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
281
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
282 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
283 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
284
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
285 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
286
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
287 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
288
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
289 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
290
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
291 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
292
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
293 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
294 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
295
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
296 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
297 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
298
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
299 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
300 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
301
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
302 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
303 const scoped_fcn_handle& fh2);
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 protected:
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 void find_function (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
308
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
309 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
310 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
311
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
312 // 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
313 // m_fcn.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
314 std::list<std::string> m_parentage;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
315 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
316
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
317 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
318 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
319 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
320
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
321 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
322 // 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
323
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
324 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
325 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
326 const std::string& /*octaveroot*/ = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
327 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
328 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
329
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
330 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
331 : 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
332 { }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
333
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
334 std::string type (void) const { return "nested"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
335
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
336 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
337
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
338 bool is_nested (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
339
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
340 // 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
341 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
342 octave_function * function_value (bool = false)
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 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
345 }
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 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
348 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
349 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
350 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
351
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
352 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
353
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
354 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
355
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
356 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
357 octave_scalar_map info (void);
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 save_ascii (std::ostream& os);
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 load_ascii (std::istream& is);
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 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
364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
365 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
366
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
367 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
368 bool save_as_floats);
28439
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 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
371 octave_hdf5_id& type_hid);
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 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
374 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
375
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
376 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
377
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
378 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
379 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
380 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
381
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
382 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
383 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
384 public:
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 // 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
387 // 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
388
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
389 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
390 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
391 const std::string& octaveroot = "")
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
392 : 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
393 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
394
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
395 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
396 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
397 : 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
398 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
399 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
400 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
401
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
402 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
403
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
404 ~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
405
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
406 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
407
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
408 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
409 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
410 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
411 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
412
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
413 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
414 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
415 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
416 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
417
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
418 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
419
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
420 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
421
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
422 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
423
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
424 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
425 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
426
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
427 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
428 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
429 return m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
430 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
431
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
432 protected:
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
433
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
434 // 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
435 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
436 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
437
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
438 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
439 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
440 public:
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 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
443 : 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
444 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
445
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
446 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
447
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
448 ~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
449
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
450 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
451 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
452 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
453 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
454
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
455 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
456
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
457 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
458
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
459 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
460
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
461 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
462 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
463
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
464 protected:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
465
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
466 // 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
467 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
468 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
469
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
470 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
471 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
472 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
473
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
474 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
475 // 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
476
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
477 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
478 const std::string& file,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
479 const std::string& /*octaveroot*/)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
480 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
481 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
482
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
483 // 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
484 // also contain the object name?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
485
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
486 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
487 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
488
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
489 class_simple_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
490 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
491 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
492
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
493 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
494 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
495 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
496
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
497 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
498
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
499 ~class_simple_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
500
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
501 class_simple_fcn_handle * clone (void) const
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 return new class_simple_fcn_handle (*this);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
506 std::string type (void) const { return "classsimple"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
507
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
508 bool is_class_simple (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
509
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
510 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
511
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
512 // 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
513 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
514 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
515 {
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
516 // 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
517 // call method?
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 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
520 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
521
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
522 symbol_table& symtab
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
523 = __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
524
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
525 // 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
526 // 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
527 // 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
528
29207
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
529 // 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
530 // 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
531 // 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
532 // 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
533 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
534
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
535 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
536 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
537
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
538 octave_user_function * user_function_value (bool = false)
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 return m_fcn.user_function_value ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
543 octave_value fcn_val (void) { return m_fcn; }
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 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
546 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
547
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
548 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
549
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
550 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
551
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
552 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
553
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
554 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
555
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
556 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
557
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
558 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
559 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
560
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
561 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
562 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
563
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
564 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
565 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
566
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
567 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
568 const class_simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
569
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
570 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
572 // The object containing the method we are handing.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
573 octave_value m_obj;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
574
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
575 // The method we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
576 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
577
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
578 // 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
579 std::string m_dispatch_class;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
580 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
581
29541
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
582 // 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
583 // 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
584 // 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
585 // 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
586 // (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
587 // 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
588 // 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
589 // 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
590 // 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
591 // scope where they are created.
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
592 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
593 // 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
594 // 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
595 // 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
596 // 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
597 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
598 // 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
599 // 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
600 // 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
601 // 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
602 // context that contains nested functions?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
603 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
604 // 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
605 // 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
606 // initialization list associated with it?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
607
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
608 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
609 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
610 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
611
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
612 static const std::string anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
613
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
614 // 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
615 // 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
616 // 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
617 // load_binary functions.
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 std::string& name = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
620 : base_fcn_handle (name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
621 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
622
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
623 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
624 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
625 : 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
626 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
627
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
628 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
629
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
630 ~base_anonymous_fcn_handle (void) = default;
28439
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 std::string type (void) const { return "anonymous"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
633
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
634 bool is_anonymous (void) const { return true; }
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 // 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
637 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
638 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
639 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
640 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
641 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
642
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
643 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
644 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
645 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
646 }
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 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
649
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
650 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
651
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
652 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
653 octave_scalar_map info (void);
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_ascii (std::ostream& os);
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_ascii (std::istream& is);
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_binary (std::ostream& os, 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_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
662
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
663 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
664 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
665
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
666 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
667 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
668
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
669 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
670 int current_print_indent_level) const;
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 // Anonymous function handles are printed without a newline.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
673 bool print_as_scalar (void) const { return false; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
674
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
675 bool parse (const std::string& fcn_text);
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 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
678
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
679 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
680 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
681
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
682 // List of captured variable values for anonymous fucntions.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
683 stack_frame::local_vars_map m_local_vars;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
684 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
685
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
686 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
687 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
688 public:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
689
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
690 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
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 // 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
693 // 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
694 // 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
695 // 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
696
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
697 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
698 : 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
701 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
702 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
703 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
704
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
705 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
706
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
707 ~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
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 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
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 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
714 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
715
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
716 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
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 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
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 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
721 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
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 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
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 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
726 }
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 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
729
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
730 // 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
731 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
734 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
735 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
736 public:
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 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
739
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
740 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
741 : 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
744 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
745
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
746 ~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
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 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
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 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
753 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
754
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
755 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
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 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
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 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
760 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
761
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
762 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
763
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
764 // 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
765 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
766 };
28439
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 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
769 const anonymous_fcn_handle& fh2);
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 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
772 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
773 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
774 name.c_str ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
775 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
776
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
777 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
778 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
779 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
780 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
781 type_str.c_str ());
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
782 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
783
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
784 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
785 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
786 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
787 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
788 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
789 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
790
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
791 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
792 base_fcn_handle::subsref (const std::string& type,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
793 const std::list<octave_value_list>& idx,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
794 int nargout)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
795 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
796 octave_value_list retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
797
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
798 switch (type[0])
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
799 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
800 case '(':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
801 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
802 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
803
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
804 retval = call (tmp_nargout, idx.front ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
805 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
806 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
807
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
808 case '{':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
809 case '.':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
810 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
811
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
812 default:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
813 panic_impossible ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
816 // FIXME: perhaps there should be an
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
817 // 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
818 // octave_builtin::subsref.
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 if (idx.size () > 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
821 retval = retval(0).next_subsref (nargout, type, idx);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
822
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
823 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
824 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
825
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
826 octave_value
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
827 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
828 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
829 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
830 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
831 return octave_value (buf.str (), type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
832 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
835 base_fcn_handle::save_ascii (std::ostream&)
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 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
838
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
839 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
840 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
843 base_fcn_handle::load_ascii (std::istream&)
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 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
846
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
847 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
848 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
851 base_fcn_handle::save_binary (std::ostream&, bool)
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 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
854
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
855 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
856 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
859 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
860 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
861 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
862
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
863 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
864 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
867 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
868 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
869 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
870
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
871 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
872 }
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 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
875 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
876 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
877 unimplemented ("load", "hdf5");
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 return true;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
882 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
883 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
884 std::string obj_type = 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 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
887 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
888 "%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
889 obj_type.c_str (), file_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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
892 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
893 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
894 std::string obj_type = 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 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
897 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
898 "%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
899 obj_type.c_str (), file_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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
902 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
903 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
904 std::string htype = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
905
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
906 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
907 op, htype.c_str (), fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
908 }
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 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
911 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
912 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
913 error ("invalid call to invalid function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
914 }
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 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
917 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
918 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
919 interpreter& interp = __get_interpreter__ ("internal_fcn_handle::call");
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 return interp.feval (m_fcn, args, nargout);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
924 octave_scalar_map internal_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
925 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
926 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
927
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
928 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
929 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
930 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
931
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
932 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
933 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
934
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
935 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
936 const internal_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
937 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
938 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
939 && 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
940 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
941 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
942 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
943 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
944
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
945 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
946 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
947 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
948 // 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
949 // 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
950 // make a subsref call using them.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
951
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
952 interpreter& interp = __get_interpreter__ ("simple_fcn_handle::call");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
953
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
954 octave_value fcn_to_call;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
955
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
956 // The following code is similar to part of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
957 // 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
958 // handles a more restricted case.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
959
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
960 symbol_table& symtab = interp.get_symbol_table ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
961
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
962 std::size_t pos = m_name.find ('.');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
963
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
964 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
965 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
966 // 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
967 // 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
968 // created before object is defined as an object.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
969 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
970 // We can have one of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
971 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
972 // pkg-list . fcn (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
973 // pkg-list . cls . meth (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
974 // class-name . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
975 // class-name . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
976 // object . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
977 // object . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
978
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
979 // Evaluate package elements until we find a function,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
980 // 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
981 // 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
982 // 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
983
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
984 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
985 std::size_t end = pos;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
986
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
987 std::vector<std::string> idx_elts;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
988
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
989 while (true)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
990 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
991 end = m_name.find ('.', beg);
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 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
994
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
995 if (end == std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
996 break;
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 beg = end+1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
999 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1000
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
1001 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
1002
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1003 bool have_object = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1004 octave_value partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1005
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1006 // 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
1007 // 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
1008 // there is a definition in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1009
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1010 partial_expr_val = interp.varval (idx_elts[0]);
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 if (partial_expr_val.is_defined ())
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 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
1015 err_invalid_fcn_handle (m_name);
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 have_object = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1018 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1019 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1020 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
1021
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1022 std::string type;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1023 std::list<octave_value_list> arg_list;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1024
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
1025 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
1026 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1027 if (partial_expr_val.is_package ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1028 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1029 if (have_object)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1030 err_invalid_fcn_handle (m_name);
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 type = ".";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1033 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1034
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1035 try
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 // Silently ignore extra output values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1038
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1039 octave_value_list tmp_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1040 = partial_expr_val.subsref (type, arg_list, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1041
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1042 partial_expr_val
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1043 = tmp_list.length () ? tmp_list(0) : octave_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1044
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1045 if (partial_expr_val.is_cs_list ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1046 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1047
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1048 arg_list.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1049 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29063
diff changeset
1050 catch (const index_exception&)
28439
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 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1053 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1054 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1055 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
1056 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1057 // 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
1058 // 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
1059 // final element, it should be a classdef method,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1060 // 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
1061 // function sort that out.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1062
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1063 if (i != n_elts-1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1064 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1065
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1066 type = ".(";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1067 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1068 arg_list.push_back (args);
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 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
1071 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1072 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1073 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1074 }
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 // 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
1077
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1078 if (! partial_expr_val.is_function ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1079 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1080
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1081 fcn_to_call = partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1082 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1083 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
1084 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1085 // 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
1086
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1087 // 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
1088 // 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
1089 // 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
1090
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1091 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
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 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
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 // 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
1096 // 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
1097
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1098 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
1099
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1100 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
1101 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1102 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
1103
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1104 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
1105
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1106 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
1107 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1108 // 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
1109 // 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
1110 // 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
1111
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1112 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
1113 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1114 }
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 else
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 // 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
1119 // 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
1120
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1121 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
1122 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1123 }
28439
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 if (! fcn_to_call.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1126 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1127
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1128 return interp.feval (fcn_to_call, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1129 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1130
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1131 octave_function * simple_fcn_handle::function_value (bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1132 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1133 // 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
1134 // 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
1135
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1136 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1137 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1138
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1139 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1140 = __get_symbol_table__ ("simple_fcn_handle::function_value");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1141
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1142 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1143 // 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
1144 // function handle object is valid.
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 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
1147
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1148 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
1149 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1150
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1151 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
1152 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1153 // 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
1154 // 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
1155
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1156 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1157 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1158
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1159 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1160 = __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
1161
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1162 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1163 // 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
1164 // function handle object is valid.
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 m_fcn = symtab.find_user_function (m_name);
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 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
1169 }
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 octave_value simple_fcn_handle::fcn_val (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1172 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1173 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1174 return m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1175
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1176 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1177 = __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
1178
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1179 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1180 // 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
1181 // function handle object is valid.
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 m_fcn = symtab.find_user_function (m_name);
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 return m_fcn;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1188 octave_scalar_map simple_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1189 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1190 octave_scalar_map m;
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 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1193 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1194 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1195 m.setfield ("file", file ());
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 return m;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1200 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
1201 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1202 os << "# octaveroot: " << config::octave_exec_home () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1203
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1204 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1205 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1206 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1207
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1208 os << "# subtype: " << type () << "\n";
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 os << m_name << "\n";
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 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1213 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1214
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1215 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
1216 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1217 // 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
1218 // 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
1219 // always be deferred until the handle is used?
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 return is.good ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1224 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
1225 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1226 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1227
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1228 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1229 std::string fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1230
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1231 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
1232 << "\n" << fnm;
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 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1235 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1236 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1237 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
1238
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1239 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1240 }
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 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
1243 mach_info::float_format)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1244 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1245 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1246 }
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 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
1249 bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1250 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1251 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1252
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1253 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1254
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1255 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1256 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1257 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
1258 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1259 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1260 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1261 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1262 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1263 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1264
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1265 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
1266 space_hid = data_hid = type_hid = -1;
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 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1269 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1270 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1271 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1272 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1273 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1274 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1275 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1276
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1277 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1278 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1279 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1280 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1281 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1282 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1283 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1284 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1285 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1286 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1287 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1288 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
1289 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1290 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1291 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1292 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
1293 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1294 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1295 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1296 || 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
1297 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1300 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1301 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1302 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1303 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1304 H5Dclose (data_hid);
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 std::string octaveroot = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1307
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1308 // When is FILE defined for simple fucntion handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1309 std::string fpath;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1310
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1311 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1312 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1313 hdims[1] = octaveroot.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1314 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1315 if (space_hid < 0)
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 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1319 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1320 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1321
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1322 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1323 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1324 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
1325 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1326 #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
1327 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
1328 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1329 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1330 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
1331 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1332 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1333
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1334 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1335 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1336 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
1337
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1338 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1339 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1340 else
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1343 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1344 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1345 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1346 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1347
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1348 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1349 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1350 hdims[1] = fpath.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1351 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1352 if (space_hid < 0)
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 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1356 return false;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1359 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1360 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1361 H5Tset_size (type_hid, fpath.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1362
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1363 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1364 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
1365 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1366 #else
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
1367 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
1368 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1369 #endif
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 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1372 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1373 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
1374
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1375 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1376 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1377 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1378 retval = false;
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1381 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1382 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1383
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1384 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1385
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1386 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1387
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1388 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1389 octave_unused_parameter (name);
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 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1392
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1393 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1394
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1395 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1396 }
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 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
1399 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1400 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1401 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1402 #if defined (HAVE_HDF5)
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 unimplemented ("load", "hdf5");
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1407 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1408 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1409
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1410 return true;
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 #else
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1415 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1416 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1417
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1418 return false;
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 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1421 }
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 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
1424 int current_print_indent_level) const
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 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
1427 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1428 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1429
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1430 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
1431 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1432 if (fh1.m_name == fh2.m_name)
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 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
1435 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
1436
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1437 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
1438 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1439 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1440
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1441 return false;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1444 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
1445 const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1446 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1447 : 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
1448 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1449 // 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
1450
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1451 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1452 {
28450
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1453 octave_function *oct_fcn = m_fcn.function_value ();
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1454
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1455 if (oct_fcn)
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1456 m_file = oct_fcn->fcn_file_name ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1457 }
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 m_parentage.push_front (name);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1462 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1463 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
1464 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1465 // 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
1466
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1467 interpreter& interp = __get_interpreter__ ("simple_fcn_handle::call");
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 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1470 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1471 // Try to find it?
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 find_function ();
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 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1477 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1478
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1479 return interp.feval (m_fcn, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1480 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1481
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1482 octave_scalar_map scoped_fcn_handle::info (void)
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 octave_scalar_map m;
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 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1487 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1488 m.setfield ("file", file ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1489
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1490 m.setfield ("parentage", Cell (m_parentage));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1491
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1492 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1493 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1494
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1495 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
1496 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1497 os << "# octaveroot: " << config::octave_exec_home () << "\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 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1500 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1501 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1502
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1503 os << "# subtype: " << type () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1504
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1505 os << m_name << "\n";
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 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1508 tmp.save_ascii (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1509
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1510 return os.good ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1513 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
1514 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1515 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1516 ov_cell.load_ascii (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1517
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1518 if (ov_cell.iscellstr ())
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 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
1521
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1522 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
1523 m_parentage.push_back (cellstr_val(i));
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1526 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1527 }
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 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
1530 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1531 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1532
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1533 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1534
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1535 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
1536 << "\n" << fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1537
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1538 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1539 int32_t len = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1540 os.write (reinterpret_cast<char *> (&len), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1541 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
1542
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1543 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1544 tmp.save_binary (os, save_as_floats);
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 return os.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1547 }
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 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
1550 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1551 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1552 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1553 ov_cell.load_binary (is, swap, fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1554
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1555 if (ov_cell.iscellstr ())
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 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
1558
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1559 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
1560 m_parentage.push_back (cellstr_val(i));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1561 }
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 return is.good ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1566 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
1567 bool)
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 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1570
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1571 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1572
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1573 // FIXME: save parentage.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1574
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1575 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1576 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1577
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1578 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1579
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1580 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1581
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1582 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1583 octave_unused_parameter (name);
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 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1586
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1587 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1588
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1589 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1590 }
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 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
1593 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1594 octave_hdf5_id& type_hid)
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 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1597
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1598 unimplemented ("load", "hdf5");
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 // FIXME: load parentage.
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1603 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1604 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1605
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1606 return true;
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 #else
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1611 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1612 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1613
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1614 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1615
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1616 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1617 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1618
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1619 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
1620 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1621 int current_print_indent_level) const
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 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
1624 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1625 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1626
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1627 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
1628 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1629 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1630 && fh2.m_parentage == fh2.m_parentage
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1631 && 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
1632 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
1633 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1634 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1635 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1636
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1637 void scoped_fcn_handle::find_function (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1638 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1639 // 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
1640 // 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
1641 // 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
1642 // handle is invalid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1643
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1644 symbol_table& symtab
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1645 = __get_symbol_table__ ("scoped_fcn_handle::find_function");
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 (m_parentage.size () == 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1648 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1649 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
1650
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
1651 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
1652
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1653 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1654 dir_name = dir_name.substr (0, pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1655 else if (dir_name == "private")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1656 dir_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 std::string fcn_name = m_parentage.front ();
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 // 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
1661
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1662 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
1663
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1664 // FIXME: Verify that it is a private function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1665 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1666 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1667 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1668 std::string primary_parent_name = m_parentage.back ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1669
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1670 octave_value ov_parent_fcn
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1671 = symtab.find_user_function (primary_parent_name);
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 if (ov_parent_fcn.is_defined ())
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 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
1676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1677 if (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1678 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1679 std::string file_name = fcn->fcn_file_name ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1680
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1681 std::string oct_home = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1682
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1683 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
1684 file_name = file_name.substr (oct_home.size ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1685
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1686 octave_value subfcn = fcn->find_subfunction (m_name);
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1687
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1688 if (subfcn.is_defined ())
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1689 m_fcn = subfcn;
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 }
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 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1694
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1695 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
1696 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1697 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1698
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1699 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1700 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1701 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1702 m.setfield ("workspace", workspace ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1703
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1704 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1705 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1706
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1707 // 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
1708 // 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
1709 // (possibly shared) workspace that was saved.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1710 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1711 // 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
1712 // 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
1713 // 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
1714 // deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1715
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1716 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
1717 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1718 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1719
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1720 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1721
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1722 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1723 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1724
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1725 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
1726 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1727 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1728
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1729 octave_unused_parameter (is);
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 return true;
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
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1734 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
1735 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1736 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1737 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1738
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1739 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1740 octave_unused_parameter (save_as_floats);
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 return true;
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
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1745 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
1746 mach_info::float_format fmt)
28439
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 unimplemented ("load", "binary");
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 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1751 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1752 octave_unused_parameter (fmt);
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 return true;
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
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1757 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
1758 const char *name, bool)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1759 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1760 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1761
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1762 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1763
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1764 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1765 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1766
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1767 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1768
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1769 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1770
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1771 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1772 octave_unused_parameter (name);
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 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1775
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1776 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1777
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1778 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1779 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1780
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1781 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
1782 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
1783 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1784 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1785 #if defined (HAVE_HDF5)
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 unimplemented ("load", "hdf5");
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1790 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1791 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1792
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1793 return true;
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 #else
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1798 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1799 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1800
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1801 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1802
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1803 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1804 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1805
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1806 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
1807 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
1808 int current_print_indent_level) const
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1809 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1810 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
1811 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1812 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1813
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1814 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
1815 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1816 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
1817 (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
1818 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1819
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1820 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1821 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
1822 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1823 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
1824
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1825 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
1826
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1827 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
1828
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1829 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
1830
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1831 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
1832 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1833
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1834 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
1835 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1836 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
1837 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1838
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1839 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
1840 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1841 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1842 && 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
1843 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
1844 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1845 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1846 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1847
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1848 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1849 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
1850 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1851 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
1852
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1853 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
1854
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1855 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
1856
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1857 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
1858
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1859 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
1860
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1861 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
1862 }
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 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
1865 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1866 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
1867
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1868 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
1869 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1870
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1871 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
1872 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
1873 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1874 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
1875 && 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
1876 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
1877 else
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1878 return false;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1879 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1880
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1881 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
1882 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
1883 : 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
1884 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
1885 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1886
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1887 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
1888 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1889 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1890 : 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
1891 m_dispatch_class (class_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1892 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1893
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1894 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
1895 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1896 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1897 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1898 : 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
1899 m_dispatch_class (class_nm)
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1902 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1903 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
1904 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1905 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
1906
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1907 if (m_obj.is_defined ())
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 octave_value_list tmp_args = args;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1910 tmp_args.prepend (m_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1911
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1912 return interp.feval (m_fcn, tmp_args, nargout);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1915 // 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
1916 // dispatch class and restoring that value instead of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1917 // 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
1918 // function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1919
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1920 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1921
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1922 unwind_action act ([&tw] () { tw.set_dispatch_class (""); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1923
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1924 tw.set_dispatch_class (m_dispatch_class);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1925
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1926 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
1927 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
1928
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1929 return interp.feval (fcn_name (), args, nargout);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1930 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1931
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1932 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
1933 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1934 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1935
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1936 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1937 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1938 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1939 m.setfield ("class", dispatch_class ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1940
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1941 return m;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1944 // 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
1945 // 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
1946 // 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
1947 // be deferred until the handle is used?
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 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
1950 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1951 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1952
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1953 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1954
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1955 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1956 }
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 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
1959 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1960 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1961
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1962 octave_unused_parameter (is);
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 return true;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1967 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
1968 bool save_as_floats)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1969 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1970 unimplemented ("save", "binary");
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 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1973 octave_unused_parameter (save_as_floats);
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 return true;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1978 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
1979 mach_info::float_format 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 unimplemented ("load", "binary");
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 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1984 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1985 octave_unused_parameter (fmt);
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 return true;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1990 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
1991 const char *name, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1992 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1993 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1994
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1995 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1996
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1997 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1998 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1999
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2000 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2001
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2002 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2003
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2004 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2005 octave_unused_parameter (name);
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 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2008
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2009 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2010
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2011 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2012 }
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 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
2015 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2016 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2017 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2018 #if defined (HAVE_HDF5)
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 unimplemented ("load", "hdf5");
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2023 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2024 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2025
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2026 return true;
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 #else
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 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2031 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2032 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2033
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2034 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2035
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2036 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2037 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2038
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2039 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
2040 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2041 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2042 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2043 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
2044 current_print_indent_level);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2047 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
2048 const class_simple_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2049 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2050 // 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
2051
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2052 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2053 && 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
2054 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
2055 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2056 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2057 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2058
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2059 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
2060
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2061 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
2062 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2063 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2064
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2065 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2066 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
2067 m.setfield ("function", buf.str ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2068
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2069 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2070 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
2071 m.setfield ("workspace", workspace ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2072 m.setfield ("within_file_path", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2073
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2074 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2075 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2076
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2077 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
2078 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2079 // 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
2080
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2081 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2082 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2083
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2084 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2085
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2086 print_raw (os, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2087 os << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2088
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
2089 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
2090
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2091 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2092 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2093 os << "# length: " << varlen << "\n";
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 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2096 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2097 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
2098 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2099 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2100 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2101
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2102 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2103 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2104
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2105 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
2106 {
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2107 octave::skip_preceeding_newline (is);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2108
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2109 std::string buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2110
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2111 if (is)
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 // 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
2114 // newline in the stream.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2115
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2116 buf = octave::read_until_newline (is, true);
28439
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2119 std::streampos pos = is.tellg ();
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 // 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
2122 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2123
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2124 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
2125 = __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
2126
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2127 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2128
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2129 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
2130 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
2131
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2132 octave_idx_type len = 0;
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 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
2135 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2136 if (len > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2137 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2138 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
2139 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2140 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2141 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2142
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2143 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
2144
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2145 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2146 error ("load: failed to load anonymous function handle");
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 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2149 }
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 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2153 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2154 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2155 is.clear ();
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2158 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2159 return parse (buf);
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 return false;
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
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2164 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
2165 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2166 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2167 // 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
2168
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2169 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2170 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2171
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2172 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2173
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
2174 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
2175
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2176 nmbuf << anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2177 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2178 nmbuf << ' ' << varlen;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2179
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2180 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2181 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2182 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2183 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
2184
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2185 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2186 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2187 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2188 tmp = stmp.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2189 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2190 os.write (stmp.c_str (), stmp.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2191
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2192 if (varlen > 0)
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 for (const auto& nm_val : m_local_vars)
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 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
2197 "", 0, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2198 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2199 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2200 }
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 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2203 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2204
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2205 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
2206 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2207 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2208 // 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
2209 // values in this anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2210
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2211 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
2212 std::size_t anl = anonymous.length ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2213 if (m_name.length () > anl)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2214 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2215 std::istringstream nm_is (m_name.substr (anl));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2216 nm_is >> len;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2217
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2218 // Anonymous functions don't have names. We just used this
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2219 // 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
2220 // variable values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2221
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2222 m_name = "";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2223 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2224
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2225 int32_t tmp;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2226
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2227 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2228 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2229 if (swap)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2230 swap_bytes<4> (&tmp);
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 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2233 // 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
2234 // effectively not reading over file end
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2235 is.read (ctmp2, tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2236 ctmp2[tmp] = 0;
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 // 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
2239 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2240
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2241 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
2242 = __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
2243
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2244 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2245
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2246 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
2247 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
2248
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2249 if (len > 0)
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 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
2252 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2253 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2254 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2255 std::string doc;
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 std::string name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2258 = 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
2259
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2260 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2261 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2262
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2263 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2264 }
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2267 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2268 return parse (ctmp2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2269
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2270 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2271 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2272
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2273 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
2274 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
2275 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2276 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2277 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2278
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2279 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2280
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2281 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2282 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2283 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
2284 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2285 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2286 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2287 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2288 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2289 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2290
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2291 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
2292 space_hid = data_hid = type_hid = -1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2293
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2294 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2295 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2296 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2297 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2298 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2299 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2300 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2301 }
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 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2304 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2305 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2306 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2307 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2308 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2309 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2310 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2311 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2312 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2313 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2314 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
2315 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2316 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2317 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2318 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
2319 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2320 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2321 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2322 || 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
2323 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2324 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2325 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2326 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2327 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2328 return false;
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 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2331
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2332 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2333 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2334 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2335
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2336 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2337 H5Tset_size (type_hid, stmp.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2338 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2339 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2340 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2341 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2342 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2343 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2344
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2345 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2346 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
2347 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2348 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2349 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2350 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
2351 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2352 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2353 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2354 || 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
2355 octave_H5P_DEFAULT, stmp.c_str ()) < 0)
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2358 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2359 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2360 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2361 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2362
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2363 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2364
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
2365 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
2366
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2367 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2368 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2369 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
2370
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2371 if (as_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2372 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2373 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2374 #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
2375 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
2376 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2377
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2378 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2379 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
2380 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2381 #endif
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 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2384 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2385 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
2386
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2387 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2388 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2389 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2390 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2391
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2392 H5Sclose (as_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2393 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2394 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2395 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2396 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2397 data_hid = H5Gcreate (group_hid, "symbol table",
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2398 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2399 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2400 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2401 data_hid = H5Gcreate (group_hid, "symbol table", 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2402 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2403 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2404 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2405 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2406 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2407 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2408 return false;
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 for (const auto& nm_val : m_local_vars)
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 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
2414 "", false, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2415 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2416 }
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 H5Gclose (data_hid);
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2421 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2422 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2423 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2424
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2425 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2426
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2427 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2428
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2429 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2430 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2431 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2432
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2433 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2434
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2435 return false;
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 #endif
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
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2440 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
2441 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
2442 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2443 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2444 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2445
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2446 bool success = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2447
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2448 #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
2449 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
2450 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2451 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
2452 #endif
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 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2455 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2456 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2457 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2458 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2459 return false;
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
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 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
2464 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
2465
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2466 if (type_class_hid != H5T_STRING)
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 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2470 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2471 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2472 return false;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2475 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2476 space_hid = H5Dget_space (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2477 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
2478
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2479 if (rank != 0)
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2482 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2483 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2484 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2485 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2486 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2487
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2488 int slen = H5Tget_size (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2489 if (slen < 0)
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2492 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2493 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2494 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2495 return false;
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
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2498 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2499
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2500 // 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
2501 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
2502 H5Tset_size (st_id, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2503
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2504 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
2505 octave_H5P_DEFAULT, fcn_tmp)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2506 < 0)
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 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2510 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2511 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2512 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2513 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2514 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2515 H5Tclose (st_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2516 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2517
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2518 octave_idx_type len = 0;
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 // 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
2521 // 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
2522 // call H5Aopen for a non-existing attribute
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2523
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2524 H5E_auto_t err_fcn;
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2525 void *err_fcn_data;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2526
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2527 // 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
2528 // reporting function:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2529 #if defined (HAVE_HDF5_18)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2530 H5Eget_auto (octave_H5E_DEFAULT, &err_fcn, &err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2531 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2532 #else
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2533 H5Eget_auto (&err_fcn, &err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2534 H5Eset_auto (nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2535 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2536
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2537 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
2538
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2539 if (attr_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2540 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2541 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
2542 success = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2543
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2544 H5Aclose (attr_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2545 }
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 // restore error reporting:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2548 #if defined (HAVE_HDF5_18)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2549 H5Eset_auto (octave_H5E_DEFAULT, err_fcn, err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2550 #else
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2551 H5Eset_auto (err_fcn, err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2552 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2553
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2554 // 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
2555 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2556
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2557 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
2558 = __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
2559
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2560 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2561
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2562 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
2563 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
2564
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2565 if (len > 0 && success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2566 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2567 hsize_t num_obj = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2568 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2569 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
2570 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2571 data_hid = H5Gopen (group_hid, "symbol table");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2572 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2573 H5Gget_num_objs (data_hid, &num_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2574 H5Gclose (data_hid);
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 (num_obj != static_cast<hsize_t> (len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2577 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2578
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2579 hdf5_callback_data dsub;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2580 int current_item = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2581 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
2582 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2583 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
2584 &dsub) <= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2585 error ("load: failed to load anonymous function handle");
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 m_local_vars[dsub.name] = dsub.tc;
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 }
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 if (success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2592 return parse (fcn_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2593
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2594 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2595
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2596 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2597
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2598 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2599 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2600 octave_unused_parameter (type_hid);
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 return false;
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 #endif
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
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2607 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
2608 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2609 tree_print_code tpc (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 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
2612
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2613 if (! f)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2614 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2615
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2616 os << "@";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2617
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2618 // 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
2619 // 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
2620 // print the parens for us.
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_parameter_list *p = f->parameter_list ();
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 if (p)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2625 p->accept (tpc);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2626
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2627 os << " ";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2628
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2629 tree_statement_list *b = f->body ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2630
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
2631 panic_if (b->length () != 1);
28439
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_statement *s = b->front ();
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 (! s)
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
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
2638 panic_unless (s->is_expression ());
28439
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 tree_expression *e = s->expression ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2641
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2642 if (! e)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2643 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2644
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2645 tpc.print_fcn_handle_body (e);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2646 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2647
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2648 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
2649 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2650 // 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
2651 // 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
2652 // 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
2653 // 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
2654 // 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
2655
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2656 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
2657 = __get_interpreter__ ("base_anonymous_fcn_handle::parse");
28439
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 // 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
2660 // 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
2661 // variables that might be in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2662
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2663 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2664 tw.push_dummy_scope ("read_mat5_binary_element");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2665
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2666 unwind_action act ([&tw] () { tw.pop_scope (); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2667
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2668 int parse_status;
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2669 octave_value anonymous_fcn_hdl
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2670 = interp.eval_string (fcn_text, true, parse_status);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2671
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2672 if (parse_status != 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2673 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2674
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2675 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
2676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2677 if (! fh)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2678 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2679
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2680 m_fcn = fh->fcn_val ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2681
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2682 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
2683
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2684 if (uf)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2685 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2686 symbol_scope uf_scope = uf->scope ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2687
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2688 if (uf_scope)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2689 uf_scope.cache_name (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2690 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2691
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2692 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2693 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2694
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2695 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
2696 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
2697 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
2698 : 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
2699 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
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
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2702 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
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 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
2705 (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
2706 }
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 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
2709 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
2710 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2711 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
2712
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2713 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
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 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
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 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
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 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
2720 }
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 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
2723 {
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_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
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 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
2727 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
2728
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2729 // 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
2730 // 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
2731 // 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
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 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
2734
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2735 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
2736 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2737 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
2738 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
2739 }
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 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
2742 // 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
2743 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
2744 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
2745 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
2746 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
2747
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2748 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
2749 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2750
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2751 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
2752 const anonymous_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2753 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2754 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
2755 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
2756 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2757 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2758 }
29477
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 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
2761 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
2762 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2763 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
2764
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2765 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
2766
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2767 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
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 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
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 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
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 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
2774 }
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 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
2777 {
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_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
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 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
2781 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
2782
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2783 // 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
2784 // 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
2785 // 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
2786
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2787 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
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 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
2790
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2791 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
2792 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2793 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
2794 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
2795 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2796
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2797 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
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 // 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
2800 // cells...
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2801 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
2802 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
2803 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
2804 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
2805
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2806 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
2807 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2808
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2809 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
2810 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
2811 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2812 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
2813 && 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
2814 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
2815 else
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2816 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
2817 }
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2818
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2819 OCTAVE_NAMESPACE_END
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
2820
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2821 octave_fcn_handle::octave_fcn_handle (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2822 : 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
2823 { }
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 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
2826 : 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
2827 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2828
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2829 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
2830 : 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
2831 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2832
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2833 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
2834 const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2835 : 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
2836 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2837
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2838 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
2839 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
2840 : octave_base_value (),
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2841 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
2842 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2843
28439
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& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2845 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2846 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2847 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2848 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
2849 { }
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 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
2852 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2853 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2854 const std::string& meth_nm)
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::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
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,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2861 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2862 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2863 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
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,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2867 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
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 (),
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
2870 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
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 (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
2874 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
2875 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
2876 : 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
2877 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
2878 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2879
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2880 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
2881 : 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
2882 { }
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2883
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2884 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
2885 : octave_base_value (fh)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
2886 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2887 m_rep.reset (fh.m_rep->clone ());
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2888 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2889
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2890 dim_vector
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2891 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
2892 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2893 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
2894 return dv;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2895 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2896
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2897 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6695
diff changeset
2898 octave_fcn_handle::save_ascii (std::ostream& os)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2899 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2900 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
2901 }
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2902
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2903 bool
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2904 octave_fcn_handle::load_ascii (std::istream& is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2905 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2906 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
2907
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2908 // 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
2909 // to finish loading object.
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2910
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2911 std::streampos pos = is.tellg ();
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 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
2914 if (octaveroot.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2915 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2916 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2917 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2918 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2919
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2920 pos = is.tellg ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2921
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2922 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
2923 if (fpath.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2924 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2925 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2926 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2927 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2928
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2929 if (! (octaveroot.empty () || fpath.empty ()))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2930 {
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
2931 std::size_t len = octaveroot.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2932 if (octaveroot == fpath.substr (0, len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2933 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
2934 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2935
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2936 pos = is.tellg ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2937
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2938 std::string subtype = extract_keyword (is, "subtype", true);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2939 if (subtype.empty ())
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2940 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2941 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2942 is.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2943
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2944 // 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
2945 // function or a simple function handle.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2946
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2947 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2948 is >> name;
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 if (name == anonymous)
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2951 new_rep.reset (new octave::anonymous_fcn_handle ());
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
2952 else
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2953 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
2954 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2955 else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2956 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2957 // Load individual function handle types.
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 if (subtype == "simple")
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
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2964 new_rep.reset (new octave::simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2965 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2966 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2967 else if (subtype == "scopedfunction")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2968 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2969 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2970 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2971
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2972 new_rep.reset (new octave::scoped_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2973 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 == "anonymous")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2976 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
2977 else if (subtype == "nested")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2978 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2979 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2980 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2981
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2982 new_rep.reset (new octave::nested_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2983 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2984 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2985 else if (subtype == "classsimple")
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 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2988 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2989
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2990 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2991 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2992 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2993 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2994
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2995 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2996 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2998 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
2999 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3000
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3001 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3002
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3003 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3004 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3005
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3006 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
3007 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
3008 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3009 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
3010 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3011
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3012 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3013 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
3014 octave::mach_info::float_format fmt)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3015 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3016 // 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
3017 // to finish loading object.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3018
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
3019 int32_t tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
3020 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3021 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3022 if (swap)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3023 swap_bytes<4> (&tmp);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3024
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3025 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
3026 // 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
3027 // 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
3028 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
3029 ctmp1[tmp] = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3030 std::string name (ctmp1);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3031
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3032 if (! is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3033 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3034
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3035 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
3036
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
3037 std::size_t anl = anonymous.length ();
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
3038
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3039 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
3040 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3041 // 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
3042 // 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
3043 // 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
3044 // load_binary function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3045
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3046 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
3047 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3048 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3049 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3050 // 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
3051 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3052 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3053
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3054 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3055 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3056 std::string subtype = "simple";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3057
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3058 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
3059 {
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
3060 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
3061 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
3062 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3063 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3064 name = name.substr (0, pos1);
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
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
3067 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3068 if (pos1 != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3069 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3070 if (name[pos1+1] == '<')
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3071 {
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
3072 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
3073
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3074 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3075 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3076 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3077
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3078 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3079 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3080
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3081 // 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
3082 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3083
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3084 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3085 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
3086 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3087 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
3088 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3089 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
3090 else if (subtype == "classsimple")
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3091 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3092 octaveroot));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3093 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3094
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3095 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3096 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3097
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3098 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
3099 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3100
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3101 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3102
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3103 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3104 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3105
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3106 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
3107 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
3108 bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3109 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3110 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
3111 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3112
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3113 bool
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3114 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
3115 {
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
3116 #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
3117
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
3118 #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
3119 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
3120 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3121 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
3122 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3123 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3124 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3125
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
3126 #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
3127 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
3128 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3129 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
3130 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3131
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3132 if (data_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3133 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3134 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3135 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3136 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3137
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3138 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
3139 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
3140
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3141 if (type_class_hid != H5T_STRING)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3142 {
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
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3149 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
3150 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
3151
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3152 if (rank != 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3153 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3154 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3155 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3156 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3157 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3158 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3159 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3160
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3161 int slen = H5Tget_size (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3162 if (slen < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3163 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3164 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3165 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3166 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3167 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3168 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3169 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3170
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3171 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3172
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3173 // 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
3174 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
3175 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3176
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3177 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
3178 octave_H5P_DEFAULT, nm_tmp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3179 < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3180 {
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3181 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3182 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3183 H5Tclose (type_hid);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3184 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3185 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3186 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3187 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3188 H5Tclose (st_id);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3189 H5Dclose (data_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3190
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3191 std::string name (nm_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3192
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3193 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
3194
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3195 if (name == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3196 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3197 // 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
3198 // functions look the same.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3199
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3200 new_rep.reset (new octave::anonymous_fcn_handle ());
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3201 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3202 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3203 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3204 // 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
3205 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3206 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3207
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3208 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3209 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3210 std::string subtype = "simple";
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.find_first_of ('\n') != std::string::npos)
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 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
3215 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
3216 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3217 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3218 name = name.substr (0, pos1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3219 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3220
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
3221 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3222 if (pos1 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3223 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3224 if (name[pos1+1] == '<')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3225 {
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
3226 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
3227
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3228 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3229 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
3230 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3231
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3232 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3233 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3234
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3235 // 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
3236 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3237
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3238 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3239 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
3240 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3241 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
3242 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3243 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
3244 else if (subtype == "classsimple")
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3245 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3246 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3247 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3248
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3249 bool status = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3250
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3251 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
3252 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3253 m_rep = new_rep;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3254 status = true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3255 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3256
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3257 // FIXME: manage these with an unwind_action object?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3258
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3259 H5Tclose (type_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3260 H5Sclose (space_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3261 H5Gclose (group_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3262
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3263 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
3264
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
3265 #else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3266
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3267 octave_unused_parameter (loc_id);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3268 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
3269
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
3270 warn_load ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3271
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
3272 return false;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3273
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
3274 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3275 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3276
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3277 /*
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3278 %!test <*33857>
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3279 %! a = 2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3280 %! f = @(x) a + x;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3281 %! 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
3282 %! hm = @version;
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
3283 %! hdld = @svd;
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3284 %! hbi = @log2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3285 %! f2 = f;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3286 %! g2 = g;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3287 %! hm2 = hm;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3288 %! hdld2 = hdld;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3289 %! hbi2 = hbi;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3290 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3291 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3292 %! && __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
3293 %! modes(end+1) = "-hdf5";
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3294 %! endif
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3295 %! for i = 1:numel (modes)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3296 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3297 %! nm = tempname ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3298 %! unwind_protect
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22417
diff changeset
3299 %! f2 (1);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3300 %! 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
3301 %! clear f2 g2 hm2 hdld2 hbi2
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3302 %! load (nm);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3303 %! assert (f (2), f2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3304 %! assert (g (2), g2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3305 %! assert (g (3), g2 (3));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3306 %! unlink (nm);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3307 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3308 %! unwind_protect_cleanup
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3309 %! unlink (nm);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3310 %! end_unwind_protect
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3311 %! endfor
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3312 */
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3313
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3314 /*
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3315 %!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
3316 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3317 %! 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
3318 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3319 %! 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
3320 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3321 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3322 %!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
3323 %! if (n == 0)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21574
diff changeset
3324 %! load (nm);
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3325 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3326 %! [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
3327 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3328 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3329
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3330 %!test <*35876>
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3331 %! a = 2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3332 %! f = @(x) a + x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3333 %! g = @(x) 2 * x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3334 %! hm = @version;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3335 %! hdld = @svd;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3336 %! hbi = @log2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3337 %! f2 = f;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3338 %! g2 = g;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3339 %! hm2 = hm;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3340 %! hdld2 = hdld;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3341 %! hbi2 = hbi;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3342 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3343 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3344 %! && __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
3345 %! modes(end+1) = "-hdf5";
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3346 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3347 %! for i = 1:numel (modes)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3348 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3349 %! nm = tempname ();
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3350 %! unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3351 %! 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
3352 %! 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
3353 %! [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
3354 %! load (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3355 %! assert (f (2), f2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3356 %! assert (g (2), g2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3357 %! assert (g (3), g2 (3));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3358 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3359 %! 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
3360 %! unwind_protect_cleanup
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3361 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3362 %! end_unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3363 %! endfor
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3364 */
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3365
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3366 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
3367 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
3368 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3369 print_raw (os, pr_as_read_syntax);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3370 newline (os);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3371 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3372
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3373 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3374 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
3375 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3376 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
3377 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3378
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3379 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3380 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
3381 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3382 // 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
3383 // typeindex?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3384
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3385 // 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
3386 // 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
3387 // invalid handles are always false.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3388
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3389 if (fh1.is_internal () && fh2.is_internal ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3390 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
3391 *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
3392 else if (fh1.is_simple () && fh2.is_simple ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3393 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
3394 *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
3395 else if (fh1.is_scoped () && fh2.is_scoped ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3396 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
3397 *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
3398 else if (fh1.is_nested () && fh2.is_nested ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3399 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
3400 *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
3401 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
3402 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
3403 *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
3404 else if (fh1.is_anonymous () && fh2.is_anonymous ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3405 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
3406 *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
3407 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3408 return false;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3409 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3410
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3411 OCTAVE_NAMESPACE_BEGIN
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3412
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3413 DEFUN (functions, args, ,
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3414 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
3415 @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
3416 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
3417 @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
3418
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3419 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
3420
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3421 @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
3422 @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
3423 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
3424 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
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 type
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3427 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
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 @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
3430 @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
3431 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
3432
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3433 @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
3434 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
3435
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 overloaded
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 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
3438
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3439 @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
3440 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
3441
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3442 @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
3443 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
3444 @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
3445
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3446 @item nested
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3447 The function is nested.
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3448
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 @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
3450 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
3451 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
3452 @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
3453
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3454 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
3455 fields.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3456
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3457 @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
3458 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
3459 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
3460
22982
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3461 @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
3462 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3463 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3464 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3465 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3466
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3467 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
3468
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3469 return ovl (fh->info ());
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3470 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3471
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
3472 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
3473 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3474 @deftypefn {} {@var{str} =} func2str (@var{fcn_handle})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3475 Return a string containing the name of the function referenced by the function
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3476 handle @var{fcn_handle}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3477 @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
3478 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3479 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3480 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3481 print_usage ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4925
diff changeset
3482
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3483 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
3484
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3485 if (! fh)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3486 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
3487
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3488 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3489
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3490 std::string fh_nm = fh->fcn_name ();
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3491
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3492 if (fh->is_anonymous ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3493 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3494 std::ostringstream buf;
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3495
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3496 fh->print_raw (buf);
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3497
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3498 retval = buf.str ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3499 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3500 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3501 retval = fh_nm;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3502
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3503 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3504 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3505
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3506 DEFMETHOD (str2func, interp, args, ,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3507 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3508 @deftypefn {} {@var{hfcn} =} str2func (@var{str})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3509 Return a function handle constructed from the string @var{str}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3510
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3511 The input may be the name of a function such as @qcode{"sin"} or a string
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3512 defining a function such as @qcode{"@@(x) sin (x + pi)"}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3513
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3514 Programming Note: In most cases it will be better to use anonymous function
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3515 syntax and let the Octave parser create the function handle rather than use
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3516 @code{str2func}. For example:
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3517
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3518 @example
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3519 @group
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3520 hfcn = @@sin ;
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3521 hfcn = @@(x) sin (x + pi) ;
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3522 @end group
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3523 @end example
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3524
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28430
diff changeset
3525 @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
3526 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3527 {
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
3528 int nargin = args.length ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3529
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3530 if (nargin < 1 || nargin > 2)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3531 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3532
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3533 std::string nm
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3534 = 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
3535
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3536 if (nm.empty ())
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3537 error ("str2func: invalid function name");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3538
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3539 if (nm[0] == '@')
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3540 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3541 // 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
3542 // 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
3543 // 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
3544 //
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3545 // str2func ("@(args) expr")
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3546 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3547 // 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
3548 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3549 // @(args) expr
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3550 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3551 // 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
3552
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3553 int parse_status;
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3554 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
3555
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3556 if (parse_status == 0)
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3557 return afh;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3558 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3559 else
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3560 {
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3561 if (nargin == 2)
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3562 warning_with_id ("Octave:str2func-global-argument",
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3563 "str2func: second argument ignored");
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3564
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
3565 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
3566
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3567 return tw.make_fcn_handle (nm);
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3568 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3569
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3570 return ovl ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3571 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3572
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3573 /*
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3574 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3575 %! f = str2func ("<");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3576 %! assert (class (f), "function_handle");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3577 %! assert (func2str (f), "lt");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3578 %! assert (f (1, 2), true);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3579 %! assert (f (2, 1), false);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3580
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3581 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3582 %! f = str2func ("@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3583 %! assert (func2str (f), "@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3584 %! assert (f (0:3), sin (0:3));
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3585
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3586 %!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
3587 */
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3588
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3589 /*
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3590 %!function y = __testrecursionfcn (f, x, n)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3591 %! if (nargin < 3)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3592 %! n = 0;
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3593 %! endif
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3594 %! if (n > 2)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3595 %! y = f (x);
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3596 %! else
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3597 %! n++;
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3598 %! y = __testrecursionfcn (@(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
3599 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3600 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3601 %!
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3602 %!assert (__testrecursionfcn (@(x) x, 1), 8)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3603 */
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
3604
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3605 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
3606 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
3607 @deftypefn {} {@var{tf} =} is_function_handle (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3608 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
3609 @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
3610 @end deftypefn */)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3611 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20797
diff changeset
3612 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
3613 print_usage ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3614
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3615 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
3616 }
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3617
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3618 /*
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 28426
diff changeset
3619 %!shared fh
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3620 %! fh = @(x) x;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3621
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3622 %!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
3623 %!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
3624 %!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
3625
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3626 %!error is_function_handle ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3627 %!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
3628 */
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3629
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3630 /*
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3631 %!test
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3632 %! f = @(t) eval ('2*t');
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3633 %! assert (f (21), 42);
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3634 */
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3635
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3636 /*
28317
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3637 %!test <*58389>
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3638 %! s = "x";
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3639 %! 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
3640 %! 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
3641 %! 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
3642 %! 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
3643 %! 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
3644 */
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3645
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3646 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3647 %!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
3648 %! r = g(i);
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3649 %!endfunction
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3650 %!test
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3651 %! 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
3652 %! 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
3653 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3654
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3655 OCTAVE_NAMESPACE_END