annotate src/ov-fcn-handle.cc @ 10250:2d47356a7a1a

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