annotate src/ov-fcn-handle.cc @ 10960:409ceee18acc

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