Mercurial > octave-nkf
annotate src/ov-fcn-handle.cc @ 10321:97b4bd6f0925
partially rewrite function handles
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sat, 13 Feb 2010 08:17:21 +0100 |
parents | 57a59eae83cc |
children | 21551cc88061 |
rev | line source |
---|---|
4343 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 John W. Eaton |
9601
a9b37bae1802
add a couple of missing copyright statements
Jaroslav Hajek <highegg@gmail.com>
parents:
9509
diff
changeset
|
4 Copyright (C) 2009 VZLU Prague, a.s. |
4343 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
4343 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
4343 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include <iostream> | |
5765 | 29 #include <sstream> |
5164 | 30 #include <vector> |
4343 | 31 |
7336 | 32 #include "file-ops.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
8021
diff
changeset
|
33 #include "oct-locbuf.h" |
7336 | 34 |
4343 | 35 #include "defun.h" |
4654 | 36 #include "error.h" |
37 #include "gripes.h" | |
5663 | 38 #include "input.h" |
4343 | 39 #include "oct-map.h" |
40 #include "ov-base.h" | |
41 #include "ov-fcn-handle.h" | |
4980 | 42 #include "ov-usr-fcn.h" |
4343 | 43 #include "pr-output.h" |
4980 | 44 #include "pt-pr-code.h" |
45 #include "pt-misc.h" | |
46 #include "pt-stmt.h" | |
47 #include "pt-cmd.h" | |
48 #include "pt-exp.h" | |
49 #include "pt-assign.h" | |
4343 | 50 #include "variables.h" |
4988 | 51 #include "parse.h" |
6625 | 52 #include "unwind-prot.h" |
53 #include "defaults.h" | |
54 #include "file-stat.h" | |
55 #include "load-path.h" | |
56 #include "oct-env.h" | |
4988 | 57 |
58 #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
|
59 #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
|
60 #include "ls-hdf5.h" |
4988 | 61 #include "ls-oct-ascii.h" |
6625 | 62 #include "ls-oct-binary.h" |
4988 | 63 #include "ls-utils.h" |
4343 | 64 |
65 DEFINE_OCTAVE_ALLOCATOR (octave_fcn_handle); | |
66 | |
4612 | 67 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
|
68 "function handle", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
69 "function_handle"); |
4343 | 70 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
71 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
|
72 |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
73 octave_fcn_handle::octave_fcn_handle (const octave_value& f, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
74 const std::string& n) |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
75 : fcn (f), nm (n), has_overloads (false) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
76 { |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
77 octave_user_function *uf = fcn.user_function_value (true); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
78 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
79 if (uf && nm != anonymous) |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
80 symbol_table::cache_name (uf->scope (), nm); |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
81 } |
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
82 |
4924 | 83 octave_value_list |
84 octave_fcn_handle::subsref (const std::string& type, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
85 const std::list<octave_value_list>& idx, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
86 int nargout) |
4924 | 87 { |
88 octave_value_list retval; | |
89 | |
90 switch (type[0]) | |
91 { | |
92 case '(': | |
93 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
94 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout; |
5663 | 95 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
96 retval = do_multi_index_op (tmp_nargout, idx.front ()); |
4924 | 97 } |
98 break; | |
99 | |
100 case '{': | |
101 case '.': | |
102 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
103 std::string tnm = type_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
104 error ("%s cannot be indexed with %c", tnm.c_str (), type[0]); |
4924 | 105 } |
106 break; | |
107 | |
108 default: | |
109 panic_impossible (); | |
110 } | |
111 | |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
112 // FIXME -- perhaps there should be an |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
113 // octave_value_list::next_subsref member function? See also |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
114 // octave_builtin::subsref. |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
115 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
116 if (idx.size () > 1) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
117 retval = retval(0).next_subsref (nargout, type, idx); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
118 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
119 return retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
120 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
121 |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
122 octave_value_list |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
123 octave_fcn_handle::do_multi_index_op (int nargout, |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
124 const octave_value_list& args) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
125 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
126 octave_value_list retval; |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
127 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
128 out_of_date_check (fcn, std::string (), false); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
129 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
130 if (has_overloads) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
131 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
132 // Possibly overloaded function. |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
133 octave_value ov_fcn; |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
134 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
135 // Compute dispatch type. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
136 builtin_type_t btyp; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
137 std::string dispatch_type = get_dispatch_type (args, btyp); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
138 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
139 // Retrieve overload. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
140 if (btyp != btyp_unknown) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
141 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
142 out_of_date_check (builtin_overloads[btyp], dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
143 ov_fcn = builtin_overloads[btyp]; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
144 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
145 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
146 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
147 str_ov_map::iterator it = overloads.find (dispatch_type); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
148 if (it != overloads.end ()) |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
149 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
150 out_of_date_check (it->second, dispatch_type, false); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
151 ov_fcn = it->second; |
9466
2ebd0717c12d
also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9463
diff
changeset
|
152 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
153 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
154 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
155 if (ov_fcn.is_defined ()) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
156 retval = ov_fcn.do_multi_index_op (nargout, args); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
157 else if (fcn.is_defined ()) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
158 retval = fcn.do_multi_index_op (nargout, args); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
159 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
160 error ("%s: no method for class %s", nm.c_str (), dispatch_type.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
161 } |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
162 else |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
163 { |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
164 // Non-overloaded function (anonymous, subfunction, private function). |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
165 if (fcn.is_defined ()) |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
166 retval = fcn.do_multi_index_op (nargout, args); |
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
167 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
168 error ("%s: no longer valid function handle", nm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
169 } |
4924 | 170 |
171 return retval; | |
172 } | |
173 | |
4988 | 174 bool |
6625 | 175 octave_fcn_handle::set_fcn (const std::string &octaveroot, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
176 const std::string& fpath) |
4988 | 177 { |
6625 | 178 bool success = true; |
179 | |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
180 if (octaveroot.length () != 0 |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
181 && fpath.length () >= octaveroot.length () |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
182 && fpath.substr (0, octaveroot.length ()) == octaveroot |
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
183 && OCTAVE_EXEC_PREFIX != octaveroot) |
6625 | 184 { |
185 // First check if just replacing matlabroot is enough | |
186 std::string str = OCTAVE_EXEC_PREFIX + | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
187 fpath.substr (octaveroot.length ()); |
6625 | 188 file_stat fs (str); |
189 | |
190 if (fs.exists ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
191 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
192 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 193 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
194 std::string dir_name = str.substr (0, xpos); |
6625 | 195 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
196 octave_function *xfcn |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
197 = load_fcn_from_file (str, dir_name, "", nm); |
6625 | 198 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
199 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
201 octave_value tmp (xfcn); |
6625 | 202 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
203 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
204 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
205 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
206 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
207 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
208 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
209 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
210 } |
6625 | 211 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
212 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
213 // Next just search for it anywhere in the system path |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
214 string_vector names(3); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
215 names(0) = nm + ".oct"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
216 names(1) = nm + ".mex"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
217 names(2) = nm + ".m"; |
6625 | 218 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
219 dir_path p (load_path::system_path ()); |
6625 | 220 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
221 str = octave_env::make_absolute (p.find_first_of (names)); |
6625 | 222 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
223 size_t xpos = str.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 224 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
225 std::string dir_name = str.substr (0, xpos); |
7336 | 226 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
227 octave_function *xfcn = load_fcn_from_file (str, dir_name, "", nm); |
4989 | 228 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
229 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
230 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
231 octave_value tmp (xfcn); |
6625 | 232 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
233 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
234 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
235 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
236 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
237 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
238 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
239 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
240 } |
6625 | 241 } |
242 else | |
243 { | |
244 if (fpath.length () > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
245 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
246 size_t xpos = fpath.find_last_of (file_ops::dir_sep_chars ()); |
6625 | 247 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
248 std::string dir_name = fpath.substr (0, xpos); |
7336 | 249 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
250 octave_function *xfcn = load_fcn_from_file (fpath, dir_name, "", nm); |
6625 | 251 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
252 if (xfcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
253 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
254 octave_value tmp (xfcn); |
6625 | 255 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
256 fcn = octave_value (new octave_fcn_handle (tmp, nm)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
257 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
258 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
259 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
260 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
261 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
262 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
263 } |
6625 | 264 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
265 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
266 fcn = symbol_table::find_function (nm); |
7336 | 267 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
268 if (! fcn.is_function ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
269 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
270 error ("function handle points to non-existent function"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
271 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
272 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
273 } |
6625 | 274 } |
275 | |
276 return success; | |
277 } | |
278 | |
279 bool | |
6974 | 280 octave_fcn_handle::save_ascii (std::ostream& os) |
6625 | 281 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
282 if (nm == anonymous) |
4988 | 283 { |
6625 | 284 os << nm << "\n"; |
285 | |
4989 | 286 print_raw (os, true); |
287 os << "\n"; | |
6625 | 288 |
7336 | 289 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
290 return false; |
6625 | 291 |
292 octave_user_function *f = fcn.user_function_value (); | |
293 | |
7336 | 294 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
295 = symbol_table::all_variables (f->scope (), 0); |
6625 | 296 |
7336 | 297 size_t varlen = vars.size (); |
6625 | 298 |
299 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
300 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
301 os << "# length: " << varlen << "\n"; |
6625 | 302 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
303 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
304 p != vars.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
305 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
306 if (! save_ascii_data (os, p->varval (), p->name (), false, 0)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
307 return os; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
308 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
309 } |
6625 | 310 } |
311 else | |
312 { | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
313 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
314 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
315 |
6625 | 316 os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n"; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
317 if (! fnm.empty ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
318 os << "# path: " << fnm << "\n"; |
6625 | 319 os << nm << "\n"; |
4988 | 320 } |
321 | |
322 return true; | |
323 } | |
324 | |
325 bool | |
326 octave_fcn_handle::load_ascii (std::istream& is) | |
327 { | |
6625 | 328 bool success = true; |
329 | |
330 std::streampos pos = is.tellg (); | |
331 std::string octaveroot = extract_keyword (is, "octaveroot", true); | |
332 if (octaveroot.length() == 0) | |
333 { | |
334 is.seekg (pos); | |
335 is.clear (); | |
336 } | |
337 pos = is.tellg (); | |
338 std::string fpath = extract_keyword (is, "path", true); | |
339 if (fpath.length() == 0) | |
340 { | |
341 is.seekg (pos); | |
342 is.clear (); | |
343 } | |
344 | |
4988 | 345 is >> nm; |
4989 | 346 |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
347 if (nm == anonymous) |
4988 | 348 { |
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
|
349 skip_preceeding_newline (is); |
4988 | 350 |
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
|
351 std::string buf; |
4988 | 352 |
353 if (is) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
354 { |
4988 | 355 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
356 // Get a line of text whitespace characters included, leaving |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
357 // newline in the stream. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
358 buf = read_until_newline (is, true); |
4989 | 359 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
360 } |
4988 | 361 |
6625 | 362 pos = is.tellg (); |
7336 | 363 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
364 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
365 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
366 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
367 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
368 |
7336 | 369 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
370 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
371 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
372 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
373 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
374 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
375 frame.add_fcn (octave_call_stack::pop); |
4988 | 376 |
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
|
377 octave_idx_type len = 0; |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
378 |
6625 | 379 if (extract_keyword (is, "length", len, true) && len >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
380 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
381 if (len > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
382 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
383 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
384 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
385 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
386 bool dummy; |
6625 | 387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
388 std::string name |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
389 = read_ascii_data (is, std::string (), dummy, t2, i); |
6625 | 390 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
391 if (!is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
392 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
393 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
394 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
395 } |
6625 | 396 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
397 symbol_table::varref (name, local_scope, 0) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
398 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
399 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
400 } |
4989 | 401 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
402 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
403 is.seekg (pos); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
404 is.clear (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
405 } |
6625 | 406 |
407 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
408 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
409 int parse_status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
410 octave_value anon_fcn_handle = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
411 eval_string (buf, true, parse_status); |
6625 | 412 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
413 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
414 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
415 octave_fcn_handle *fh = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
416 anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
418 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
419 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
420 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
421 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
422 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
423 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
424 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
425 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
426 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
427 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
428 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
429 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
430 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
431 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
432 } |
6625 | 433 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
434 success = false; |
4988 | 435 } |
436 else | |
6625 | 437 success = set_fcn (octaveroot, fpath); |
4988 | 438 |
6625 | 439 return success; |
4988 | 440 } |
441 | |
442 bool | |
6625 | 443 octave_fcn_handle::save_binary (std::ostream& os, bool& save_as_floats) |
4988 | 444 { |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
445 if (nm == anonymous) |
4988 | 446 { |
6625 | 447 std::ostringstream nmbuf; |
448 | |
7336 | 449 if (fcn.is_undefined ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
450 return false; |
6625 | 451 |
452 octave_user_function *f = fcn.user_function_value (); | |
453 | |
7336 | 454 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
455 = symbol_table::all_variables (f->scope (), 0); |
6625 | 456 |
7336 | 457 size_t varlen = vars.size (); |
6625 | 458 |
459 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
460 nmbuf << nm << " " << varlen; |
6625 | 461 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
462 nmbuf << nm; |
6625 | 463 |
464 std::string buf_str = nmbuf.str(); | |
465 int32_t tmp = buf_str.length (); | |
466 os.write (reinterpret_cast<char *> (&tmp), 4); | |
467 os.write (buf_str.c_str (), buf_str.length ()); | |
468 | |
5765 | 469 std::ostringstream buf; |
4988 | 470 print_raw (buf, true); |
5765 | 471 std::string stmp = buf.str (); |
4988 | 472 tmp = stmp.length (); |
5760 | 473 os.write (reinterpret_cast<char *> (&tmp), 4); |
4988 | 474 os.write (stmp.c_str (), stmp.length ()); |
6625 | 475 |
476 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
477 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
478 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
479 p != vars.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
480 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
481 if (! save_binary_data (os, p->varval (), p->name (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
482 "", 0, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
483 return os; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
484 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
485 } |
6625 | 486 } |
487 else | |
488 { | |
489 std::ostringstream nmbuf; | |
490 | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
491 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
492 std::string fnm = f ? f->fcn_file_name () : std::string (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
493 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
494 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm; |
6625 | 495 |
496 std::string buf_str = nmbuf.str (); | |
497 int32_t tmp = buf_str.length (); | |
498 os.write (reinterpret_cast<char *> (&tmp), 4); | |
499 os.write (buf_str.c_str (), buf_str.length ()); | |
4988 | 500 } |
7336 | 501 |
4988 | 502 return true; |
503 } | |
504 | |
505 bool | |
506 octave_fcn_handle::load_binary (std::istream& is, bool swap, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
507 oct_mach_info::float_format fmt) |
4988 | 508 { |
6625 | 509 bool success = true; |
7336 | 510 |
5828 | 511 int32_t tmp; |
5760 | 512 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
4988 | 513 return false; |
514 if (swap) | |
515 swap_bytes<4> (&tmp); | |
516 | |
517 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); | |
8378
7d0492aa522d
fix use of uninitialized buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
518 is.get (ctmp1, tmp+1, 0); |
4988 | 519 nm = std::string (ctmp1); |
520 | |
521 if (! is) | |
522 return false; | |
523 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
524 size_t anl = anonymous.length (); |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
525 |
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
526 if (nm.length() >= anl && nm.substr (0, anl) == anonymous) |
4988 | 527 { |
6625 | 528 octave_idx_type len = 0; |
529 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
530 if (nm.length() > anl) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
531 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
532 std::istringstream nm_is (nm.substr (anl)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
533 nm_is >> len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
534 nm = nm.substr (0, anl); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
535 } |
6625 | 536 |
5760 | 537 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
538 return false; |
4988 | 539 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
540 swap_bytes<4> (&tmp); |
4988 | 541 |
542 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); | |
8378
7d0492aa522d
fix use of uninitialized buffers
Jaroslav Hajek <highegg@gmail.com>
parents:
8377
diff
changeset
|
543 is.get (ctmp2, tmp+1, 0); |
4988 | 544 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
545 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
546 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
547 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
548 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
549 |
7336 | 550 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
551 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
552 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
553 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
554 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
555 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
556 frame.add_fcn (octave_call_stack::pop); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
557 |
6625 | 558 if (len > 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
559 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
560 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
561 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
562 octave_value t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
563 bool dummy; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
564 std::string doc; |
6625 | 565 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
566 std::string name = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
567 read_binary_data (is, swap, fmt, std::string (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
568 dummy, t2, doc); |
6625 | 569 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
570 if (!is) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
571 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
572 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
573 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
574 } |
6625 | 575 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
576 symbol_table::varref (name, local_scope) = t2; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
577 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
578 } |
6625 | 579 |
580 if (is && success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
581 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
582 int parse_status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
583 octave_value anon_fcn_handle = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
584 eval_string (ctmp2, true, parse_status); |
6625 | 585 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
586 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
587 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
588 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
589 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
590 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
591 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
592 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
593 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
594 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
595 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
596 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
597 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
598 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
599 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
600 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
601 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
602 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
603 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
604 } |
4988 | 605 } |
606 else | |
607 { | |
6625 | 608 std::string octaveroot; |
609 std::string fpath; | |
610 | |
8021 | 611 if (nm.find_first_of ("\n") != std::string::npos) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
612 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
613 size_t pos1 = nm.find_first_of ("\n"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
614 size_t pos2 = nm.find_first_of ("\n", pos1 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
615 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
616 fpath = nm.substr (pos2 + 1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
617 nm = nm.substr (0, pos1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
618 } |
6625 | 619 |
620 success = set_fcn (octaveroot, fpath); | |
621 } | |
622 | |
623 return success; | |
4988 | 624 } |
625 | |
626 #if defined (HAVE_HDF5) | |
627 bool | |
628 octave_fcn_handle::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
629 bool save_as_floats) |
4988 | 630 { |
7336 | 631 bool retval = true; |
632 | |
4988 | 633 hid_t group_hid = -1; |
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
|
634 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
635 group_hid = H5Gcreate (loc_id, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
636 #else |
4988 | 637 group_hid = H5Gcreate (loc_id, name, 0); |
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
|
638 #endif |
7336 | 639 if (group_hid < 0) |
640 return false; | |
4988 | 641 |
642 hid_t space_hid = -1, data_hid = -1, type_hid = -1;; | |
643 | |
644 // attach the type of the variable | |
645 type_hid = H5Tcopy (H5T_C_S1); | |
646 H5Tset_size (type_hid, nm.length () + 1); | |
647 if (type_hid < 0) | |
648 { | |
649 H5Gclose (group_hid); | |
650 return false; | |
651 } | |
652 | |
653 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2); | |
654 hdims[0] = 0; | |
655 hdims[1] = 0; | |
5760 | 656 space_hid = H5Screate_simple (0 , hdims, 0); |
4988 | 657 if (space_hid < 0) |
658 { | |
659 H5Tclose (type_hid); | |
660 H5Gclose (group_hid); | |
661 return false; | |
662 } | |
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
|
663 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
664 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
665 H5P_DEFAULT, H5P_DEFAULT, 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
|
666 #else |
4988 | 667 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid, 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
|
668 #endif |
4988 | 669 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
670 H5P_DEFAULT, nm.c_str ()) < 0) |
4988 | 671 { |
672 H5Sclose (space_hid); | |
673 H5Tclose (type_hid); | |
674 H5Gclose (group_hid); | |
675 return false; | |
676 } | |
677 H5Dclose (data_hid); | |
678 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
679 if (nm == anonymous) |
4988 | 680 { |
5765 | 681 std::ostringstream buf; |
4988 | 682 print_raw (buf, true); |
5765 | 683 std::string stmp = buf.str (); |
4988 | 684 |
685 // attach the type of the variable | |
686 H5Tset_size (type_hid, stmp.length () + 1); | |
687 if (type_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
688 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
689 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
690 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
691 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
692 } |
4988 | 693 |
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
|
694 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
695 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
696 H5P_DEFAULT, H5P_DEFAULT, 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
|
697 #else |
4988 | 698 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
699 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
|
700 #endif |
4988 | 701 if (data_hid < 0 || H5Dwrite (data_hid, type_hid, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
702 H5P_DEFAULT, stmp.c_str ()) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
703 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
704 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
705 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
706 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
707 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
708 } |
4988 | 709 |
710 H5Dclose (data_hid); | |
6625 | 711 |
712 octave_user_function *f = fcn.user_function_value (); | |
713 | |
7336 | 714 std::list<symbol_table::symbol_record> vars |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
715 = symbol_table::all_variables (f->scope (), 0); |
7336 | 716 |
717 size_t varlen = vars.size (); | |
6625 | 718 |
719 if (varlen > 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
720 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
721 hid_t as_id = H5Screate (H5S_SCALAR); |
6625 | 722 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
723 if (as_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
724 { |
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
|
725 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
726 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
727 H5T_NATIVE_IDX, as_id, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
728 H5P_DEFAULT, 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
|
729 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
730 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
731 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
732 H5T_NATIVE_IDX, as_id, 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
|
733 #endif |
6625 | 734 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
735 if (a_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
736 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
737 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0); |
6625 | 738 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
739 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
740 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
741 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
742 retval = false; |
6625 | 743 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
744 H5Sclose (as_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
745 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
746 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
747 retval = false; |
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
|
748 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
749 data_hid = H5Gcreate (group_hid, "symbol table", H5P_DEFAULT, H5P_DEFAULT, 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
|
750 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
751 data_hid = H5Gcreate (group_hid, "symbol table", 0); |
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
|
752 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
753 if (data_hid < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
754 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
755 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
756 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
757 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
758 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
759 } |
6625 | 760 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
761 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
762 p != vars.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
763 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
764 if (! add_hdf5_data (data_hid, p->varval (), p->name (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
765 "", false, save_as_floats)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
766 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
767 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
768 H5Gclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
769 } |
6625 | 770 } |
771 else | |
772 { | |
773 std::string octaveroot = OCTAVE_EXEC_PREFIX; | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
774 |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
775 octave_function *f = function_value (); |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
776 std::string fpath = f ? f->fcn_file_name () : std::string (); |
6625 | 777 |
778 H5Sclose (space_hid); | |
779 hdims[0] = 1; | |
780 hdims[1] = octaveroot.length (); | |
781 space_hid = H5Screate_simple (0 , hdims, 0); | |
782 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
783 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
784 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
785 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
786 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
787 } |
6625 | 788 |
789 H5Tclose (type_hid); | |
790 type_hid = H5Tcopy (H5T_C_S1); | |
791 H5Tset_size (type_hid, octaveroot.length () + 1); | |
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
|
792 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
793 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
794 type_hid, space_hid, H5P_DEFAULT, 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
|
795 #else |
6625 | 796 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT", |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
797 type_hid, space_hid, 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
|
798 #endif |
6625 | 799 |
800 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
801 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
802 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0); |
6625 | 803 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
804 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
805 } |
6625 | 806 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
807 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
808 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
809 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
810 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
811 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
812 } |
6625 | 813 |
814 H5Sclose (space_hid); | |
815 hdims[0] = 1; | |
816 hdims[1] = fpath.length (); | |
817 space_hid = H5Screate_simple (0 , hdims, 0); | |
818 if (space_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
819 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
820 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
821 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
822 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
823 } |
6625 | 824 |
825 H5Tclose (type_hid); | |
826 type_hid = H5Tcopy (H5T_C_S1); | |
827 H5Tset_size (type_hid, fpath.length () + 1); | |
828 | |
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
|
829 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
830 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
831 H5P_DEFAULT, 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
|
832 #else |
6625 | 833 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, 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
|
834 #endif |
6625 | 835 |
836 if (a_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
837 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
838 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0); |
6625 | 839 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
840 H5Aclose (a_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
841 } |
6625 | 842 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
843 retval = false; |
4988 | 844 } |
845 | |
846 H5Sclose (space_hid); | |
847 H5Tclose (type_hid); | |
848 H5Gclose (group_hid); | |
849 | |
850 return retval; | |
851 } | |
852 | |
853 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9601
diff
changeset
|
854 octave_fcn_handle::load_hdf5 (hid_t loc_id, const char *name) |
4988 | 855 { |
7336 | 856 bool success = true; |
857 | |
4988 | 858 hid_t group_hid, data_hid, space_hid, type_hid, type_class_hid, st_id; |
859 hsize_t rank; | |
860 int slen; | |
861 | |
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
|
862 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
863 group_hid = H5Gopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
864 #else |
4988 | 865 group_hid = H5Gopen (loc_id, name); |
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
|
866 #endif |
7336 | 867 if (group_hid < 0) |
868 return false; | |
4988 | 869 |
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
|
870 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
871 data_hid = H5Dopen (group_hid, "nm", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
872 #else |
4988 | 873 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
|
874 #endif |
4988 | 875 |
876 if (data_hid < 0) | |
877 { | |
878 H5Gclose (group_hid); | |
879 return false; | |
880 } | |
881 | |
882 type_hid = H5Dget_type (data_hid); | |
883 type_class_hid = H5Tget_class (type_hid); | |
884 | |
885 if (type_class_hid != H5T_STRING) | |
886 { | |
887 H5Tclose (type_hid); | |
888 H5Dclose (data_hid); | |
889 H5Gclose (group_hid); | |
890 return false; | |
891 } | |
892 | |
893 space_hid = H5Dget_space (data_hid); | |
894 rank = H5Sget_simple_extent_ndims (space_hid); | |
895 | |
896 if (rank != 0) | |
897 { | |
898 H5Sclose (space_hid); | |
899 H5Tclose (type_hid); | |
900 H5Dclose (data_hid); | |
901 H5Gclose (group_hid); | |
902 return false; | |
903 } | |
904 | |
905 slen = H5Tget_size (type_hid); | |
906 if (slen < 0) | |
907 { | |
908 H5Sclose (space_hid); | |
909 H5Tclose (type_hid); | |
910 H5Dclose (data_hid); | |
911 H5Gclose (group_hid); | |
912 return false; | |
913 } | |
914 | |
915 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen); | |
916 | |
917 // create datatype for (null-terminated) string to read into: | |
918 st_id = H5Tcopy (H5T_C_S1); | |
919 H5Tset_size (st_id, slen); | |
920 | |
5760 | 921 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, nm_tmp) < 0) |
4988 | 922 { |
6695 | 923 H5Tclose (st_id); |
4988 | 924 H5Sclose (space_hid); |
925 H5Tclose (type_hid); | |
6695 | 926 H5Dclose (data_hid); |
4988 | 927 H5Gclose (group_hid); |
928 return false; | |
929 } | |
930 H5Tclose (st_id); | |
931 H5Dclose (data_hid); | |
932 nm = nm_tmp; | |
933 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
934 if (nm == anonymous) |
4988 | 935 { |
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
|
936 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
937 data_hid = H5Dopen (group_hid, "fcn", H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
938 #else |
4988 | 939 data_hid = H5Dopen (group_hid, "fcn"); |
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
|
940 #endif |
4988 | 941 |
942 if (data_hid < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
943 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
944 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
945 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
946 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
947 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
948 } |
4988 | 949 |
6695 | 950 H5Tclose (type_hid); |
4988 | 951 type_hid = H5Dget_type (data_hid); |
952 type_class_hid = H5Tget_class (type_hid); | |
953 | |
954 if (type_class_hid != H5T_STRING) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
955 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
956 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
957 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
958 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
959 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
960 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
961 } |
4988 | 962 |
6695 | 963 H5Sclose (space_hid); |
4988 | 964 space_hid = H5Dget_space (data_hid); |
965 rank = H5Sget_simple_extent_ndims (space_hid); | |
966 | |
967 if (rank != 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
968 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
969 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
970 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
971 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
972 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
973 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
974 } |
4988 | 975 |
976 slen = H5Tget_size (type_hid); | |
977 if (slen < 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
978 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
979 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
980 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
981 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
982 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
983 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
984 } |
4988 | 985 |
986 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen); | |
987 | |
988 // create datatype for (null-terminated) string to read into: | |
989 st_id = H5Tcopy (H5T_C_S1); | |
990 H5Tset_size (st_id, slen); | |
991 | |
5760 | 992 if (H5Dread (data_hid, st_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, fcn_tmp) < 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
993 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
994 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
995 H5Sclose (space_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
996 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
997 H5Dclose (data_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
998 H5Gclose (group_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
999 return false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1000 } |
6695 | 1001 H5Tclose (st_id); |
4988 | 1002 H5Dclose (data_hid); |
6625 | 1003 |
1004 octave_idx_type len = 0; | |
1005 | |
1006 // we have to pull some shenanigans here to make sure | |
1007 // HDF5 doesn't print out all sorts of error messages if we | |
1008 // call H5Aopen for a non-existing attribute | |
1009 | |
1010 H5E_auto_t err_func; | |
1011 void *err_func_data; | |
4988 | 1012 |
6625 | 1013 // turn off error reporting temporarily, but save the error |
1014 // reporting function: | |
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
|
1015 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1016 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1017 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1018 #else |
6625 | 1019 H5Eget_auto (&err_func, &err_func_data); |
1020 H5Eset_auto (0, 0); | |
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
|
1021 #endif |
6625 | 1022 |
1023 hid_t attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE"); | |
4988 | 1024 |
6625 | 1025 if (attr_id >= 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1026 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1027 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1028 success = false; |
6625 | 1029 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1030 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1031 } |
6625 | 1032 |
1033 // restore error reporting: | |
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
|
1034 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1035 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1036 #else |
6625 | 1037 H5Eset_auto (err_func, err_func_data); |
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
|
1038 #endif |
6625 | 1039 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1040 unwind_protect_safe frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1041 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1042 // Set up temporary scope to use for evaluating the text that |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1043 // defines the anonymous function. |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1044 |
7336 | 1045 symbol_table::scope_id local_scope = symbol_table::alloc_scope (); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1046 frame.add_fcn (symbol_table::erase_scope, local_scope); |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1047 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1048 symbol_table::set_scope (local_scope); |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1049 |
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8946
diff
changeset
|
1050 octave_call_stack::push (local_scope, 0); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1051 frame.add_fcn (octave_call_stack::pop); |
7336 | 1052 |
6625 | 1053 if (len > 0 && success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1054 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1055 hsize_t num_obj = 0; |
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
|
1056 #if HAVE_HDF5_18 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1057 data_hid = H5Gopen (group_hid, "symbol table", 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
|
1058 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1059 data_hid = H5Gopen (group_hid, "symbol table"); |
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
|
1060 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1061 H5Gget_num_objs (data_hid, &num_obj); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1062 H5Gclose (data_hid); |
6625 | 1063 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1064 if (num_obj != static_cast<hsize_t>(len)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1065 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1066 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1067 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1068 } |
6625 | 1069 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1070 if (! error_state) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1071 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1072 hdf5_callback_data dsub; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1073 int current_item = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1074 for (octave_idx_type i = 0; i < len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1075 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1076 if (H5Giterate (group_hid, "symbol table", ¤t_item, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1077 hdf5_read_next_data, &dsub) <= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1078 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1079 error ("load: failed to load anonymous function handle"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1080 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1081 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1082 } |
6625 | 1083 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1084 symbol_table::varref (dsub.name, local_scope) = dsub.tc; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1085 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1086 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1087 } |
6625 | 1088 |
1089 if (success) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1090 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1091 int parse_status; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1092 octave_value anon_fcn_handle = |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1093 eval_string (fcn_tmp, true, parse_status); |
6625 | 1094 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1095 if (parse_status == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1096 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1097 octave_fcn_handle *fh = anon_fcn_handle.fcn_handle_value (); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1098 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1099 if (fh) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1100 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1101 fcn = fh->fcn; |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1102 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1103 octave_user_function *uf = fcn.user_function_value (true); |
7761
5adeea5de26c
symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents:
7756
diff
changeset
|
1104 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1105 if (uf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1106 symbol_table::cache_name (uf->scope (), nm); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1107 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1108 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1109 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1110 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1111 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1112 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1113 } |
6625 | 1114 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
1115 frame.run (); |
4988 | 1116 } |
1117 else | |
1118 { | |
6625 | 1119 std::string octaveroot; |
1120 std::string fpath; | |
1121 | |
1122 // we have to pull some shenanigans here to make sure | |
1123 // HDF5 doesn't print out all sorts of error messages if we | |
1124 // call H5Aopen for a non-existing attribute | |
1125 | |
1126 H5E_auto_t err_func; | |
1127 void *err_func_data; | |
1128 | |
1129 // turn off error reporting temporarily, but save the error | |
1130 // reporting function: | |
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
|
1131 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1132 H5Eget_auto (H5E_DEFAULT, &err_func, &err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1133 H5Eset_auto (H5E_DEFAULT, 0, 0); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1134 #else |
6625 | 1135 H5Eget_auto (&err_func, &err_func_data); |
1136 H5Eset_auto (0, 0); | |
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
|
1137 #endif |
6625 | 1138 |
1139 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT"); | |
1140 if (attr_id >= 0) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1141 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1142 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1143 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1144 type_class_hid = H5Tget_class (type_hid); |
6625 | 1145 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1146 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1147 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1148 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1149 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1150 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1151 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1152 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1153 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen); |
6625 | 1154 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1155 if (H5Aread (attr_id, st_id, root_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1156 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1157 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1158 octaveroot = root_tmp; |
6695 | 1159 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1160 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1161 } |
6625 | 1162 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1163 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1164 } |
6625 | 1165 |
6695 | 1166 if (success) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1167 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1168 attr_id = H5Aopen_name (group_hid, "FILE"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1169 if (attr_id >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1170 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1171 H5Tclose (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1172 type_hid = H5Aget_type (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1173 type_class_hid = H5Tget_class (type_hid); |
6625 | 1174 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1175 if (type_class_hid != H5T_STRING) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1176 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1177 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1178 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1179 slen = H5Tget_size (type_hid); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1180 st_id = H5Tcopy (H5T_C_S1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1181 H5Tset_size (st_id, slen); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1182 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen); |
6695 | 1183 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1184 if (H5Aread (attr_id, st_id, path_tmp) < 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1185 success = false; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1186 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1187 fpath = path_tmp; |
6695 | 1188 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1189 H5Tclose (st_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1190 } |
6695 | 1191 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1192 H5Aclose (attr_id); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1193 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1194 } |
6625 | 1195 |
1196 // restore error reporting: | |
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
|
1197 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1198 H5Eset_auto (H5E_DEFAULT, err_func, err_func_data); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
1199 #else |
6625 | 1200 H5Eset_auto (err_func, err_func_data); |
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
|
1201 #endif |
6625 | 1202 |
1203 success = (success ? set_fcn (octaveroot, fpath) : success); | |
4988 | 1204 } |
1205 | |
6695 | 1206 H5Tclose (type_hid); |
1207 H5Sclose (space_hid); | |
1208 H5Gclose (group_hid); | |
1209 | |
6625 | 1210 return success; |
4988 | 1211 } |
6625 | 1212 |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1213 #endif |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1214 |
6625 | 1215 /* |
1216 | |
1217 %!test | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1218 %! a = 2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1219 %! f = @(x) a + x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1220 %! g = @(x) 2 * x; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1221 %! hm = @flops; |
7745
0ff0fc033f28
better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents:
7744
diff
changeset
|
1222 %! hdld = @svd; |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1223 %! hbi = @log2; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1224 %! f2 = f; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1225 %! g2 = g; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1226 %! hm2 = hm; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1227 %! hdld2 = hdld; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1228 %! hbi2 = hbi; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1229 %! modes = {"-text", "-binary"}; |
6625 | 1230 %! if (!isempty(findstr(octave_config_info ("DEFS"),"HAVE_HDF5"))) |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1231 %! modes(end+1) = "-hdf5"; |
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1232 %! endif |
7901 | 1233 %! for i = 1:numel (modes) |
1234 %! mode = modes{i}; | |
6625 | 1235 %! nm = tmpnam(); |
1236 %! unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1237 %! 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
|
1238 %! clear f2 g2 hm2 hdld2 hbi2 |
6625 | 1239 %! load (nm); |
1240 %! assert (f(2),f2(2)); | |
1241 %! assert (g(2),g2(2)); | |
1242 %! assert (g(3),g2(3)); | |
1243 %! unlink (nm); | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1244 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2"); |
6625 | 1245 %! unwind_protect_cleanup |
1246 %! unlink (nm); | |
1247 %! end_unwind_protect | |
7744
14b841c47a5f
handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents:
7740
diff
changeset
|
1248 %! endfor |
6625 | 1249 |
1250 */ | |
4988 | 1251 |
4343 | 1252 void |
1253 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax) const | |
1254 { | |
1255 print_raw (os, pr_as_read_syntax); | |
1256 newline (os); | |
1257 } | |
1258 | |
1259 void | |
1260 octave_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax) const | |
1261 { | |
4980 | 1262 bool printed = false; |
1263 | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1264 if (nm == anonymous) |
4980 | 1265 { |
1266 tree_print_code tpc (os); | |
1267 | |
4989 | 1268 // FCN is const because this member function is, so we can't |
4980 | 1269 // use it to call user_function_value, so we make a copy first. |
1270 | |
1271 octave_value ftmp = fcn; | |
1272 | |
1273 octave_user_function *f = ftmp.user_function_value (); | |
1274 | |
1275 if (f) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1276 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1277 tree_parameter_list *p = f->parameter_list (); |
4980 | 1278 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1279 os << "@("; |
4980 | 1280 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1281 if (p) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1282 p->accept (tpc); |
4980 | 1283 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1284 os << ") "; |
4980 | 1285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1286 tree_statement_list *b = f->body (); |
4980 | 1287 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1288 if (b) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1289 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1290 assert (b->length () == 1); |
4980 | 1291 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1292 tree_statement *s = b->front (); |
4980 | 1293 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1294 if (s) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1295 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1296 if (s->is_expression ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1297 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1298 tree_expression *e = s->expression (); |
4980 | 1299 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1300 if (e) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1301 e->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1302 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1303 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1304 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1305 tree_command *c = s->command (); |
4980 | 1306 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1307 tpc.suspend_newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1308 c->accept (tpc); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1309 tpc.resume_newline (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1310 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1311 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1312 } |
4980 | 1313 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1314 printed = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1315 } |
4980 | 1316 } |
1317 | |
1318 if (! printed) | |
10261
a4fb4675accb
make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents:
10250
diff
changeset
|
1319 octave_print_internal (os, "@" + nm, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1320 current_print_indent_level ()); |
4343 | 1321 } |
1322 | |
1323 octave_value | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1324 make_fcn_handle (const std::string& nm, bool local_funcs) |
4343 | 1325 { |
1326 octave_value retval; | |
1327 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1328 // Bow to the god of compatibility. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1329 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1330 // FIXME -- it seems ugly to put this here, but there is no single |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1331 // function in the parser that converts from the operator name to |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1332 // the corresponding function name. At least try to do it without N |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1333 // string compares. |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1334 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1335 std::string tnm = nm; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1336 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1337 size_t len = nm.length (); |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1338 |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1339 if (len == 3 && nm == ".**") |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1340 tnm = "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1341 else if (len == 2) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1342 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1343 if (nm[0] == '.') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1344 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1345 switch (nm[1]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1346 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1347 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1348 tnm = "transpose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1349 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1350 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1351 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1352 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1353 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1354 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1355 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1356 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1357 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1358 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1359 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1360 tnm = "times"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1361 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1362 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1363 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1364 tnm = "rdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1365 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1366 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1367 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1368 tnm = "power"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1369 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1370 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1371 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1372 tnm = "ldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1373 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1374 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1375 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1376 else if (nm[1] == '=') |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1377 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1378 switch (nm[0]) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1379 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1380 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1381 tnm = "le"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1382 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1383 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1384 case '=': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1385 tnm = "eq"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1386 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1387 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1388 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1389 tnm = "ge"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1390 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1391 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1392 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1393 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1394 tnm = "ne"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1395 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1396 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1397 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1398 else if (nm == "**") |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1399 tnm = "mpower"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1400 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1401 else if (len == 1) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1402 { |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1403 switch (nm[0]) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1404 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1405 case '~': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1406 case '!': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1407 tnm = "not"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1408 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1409 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1410 case '\'': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1411 tnm = "ctranspose"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1412 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1413 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1414 case '+': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1415 tnm = "plus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1416 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1417 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1418 case '-': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1419 tnm = "minus"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1420 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1421 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1422 case '*': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1423 tnm = "mtimes"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1424 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1425 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1426 case '/': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1427 tnm = "mrdivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1428 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1429 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1430 case '^': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1431 tnm = "mpower"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1432 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1433 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1434 case '\\': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1435 tnm = "mldivide"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1436 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1437 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1438 case '<': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1439 tnm = "lt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1440 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1441 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1442 case '>': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1443 tnm = "gt"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1444 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1445 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1446 case '&': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1447 tnm = "and"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1448 break; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1449 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1450 case '|': |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1451 tnm = "or"; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1452 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1453 } |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1454 } |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1455 |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1456 bool handle_ok = false; |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1457 octave_value f = symbol_table::find_function (tnm, octave_value_list (), |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1458 local_funcs); |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1459 octave_function *fptr = f.function_value (true); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1460 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1461 if (local_funcs && fptr |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1462 && (fptr->is_nested_function () || fptr->is_private_function () |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1463 || fptr->is_class_constructor ())) |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1464 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1465 // Locally visible function. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1466 retval = octave_value (new octave_fcn_handle (f, tnm)); |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1467 } |
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1468 else |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1469 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1470 // Globally visible (or no match yet). Query overloads. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1471 std::list<std::string> classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1472 bool any_match = fptr != 0 || classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1473 if (! any_match) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1474 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1475 // No match found, try updating load_path and query classes again. |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1476 load_path::update (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1477 classes = load_path::overloads (tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1478 any_match = classes.size () > 0; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1479 } |
9458
0c7d84a65386
allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents:
9450
diff
changeset
|
1480 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1481 if (any_match) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1482 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1483 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1484 retval = fh; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1485 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1486 for (std::list<std::string>::iterator iter = classes.begin (); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1487 iter != classes.end (); iter++) |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1488 { |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1489 std::string class_name = *iter; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1490 octave_value fmeth = symbol_table::find_method (tnm, class_name); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1491 |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1492 bool is_builtin = false; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1493 for (int i = 0; i < btyp_num_types; i++) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1494 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1495 // FIXME: Too slow? Maybe binary lookup? |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1496 if (class_name == btyp_class_name[i]) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1497 { |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1498 is_builtin = true; |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1499 fh->set_overload (static_cast<builtin_type_t> (i), fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1500 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1501 } |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1502 |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1503 if (! is_builtin) |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1504 fh->set_overload (class_name, fmeth); |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1505 } |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1506 } |
10321
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1507 else |
97b4bd6f0925
partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
10315
diff
changeset
|
1508 error ("@%s: no function and no method found", tnm.c_str ()); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1509 } |
4343 | 1510 |
1511 return retval; | |
1512 } | |
1513 | |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1514 /* |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1515 %!test |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1516 %! x = {".**", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1517 %! ".'", "transpose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1518 %! ".+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1519 %! ".-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1520 %! ".*", "times"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1521 %! "./", "rdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1522 %! ".^", "power"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1523 %! ".\\", "ldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1524 %! "<=", "le"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1525 %! "==", "eq"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1526 %! ">=", "ge"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1527 %! "~=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1528 %! "!=", "ne"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1529 %! "**", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1530 %! "~", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1531 %! "!", "not"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1532 %! "\'", "ctranspose"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1533 %! "+", "plus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1534 %! "-", "minus"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1535 %! "*", "mtimes"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1536 %! "/", "mrdivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1537 %! "^", "mpower"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1538 %! "\\", "mldivide"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1539 %! "<", "lt"; |
9343
70e0d3b1f26f
fix typos in previous change
John W. Eaton <jwe@octave.org>
parents:
9342
diff
changeset
|
1540 %! ">", "gt"; |
9342
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1541 %! "&", "and"; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1542 %! "|", "or"}; |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1543 %! for i = 1:rows (x) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1544 %! assert (functions (str2func (x{i,1})).function, x{i,2}) |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1545 %! endfor |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1546 */ |
2ca8879a140c
allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
1547 |
4933 | 1548 DEFUN (functions, args, , |
4343 | 1549 "-*- texinfo -*-\n\ |
4933 | 1550 @deftypefn {Built-in Function} {} functions (@var{fcn_handle})\n\ |
1551 Return a struct containing information about the function handle\n\ | |
1552 @var{fcn_handle}.\n\ | |
1553 @end deftypefn") | |
4343 | 1554 { |
1555 octave_value retval; | |
1556 | |
4933 | 1557 if (args.length () == 1) |
4343 | 1558 { |
4933 | 1559 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4343 | 1560 |
1561 if (! error_state) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1562 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1563 octave_function *fcn = fh ? fh->function_value () : 0; |
4343 | 1564 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1565 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1566 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1567 Octave_map m; |
4649 | 1568 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1569 std::string fh_nm = fh->fcn_name (); |
4933 | 1570 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1571 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1572 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1573 std::ostringstream buf; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1574 fh->print_raw (buf); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1575 m.assign ("function", buf.str ()); |
6625 | 1576 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1577 m.assign ("type", "anonymous"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1578 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1579 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1580 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1581 m.assign ("function", fh_nm); |
4343 | 1582 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1583 if (fcn->is_nested_function ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1584 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1585 m.assign ("type", "subfunction"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1586 Cell parentage (dim_vector (1, 2)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1587 parentage.elem(0) = fh_nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1588 parentage.elem(1) = fcn->parent_fcn_name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1589 m.assign ("parentage", octave_value (parentage)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1590 } |
9509
c5330ef7aecd
fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents:
9466
diff
changeset
|
1591 else if (fcn->is_private_function ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1592 m.assign ("type", "private"); |
9450
cf714e75c656
implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents:
9419
diff
changeset
|
1593 else if (fh->is_overloaded ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1594 m.assign ("type", "overloaded"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1595 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1596 m.assign ("type", "simple"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1597 } |
4933 | 1598 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1599 std::string nm = fcn->fcn_file_name (); |
4343 | 1600 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1601 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1602 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1603 m.assign ("file", nm); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1604 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1605 octave_user_function *fu = fh->user_function_value (); |
6625 | 1606 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1607 std::list<symbol_table::symbol_record> vars |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1608 = symbol_table::all_variables (fu->scope (), 0); |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1609 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1610 size_t varlen = vars.size (); |
6625 | 1611 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1612 if (varlen > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1614 Octave_map ws; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1615 for (std::list<symbol_table::symbol_record>::const_iterator p = vars.begin (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1616 p != vars.end (); p++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1617 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1618 ws.assign (p->name (), p->varval (0)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1619 } |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1620 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1621 m.assign ("workspace", ws); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1622 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1623 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1624 else if (fcn->is_user_function () || fcn->is_user_script ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1625 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1626 octave_function *fu = fh->function_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1627 m.assign ("file", fu->fcn_file_name ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1628 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1629 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1630 m.assign ("file", ""); |
4933 | 1631 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1632 retval = m; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1633 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1634 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1635 error ("functions: invalid function handle object"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1636 } |
4343 | 1637 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1638 error ("functions: argument must be a function handle object"); |
4343 | 1639 } |
1640 else | |
5823 | 1641 print_usage (); |
4343 | 1642 |
1643 return retval; | |
1644 } | |
1645 | |
4933 | 1646 DEFUN (func2str, args, , |
4343 | 1647 "-*- texinfo -*-\n\ |
4933 | 1648 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\ |
1649 Return a string containing the name of the function referenced by\n\ | |
1650 the function handle @var{fcn_handle}.\n\ | |
1651 @end deftypefn") | |
4343 | 1652 { |
1653 octave_value retval; | |
1654 | |
4933 | 1655 if (args.length () == 1) |
4930 | 1656 { |
4933 | 1657 octave_fcn_handle *fh = args(0).fcn_handle_value (); |
4930 | 1658 |
4933 | 1659 if (! error_state && fh) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1660 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1661 std::string fh_nm = fh->fcn_name (); |
6416 | 1662 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1663 if (fh_nm == octave_fcn_handle::anonymous) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1664 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1665 std::ostringstream buf; |
6416 | 1666 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1667 fh->print_raw (buf); |
6416 | 1668 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1669 retval = buf.str (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1670 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1671 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1672 retval = fh_nm; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1673 } |
4343 | 1674 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1675 error ("func2str: expecting valid function handle as first argument"); |
4343 | 1676 } |
1677 else | |
5823 | 1678 print_usage (); |
4343 | 1679 |
1680 return retval; | |
1681 } | |
1682 | |
4933 | 1683 DEFUN (str2func, args, , |
4343 | 1684 "-*- texinfo -*-\n\ |
4933 | 1685 @deftypefn {Built-in Function} {} str2func (@var{fcn_name})\n\ |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1686 @deftypefnx {Built-in Function} {} str2func (@var{fcn_name}, \"global\")\n\ |
4933 | 1687 Return a function handle constructed from the string @var{fcn_name}.\n\ |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1688 If the optional \"global\" argument is passed, locally visible functions\n\ |
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1689 are ignored in the lookup.\n\ |
4933 | 1690 @end deftypefn") |
4343 | 1691 { |
1692 octave_value retval; | |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1693 int nargin = args.length (); |
4343 | 1694 |
9463
d34baf412786
support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents:
9458
diff
changeset
|
1695 if (nargin == 1 || nargin == 2) |
4343 | 1696 { |
4933 | 1697 std::string nm = args(0).string_value (); |
4343 | 1698 |
4933 | 1699 if (! error_state) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1700 retval = make_fcn_handle (nm, nargin != 2); |
4343 | 1701 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10261
diff
changeset
|
1702 error ("str2func: expecting string as first argument"); |
4343 | 1703 } |
1704 else | |
5823 | 1705 print_usage (); |
4343 | 1706 |
1707 return retval; | |
1708 } | |
1709 | |
1710 /* | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1711 %!function y = testrecursionfunc (f, x, n) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1712 %! if (nargin < 3) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1713 %! n = 0; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1714 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1715 %! if (n > 2) |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1716 %! y = f (x); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1717 %! else |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1718 %! n++; |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1719 %! y = testrecursionfunc (@(x) f(2*x), x, n); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1720 %! endif |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1721 %!test |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1722 %! assert (testrecursionfunc (@(x) x, 1), 8); |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7761
diff
changeset
|
1723 */ |