annotate libinterp/octave-value/ov-fcn-handle.cc @ 17281:bc924baa2c4e

doc: Add new @qcode macro for code samples which are quoted. Macro handles options ("on") or properties ("position") more elegantly than @code{"text"}. * doc/interpreter/macros.texi: Add new @qcode macro. * doc/interpreter/tips.txi: Add documentation about @qcode macro. * doc/interpreter/basics.txi, doc/interpreter/container.txi, doc/interpreter/emacs.txi, doc/interpreter/errors.txi, doc/interpreter/eval.txi, doc/interpreter/expr.txi, doc/interpreter/external.txi, doc/interpreter/func.txi, doc/interpreter/grammar.txi, doc/interpreter/image.txi, doc/interpreter/install.txi, doc/interpreter/interp.txi, doc/interpreter/io.txi, doc/interpreter/matrix.txi, doc/interpreter/numbers.txi, doc/interpreter/oop.txi, doc/interpreter/package.txi, doc/interpreter/plot.txi, doc/interpreter/quad.txi, doc/interpreter/sparse.txi, doc/interpreter/strings.txi, doc/interpreter/system.txi, doc/interpreter/vectorize.txi, libinterp/corefcn/balance.cc, libinterp/corefcn/bitfcns.cc, libinterp/corefcn/cellfun.cc, libinterp/corefcn/conv2.cc, libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc, libinterp/corefcn/defaults.cc, libinterp/corefcn/dirfns.cc, libinterp/corefcn/dlmread.cc, libinterp/corefcn/error.cc, libinterp/corefcn/file-io.cc, libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc, libinterp/corefcn/graphics.cc, libinterp/corefcn/help.cc, libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc, libinterp/corefcn/load-path.cc, libinterp/corefcn/load-save.cc, libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc, libinterp/corefcn/matrix_type.cc, libinterp/corefcn/oct-hist.cc, libinterp/corefcn/pager.cc, libinterp/corefcn/pr-output.cc, libinterp/corefcn/pt-jit.cc, libinterp/corefcn/qz.cc, libinterp/corefcn/rand.cc, libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc, libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sparse.cc, libinterp/corefcn/spparms.cc, libinterp/corefcn/str2double.cc, libinterp/corefcn/svd.cc, libinterp/corefcn/symtab.cc, libinterp/corefcn/syscalls.cc, libinterp/corefcn/toplev.cc, libinterp/corefcn/tril.cc, libinterp/corefcn/typecast.cc, libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc, libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/chol.cc, libinterp/dldfcn/colamd.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc, libinterp/dldfcn/symbfact.cc, libinterp/octave-value/ov-base.cc, libinterp/octave-value/ov-fcn-handle.cc, libinterp/octave-value/ov-fcn-inline.cc, libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-range.cc, libinterp/octave-value/ov-struct.cc, libinterp/octave-value/ov-usr-fcn.cc, libinterp/parse-tree/oct-parse.in.yy, libinterp/parse-tree/pt-binop.cc, libinterp/parse-tree/pt-eval.cc, libinterp/parse-tree/pt-mat.cc, scripts/@ftp/ftp.m, scripts/deprecated/java_convert_matrix.m, scripts/deprecated/java_debug.m, scripts/deprecated/java_unsigned_conversion.m, scripts/deprecated/shell_cmd.m, scripts/general/dblquad.m, scripts/general/display.m, scripts/general/genvarname.m, scripts/general/idivide.m, scripts/general/interp1.m, scripts/general/interp2.m, scripts/general/interp3.m, scripts/general/interpn.m, scripts/general/isa.m, scripts/general/profexplore.m, scripts/general/profile.m, scripts/general/quadgk.m, scripts/general/randi.m, scripts/general/structfun.m, scripts/general/subsindex.m, scripts/general/triplequad.m, scripts/geometry/griddata.m, scripts/geometry/griddata3.m, scripts/geometry/griddatan.m, scripts/geometry/voronoi.m, scripts/help/help.m, scripts/help/lookfor.m, scripts/image/cmpermute.m, scripts/image/colormap.m, scripts/image/image.m, scripts/image/imagesc.m, scripts/image/imfinfo.m, scripts/image/imformats.m, scripts/image/imread.m, scripts/image/imshow.m, scripts/image/imwrite.m, scripts/image/ind2gray.m, scripts/image/lines.m, scripts/image/rgb2ind.m, scripts/image/spinmap.m, scripts/io/dlmwrite.m, scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m, scripts/java/javaclasspath.m, scripts/java/usejava.m, scripts/miscellaneous/bzip2.m, scripts/miscellaneous/computer.m, scripts/miscellaneous/copyfile.m, scripts/miscellaneous/debug.m, scripts/miscellaneous/dos.m, scripts/miscellaneous/edit.m, scripts/miscellaneous/gzip.m, scripts/miscellaneous/license.m, scripts/miscellaneous/mkoctfile.m, scripts/miscellaneous/movefile.m, scripts/miscellaneous/parseparams.m, scripts/miscellaneous/unix.m, scripts/optimization/fminbnd.m, scripts/optimization/fminsearch.m, scripts/optimization/fminunc.m, scripts/optimization/fsolve.m, scripts/optimization/fzero.m, scripts/optimization/glpk.m, scripts/optimization/lsqnonneg.m, scripts/optimization/optimset.m, scripts/optimization/pqpnonneg.m, scripts/pkg/pkg.m, scripts/plot/allchild.m, scripts/plot/ancestor.m, scripts/plot/area.m, scripts/plot/axis.m, scripts/plot/bar.m, scripts/plot/barh.m, scripts/plot/box.m, scripts/plot/caxis.m, scripts/plot/cla.m, scripts/plot/clabel.m, scripts/plot/clf.m, scripts/plot/close.m, scripts/plot/colorbar.m, scripts/plot/daspect.m, scripts/plot/ezmesh.m, scripts/plot/ezmeshc.m, scripts/plot/ezsurf.m, scripts/plot/ezsurfc.m, scripts/plot/findall.m, scripts/plot/findobj.m, scripts/plot/gcbo.m, scripts/plot/gcf.m, scripts/plot/gco.m, scripts/plot/grid.m, scripts/plot/guihandles.m, scripts/plot/hdl2struct.m, scripts/plot/hidden.m, scripts/plot/hold.m, scripts/plot/isonormals.m, scripts/plot/isosurface.m, scripts/plot/legend.m, scripts/plot/mesh.m, scripts/plot/meshc.m, scripts/plot/meshz.m, scripts/plot/newplot.m, scripts/plot/orient.m, scripts/plot/pareto.m, scripts/plot/patch.m, scripts/plot/pbaspect.m, scripts/plot/pcolor.m, scripts/plot/plot.m, scripts/plot/print.m, scripts/plot/private/__add_default_menu__.m, scripts/plot/quiver.m, scripts/plot/quiver3.m, scripts/plot/refreshdata.m, scripts/plot/saveas.m, scripts/plot/scatter.m, scripts/plot/scatter3.m, scripts/plot/shading.m, scripts/plot/shrinkfaces.m, scripts/plot/slice.m, scripts/plot/stem.m, scripts/plot/stem3.m, scripts/plot/struct2hdl.m, scripts/plot/subplot.m, scripts/plot/surf.m, scripts/plot/surfc.m, scripts/plot/surfl.m, scripts/plot/tetramesh.m, scripts/plot/uigetfile.m, scripts/plot/uimenu.m, scripts/plot/uiputfile.m, scripts/plot/waterfall.m, scripts/plot/whitebg.m, scripts/plot/xlim.m, scripts/plot/ylim.m, scripts/plot/zlim.m, scripts/polynomial/conv.m, scripts/polynomial/polyout.m, scripts/polynomial/splinefit.m, scripts/set/ismember.m, scripts/set/powerset.m, scripts/set/setdiff.m, scripts/set/union.m, scripts/set/unique.m, scripts/signal/detrend.m, scripts/signal/filter2.m, scripts/signal/freqz.m, scripts/signal/periodogram.m, scripts/signal/spectral_adf.m, scripts/signal/spectral_xdf.m, scripts/sparse/eigs.m, scripts/sparse/svds.m, scripts/specfun/legendre.m, scripts/special-matrix/gallery.m, scripts/statistics/base/mean.m, scripts/statistics/base/moment.m, scripts/statistics/tests/cor_test.m, scripts/statistics/tests/kolmogorov_smirnov_test.m, scripts/statistics/tests/kolmogorov_smirnov_test_2.m, scripts/statistics/tests/kruskal_wallis_test.m, scripts/statistics/tests/prop_test_2.m, scripts/statistics/tests/sign_test.m, scripts/statistics/tests/t_test.m, scripts/statistics/tests/t_test_2.m, scripts/statistics/tests/t_test_regression.m, scripts/statistics/tests/u_test.m, scripts/statistics/tests/var_test.m, scripts/statistics/tests/welch_test.m, scripts/statistics/tests/wilcoxon_test.m, scripts/statistics/tests/z_test.m, scripts/statistics/tests/z_test_2.m, scripts/strings/base2dec.m, scripts/strings/index.m, scripts/strings/isstrprop.m, scripts/strings/mat2str.m, scripts/strings/regexptranslate.m, scripts/strings/rindex.m, scripts/strings/str2num.m, scripts/strings/strcat.m, scripts/strings/strjust.m, scripts/strings/strmatch.m, scripts/strings/validatestring.m, scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/test.m, scripts/time/addtodate.m, scripts/time/asctime.m, scripts/time/datestr.m, scripts/time/datetick.m, scripts/time/weekday.m, scripts/ui/errordlg.m, scripts/ui/helpdlg.m, scripts/ui/inputdlg.m, scripts/ui/listdlg.m, scripts/ui/msgbox.m, scripts/ui/questdlg.m, scripts/ui/warndlg.m: Use new @qcode macro.
author Rik <rik@octave.org>
date Mon, 19 Aug 2013 20:46:38 -0700
parents e39f00a32dc7
children c702371ff6df d63878346099
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
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 14085
diff changeset
3 Copyright (C) 2003-2012 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);
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14429
diff changeset
83
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14429
diff changeset
84 if (uf && uf->is_nested_function ())
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14429
diff changeset
85 ::error ("handles to nested functions are not yet supported");
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
86 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
87
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
88 octave_value_list
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
89 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
90 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
91 int nargout)
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
92 {
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
93 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
94 }
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
95
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
96 octave_value_list
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
97 octave_fcn_handle::subsref (const std::string& type,
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
98 const std::list<octave_value_list>& idx,
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
99 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
100 {
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
101 octave_value_list retval;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
102
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
103 switch (type[0])
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
104 {
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
105 case '(':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
106 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
107 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
108
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
109 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
110 idx.size () == 1 ? lvalue_list : 0);
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
111 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
112 break;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
113
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
114 case '{':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
115 case '.':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
116 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
117 std::string tnm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
118 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
119 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
120 break;
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 default:
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
123 panic_impossible ();
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
124 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
125
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
126 // FIXME -- perhaps there should be an
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
127 // octave_value_list::next_subsref member function? See also
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
128 // octave_builtin::subsref.
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 if (idx.size () > 1)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
131 retval = retval(0).next_subsref (nargout, type, idx);
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 return retval;
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
134 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
135
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
136 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
137 octave_fcn_handle::do_multi_index_op (int nargout,
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
138 const octave_value_list& args)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
139 {
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
140 return do_multi_index_op (nargout, args, 0);
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
141 }
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
142
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
143 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
144 octave_fcn_handle::do_multi_index_op (int nargout,
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
145 const octave_value_list& args,
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
146 const std::list<octave_lvalue>* lvalue_list)
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
147 {
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
148 octave_value_list retval;
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
149
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
150 out_of_date_check (fcn, std::string (), false);
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
151
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
152 if (has_overloads)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
153 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
154 // Possibly overloaded function.
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
155 octave_value ov_fcn;
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
156
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
157 // Compute dispatch type.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
158 builtin_type_t btyp;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
159 std::string dispatch_type = get_dispatch_type (args, btyp);
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 // Retrieve overload.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
162 if (btyp != btyp_unknown)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
163 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
164 out_of_date_check (builtin_overloads[btyp], dispatch_type, false);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
165 ov_fcn = builtin_overloads[btyp];
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
166 }
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
167 else
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
168 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
169 str_ov_map::iterator it = overloads.find (dispatch_type);
13193
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
170
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
171 if (it == overloads.end ())
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
172 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
173 // Try parent classes too.
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
174
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
175 std::list<std::string> plist
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
176 = symbol_table::parent_classes (dispatch_type);
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
177
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
178 std::list<std::string>::const_iterator pit = plist.begin ();
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
179
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
180 while (pit != plist.end ())
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
181 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
182 std::string pname = *pit;
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
183
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
184 std::string fnm = fcn_name ();
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
185
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
186 octave_value ftmp = symbol_table::find_method (fnm, pname);
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
187
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
188 if (ftmp.is_defined ())
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
189 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
190 set_overload (pname, ftmp);
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
191
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
192 out_of_date_check (ftmp, pname, false);
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
193 ov_fcn = ftmp;
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
194
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
195 break;
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
196 }
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
197
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
198 pit++;
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
199 }
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
200 }
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
201 else
9466
2ebd0717c12d also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9463
diff changeset
202 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
203 out_of_date_check (it->second, dispatch_type, false);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
204 ov_fcn = it->second;
9466
2ebd0717c12d also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9463
diff changeset
205 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
206 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
207
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
208 if (ov_fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
209 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
210 else if (fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
211 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
212 else
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
213 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
214 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
215 else
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
216 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
217 // Non-overloaded function (anonymous, subfunction, private function).
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
218 if (fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
219 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
220 else
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
221 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
222 }
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
223
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
224 return retval;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
225 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
226
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
227 bool
10322
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
228 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
229 {
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
230 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
231 retval = retval && (overloads.size () == h.overloads.size ());
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
232
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
233 if (retval && has_overloads)
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
234 {
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
235 for (int i = 0; i < btyp_num_types && retval; i++)
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
236 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
237
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
238 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
239 for (; iter != overloads.end () && retval; iter++, hiter++)
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
240 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
241 }
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
242
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
243 return retval;
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
244 }
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
245
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
246 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
247 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
248 const std::string& fpath)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
249 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
250 bool success = true;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
251
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
252 if (octaveroot.length () != 0
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
253 && fpath.length () >= octaveroot.length ()
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
254 && 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
255 && OCTAVE_EXEC_PREFIX != octaveroot)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
256 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
257 // First check if just replacing matlabroot is enough
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
258 std::string str = OCTAVE_EXEC_PREFIX +
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
259 fpath.substr (octaveroot.length ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
260 file_stat fs (str);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
261
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
262 if (fs.exists ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
263 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
264 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
265
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
266 std::string dir_name = str.substr (0, xpos);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
267
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
268 octave_function *xfcn
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
269 = load_fcn_from_file (str, dir_name, "", nm);
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 if (xfcn)
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 octave_value tmp (xfcn);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
274
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
275 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
276 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
277 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
278 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
279 error ("function handle points to non-existent function");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
280 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
281 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
282 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
283 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
284 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
285 // 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
286 string_vector names(3);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
287 names(0) = nm + ".oct";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
288 names(1) = nm + ".mex";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
289 names(2) = nm + ".m";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
290
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
291 dir_path p (load_path::system_path ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
292
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
293 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
294
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
295 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
296
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
297 std::string dir_name = str.substr (0, xpos);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
298
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
299 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
300
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
301 if (xfcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
302 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
303 octave_value tmp (xfcn);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
304
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
305 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
306 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
307 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
308 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
309 error ("function handle points to non-existent function");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
310 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
311 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
312 }
6625
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 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
315 {
15005
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
316 if (fpath.length () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
317 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
318 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
319
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
320 std::string dir_name = fpath.substr (0, xpos);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
321
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
322 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
323
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
324 if (xfcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
325 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
326 octave_value tmp (xfcn);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
327
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
328 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
329 }
15005
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
330 else
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
331 {
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
332 error ("function handle points to non-existent function");
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
333 success = false;
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
334 }
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
335 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
336 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
337 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
338 fcn = symbol_table::find_function (nm);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
339
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
340 if (! fcn.is_function ())
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
341 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
342 error ("function handle points to non-existent function");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
343 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
344 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
345 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
346 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
347
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
348 return success;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
349 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
350
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
351 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6695
diff changeset
352 octave_fcn_handle::save_ascii (std::ostream& os)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
353 {
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
354 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
355 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
356 os << nm << "\n";
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
357
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
358 print_raw (os, true);
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
359 os << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
360
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
361 if (fcn.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
362 return false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
363
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
364 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
365
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
366 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
367 = symbol_table::all_variables (f->scope (), 0);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
368
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
369 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
370
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
371 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
372 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
373 os << "# length: " << varlen << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
374
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
375 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
376 p != vars.end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
377 {
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
378 if (! save_ascii_data (os, p->varval (0), p->name (), false, 0))
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
379 return os;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
380 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
381 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
382 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
383 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
384 {
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
385 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
386 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
387
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
388 os << "# octaveroot: " << OCTAVE_EXEC_PREFIX << "\n";
15005
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
389 if (! fnm.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
390 os << "# path: " << fnm << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
391 os << nm << "\n";
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
392 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
393
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
394 return true;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
395 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
396
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
397 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
398 octave_fcn_handle::load_ascii (std::istream& is)
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 bool success = true;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
401
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
402 std::streampos pos = is.tellg ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
403 std::string octaveroot = extract_keyword (is, "octaveroot", true);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14544
diff changeset
404 if (octaveroot.length () == 0)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
405 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
406 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
407 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
408 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
409 pos = is.tellg ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
410 std::string fpath = extract_keyword (is, "path", true);
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14544
diff changeset
411 if (fpath.length () == 0)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
412 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
413 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
414 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
415 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
416
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
417 is >> nm;
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
418
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
419 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
420 {
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
421 skip_preceeding_newline (is);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
422
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
423 std::string buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
424
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
425 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
426 {
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
427
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
428 // 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
429 // newline in the stream.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
430 buf = read_until_newline (is, true);
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
431
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
432 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
433
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
434 pos = is.tellg ();
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
435
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
436 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
437
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
438 // 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
439 // 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
440
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
441 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
442 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
443
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
444 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
445
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
446 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
447 frame.add_fcn (octave_call_stack::pop);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
448
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
449 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
450
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
451 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
452 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
453 if (len > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
454 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
455 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
456 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
457 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
458 bool dummy;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
459
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
460 std::string name
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
461 = 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
462
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
463 if (!is)
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 error ("load: failed to load anonymous function handle");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
466 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
467 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
468
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16170
diff changeset
469 symbol_table::assign (name, t2, local_scope, 0);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
470 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
471 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
472 }
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
473 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
474 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
475 is.seekg (pos);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
476 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
477 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
478
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
479 if (is && success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
480 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
481 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
482 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
483 eval_string (buf, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
484
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
485 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
486 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
487 octave_fcn_handle *fh =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
488 anon_fcn_handle.fcn_handle_value ();
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
489
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
490 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
491 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
492 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
493
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
494 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
495
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
496 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
497 symbol_table::cache_name (uf->scope (), nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
498 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
499 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
500 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
501 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
502 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
503 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
504 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
505 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
506 success = false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
507 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
508 else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
509 success = set_fcn (octaveroot, fpath);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
510
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
511 return success;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
512 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
513
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
514 bool
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
515 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
516 {
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
517 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
518 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
519 std::ostringstream nmbuf;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
520
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
521 if (fcn.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
522 return false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
523
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
524 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
525
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
526 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
527 = symbol_table::all_variables (f->scope (), 0);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
528
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
529 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
530
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
531 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
532 nmbuf << nm << " " << varlen;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
533 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
534 nmbuf << nm;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
535
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14544
diff changeset
536 std::string buf_str = nmbuf.str ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
537 int32_t tmp = buf_str.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
538 os.write (reinterpret_cast<char *> (&tmp), 4);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
539 os.write (buf_str.c_str (), buf_str.length ());
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
540
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
541 std::ostringstream buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
542 print_raw (buf, true);
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
543 std::string stmp = buf.str ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
544 tmp = stmp.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
545 os.write (reinterpret_cast<char *> (&tmp), 4);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
546 os.write (stmp.c_str (), stmp.length ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
547
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
548 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
549 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
550 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
551 p != vars.end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
552 {
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
553 if (! save_binary_data (os, p->varval (0), p->name (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
554 "", 0, save_as_floats))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
555 return os;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
556 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
557 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
558 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
559 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
560 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
561 std::ostringstream nmbuf;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
562
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
563 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
564 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
565
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
566 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
567
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
568 std::string buf_str = nmbuf.str ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
569 int32_t tmp = buf_str.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
570 os.write (reinterpret_cast<char *> (&tmp), 4);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
571 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
572 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
573
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
574 return true;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
575 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
576
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
577 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
578 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
579 oct_mach_info::float_format fmt)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
580 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
581 bool success = true;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
582
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
583 int32_t tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
584 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
585 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
586 if (swap)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
587 swap_bytes<4> (&tmp);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
588
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
589 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1);
12714
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
590 // is.get (ctmp1, tmp+1, 0); caused is.eof () to be true though
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
591 // effectively not reading over file end
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
592 is.read (ctmp1, tmp);
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
593 ctmp1[tmp] = 0;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
594 nm = std::string (ctmp1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
595
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
596 if (! is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
597 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
598
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
599 size_t anl = anonymous.length ();
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
600
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14544
diff changeset
601 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
602 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
603 octave_idx_type len = 0;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
604
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14544
diff changeset
605 if (nm.length () > anl)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
606 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
607 std::istringstream nm_is (nm.substr (anl));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
608 nm_is >> len;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
609 nm = nm.substr (0, anl);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
610 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
611
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
612 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
613 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
614 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
615 swap_bytes<4> (&tmp);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
616
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
617 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
12714
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
618 // is.get (ctmp2, tmp+1, 0); caused is.eof () to be true though
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
619 // effectively not reading over file end
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
620 is.read (ctmp2, tmp);
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
621 ctmp2[tmp] = 0;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
622
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
623 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
624
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
625 // 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
626 // 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
627
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
628 symbol_table::scope_id local_scope = symbol_table::alloc_scope ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
629 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
630
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
631 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
632
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
633 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
634 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
635
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
636 if (len > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
637 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
638 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
639 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
640 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
641 bool dummy;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
642 std::string doc;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
643
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
644 std::string name =
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
645 read_binary_data (is, swap, fmt, std::string (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
646 dummy, t2, doc);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
647
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
648 if (!is)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
649 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
650 error ("load: failed to load anonymous function handle");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
651 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
652 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
653
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16170
diff changeset
654 symbol_table::assign (name, t2, local_scope);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
655 }
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 if (is && success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
659 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
660 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
661 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
662 eval_string (ctmp2, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
663
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
664 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
665 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
666 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
667
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
668 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
669 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
670 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
671
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
672 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
673
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
674 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
675 symbol_table::cache_name (uf->scope (), nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
676 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
677 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
678 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
679 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
680 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
681 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
682 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
683 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
684 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
685 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
686 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
687 std::string fpath;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
688
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
689 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
690 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
691 size_t pos1 = nm.find_first_of ("\n");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
692 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
693 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
694 fpath = nm.substr (pos2 + 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
695 nm = nm.substr (0, pos1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
696 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
697
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
698 success = set_fcn (octaveroot, fpath);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
699 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
700
12714
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
701 return success;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
702 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
703
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
704 #if defined (HAVE_HDF5)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
705 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
706 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
707 bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
708 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
709 bool retval = true;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
710
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
711 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
712 #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
713 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
714 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
715 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
716 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
717 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
718 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
719
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
720 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
721
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
722 // attach the type of the variable
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
723 type_hid = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
724 H5Tset_size (type_hid, nm.length () + 1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
725 if (type_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
726 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
727 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
728 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
729 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
730
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
731 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
732 hdims[0] = 0;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
733 hdims[1] = 0;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
734 space_hid = H5Screate_simple (0 , hdims, 0);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
735 if (space_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
736 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
737 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
738 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
739 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
740 }
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
741 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
742 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
743 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
744 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
745 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
746 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
747 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
748 H5P_DEFAULT, nm.c_str ()) < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
749 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
750 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
751 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
752 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
753 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
754 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
755 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
756
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
757 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
758 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
759 std::ostringstream buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
760 print_raw (buf, true);
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
761 std::string stmp = buf.str ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
762
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
763 // attach the type of the variable
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
764 H5Tset_size (type_hid, stmp.length () + 1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
765 if (type_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
766 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
767 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
768 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
769 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
770 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
771
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
772 #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
773 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
774 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
775 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
776 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
777 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
778 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
779 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
780 H5P_DEFAULT, stmp.c_str ()) < 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
781 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
782 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
783 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
784 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
785 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
786 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
787
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
788 H5Dclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
789
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
790 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
791
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
792 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
793 = symbol_table::all_variables (f->scope (), 0);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
794
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
795 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
796
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
797 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
798 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
799 hid_t as_id = H5Screate (H5S_SCALAR);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
800
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
801 if (as_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
802 {
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
803 #if HAVE_HDF5_18
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
804 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE",
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
805 H5T_NATIVE_IDX, as_id,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
806 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
807
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
808 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
809 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
810 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
811 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
812
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
813 if (a_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
814 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
815 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
816
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
817 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
818 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
819 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
820 retval = false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
821
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
822 H5Sclose (as_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
823 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
824 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
825 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
826 #if HAVE_HDF5_18
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
827 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
828 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
829 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
830 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
831 if (data_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
832 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
833 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
834 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
835 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
836 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
837 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
838
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
839 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
840 p != vars.end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
841 {
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
842 if (! add_hdf5_data (data_hid, p->varval (0), p->name (),
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
843 "", false, save_as_floats))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
844 break;
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 H5Gclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
847 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
848 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
849 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
850 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
851 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
852
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
853 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
854 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
855
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
856 H5Sclose (space_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
857 hdims[0] = 1;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
858 hdims[1] = octaveroot.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
859 space_hid = H5Screate_simple (0 , hdims, 0);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
860 if (space_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
861 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
862 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
863 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
864 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
865 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
866
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
867 H5Tclose (type_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
868 type_hid = H5Tcopy (H5T_C_S1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
869 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
870 #if HAVE_HDF5_18
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
871 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
872 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
873 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
874 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
875 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
876 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
877
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
878 if (a_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
879 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
880 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
881
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
882 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
883 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
884 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
885 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
886 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
887 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
888 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
889 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
890 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
891
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
892 H5Sclose (space_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
893 hdims[0] = 1;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
894 hdims[1] = fpath.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
895 space_hid = H5Screate_simple (0 , hdims, 0);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
896 if (space_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
897 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
898 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
899 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
900 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
901 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
902
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
903 H5Tclose (type_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
904 type_hid = H5Tcopy (H5T_C_S1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
905 H5Tset_size (type_hid, fpath.length () + 1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
906
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
907 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
908 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
909 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
910 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
911 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
912 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
913
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
914 if (a_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
915 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
916 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
917
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
918 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
919 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
920 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
921 retval = false;
4988
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
924 H5Sclose (space_hid);
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 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
927
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
928 return retval;
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 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9601
diff changeset
932 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
933 {
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
934 bool success = true;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
935
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
936 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
937 hsize_t rank;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
938 int slen;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
939
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
940 #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
941 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
942 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
943 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
944 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
945 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
946 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
947
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
948 #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
949 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
950 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
951 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
952 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
953
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
954 if (data_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
955 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
956 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
957 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
958 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
959
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
960 type_hid = H5Dget_type (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
961 type_class_hid = H5Tget_class (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
962
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
963 if (type_class_hid != H5T_STRING)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
964 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
965 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
966 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
967 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
968 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
969 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
970
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
971 space_hid = H5Dget_space (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
972 rank = H5Sget_simple_extent_ndims (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
973
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
974 if (rank != 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
975 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
976 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
977 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
978 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
979 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
980 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
981 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
982
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
983 slen = H5Tget_size (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
984 if (slen < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
985 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
986 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
987 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
988 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
989 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
990 return false;
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
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
993 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
994
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
995 // create datatype for (null-terminated) string to read into:
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
996 st_id = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
997 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
998
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
999 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
1000 {
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1001 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1002 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1003 H5Tclose (type_hid);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1004 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1005 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1006 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1007 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1008 H5Tclose (st_id);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1009 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1010 nm = nm_tmp;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1011
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1012 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1013 {
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
1014 #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
1015 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
1016 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1017 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
1018 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1019
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1020 if (data_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1021 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1022 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1023 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1024 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1025 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1026 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1027
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1028 H5Tclose (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1029 type_hid = H5Dget_type (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1030 type_class_hid = H5Tget_class (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1031
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1032 if (type_class_hid != H5T_STRING)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1033 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1034 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1035 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1036 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1037 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1038 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1039 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1040
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1041 H5Sclose (space_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1042 space_hid = H5Dget_space (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1043 rank = H5Sget_simple_extent_ndims (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1044
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1045 if (rank != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1046 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1047 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1048 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1049 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1050 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1051 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1052 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1053
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1054 slen = H5Tget_size (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1055 if (slen < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1056 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1057 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1058 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1059 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1060 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1061 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1062 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1063
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1064 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1065
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1066 // create datatype for (null-terminated) string to read into:
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1067 st_id = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1068 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1069
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
1070 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
1071 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1072 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1073 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1074 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1075 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1076 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1077 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1078 }
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1079 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1080 H5Dclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1081
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1082 octave_idx_type len = 0;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1083
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1084 // 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
1085 // 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
1086 // call H5Aopen for a non-existing attribute
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1087
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1088 H5E_auto_t err_func;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1089 void *err_func_data;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1090
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1091 // turn off error reporting temporarily, but save the error
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1092 // 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
1093 #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
1094 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
1095 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
1096 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1097 H5Eget_auto (&err_func, &err_func_data);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1098 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
1099 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1100
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1101 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
1102
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1103 if (attr_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1104 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1105 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
1106 success = false;
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 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1109 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1110
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1111 // 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
1112 #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
1113 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
1114 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1115 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
1116 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1117
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1118 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
1119
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1120 // 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
1121 // 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
1122
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
1123 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
1124 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
1125
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1126 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
1127
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1128 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1129 frame.add_fcn (octave_call_stack::pop);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
1130
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1131 if (len > 0 && success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1132 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1133 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
1134 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1135 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
1136 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1137 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
1138 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1139 H5Gget_num_objs (data_hid, &num_obj);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1140 H5Gclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1141
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1142 if (num_obj != static_cast<hsize_t>(len))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1143 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1144 error ("load: failed to load anonymous function handle");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1145 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1146 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1147
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1148 if (! error_state)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1149 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1150 hdf5_callback_data dsub;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1151 int current_item = 0;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1152 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
1153 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1154 if (H5Giterate (group_hid, "symbol table", &current_item,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1155 hdf5_read_next_data, &dsub) <= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1156 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1157 error ("load: failed to load anonymous function handle");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1158 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1159 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1160 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1161
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16170
diff changeset
1162 symbol_table::assign (dsub.name, dsub.tc, local_scope);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1163 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1164 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1165 }
6625
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 if (success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1168 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1169 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1170 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1171 eval_string (fcn_tmp, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1172
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1173 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1174 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1175 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
1176
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1177 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1178 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1179 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
1180
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1181 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
1182
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1183 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1184 symbol_table::cache_name (uf->scope (), nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1185 }
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 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1188 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1189 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1190 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1191 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1192
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1193 frame.run ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1194 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1195 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1196 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1197 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1198 std::string fpath;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1199
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1200 // 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
1201 // 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
1202 // call H5Aopen for a non-existing attribute
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1203
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1204 H5E_auto_t err_func;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1205 void *err_func_data;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1206
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1207 // turn off error reporting temporarily, but save the error
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1208 // 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
1209 #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
1210 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
1211 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
1212 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1213 H5Eget_auto (&err_func, &err_func_data);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1214 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
1215 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1216
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1217 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT");
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1218 if (attr_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1219 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1220 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1221 type_hid = H5Aget_type (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1222 type_class_hid = H5Tget_class (type_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1223
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1224 if (type_class_hid != H5T_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1225 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1226 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1227 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1228 slen = H5Tget_size (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1229 st_id = H5Tcopy (H5T_C_S1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1230 H5Tset_size (st_id, slen);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1231 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1232
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1233 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
1234 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1235 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1236 octaveroot = root_tmp;
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1237
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1238 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1239 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1240
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1241 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1242 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1243
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1244 if (success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1245 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1246 attr_id = H5Aopen_name (group_hid, "FILE");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1247 if (attr_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1248 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1249 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1250 type_hid = H5Aget_type (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1251 type_class_hid = H5Tget_class (type_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1252
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1253 if (type_class_hid != H5T_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1254 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1255 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1256 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1257 slen = H5Tget_size (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1258 st_id = H5Tcopy (H5T_C_S1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1259 H5Tset_size (st_id, slen);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1260 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1261
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1262 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
1263 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1264 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1265 fpath = path_tmp;
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1266
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1267 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1268 }
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1269
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1270 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1271 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1272 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1273
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1274 // 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
1275 #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
1276 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
1277 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1278 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
1279 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1280
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1281 success = (success ? set_fcn (octaveroot, fpath) : success);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1282 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1283
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1284 H5Tclose (type_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1285 H5Sclose (space_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1286 H5Gclose (group_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1287
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1288 return success;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1289 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1290
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1291 #endif
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1292
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1293 /*
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1294 %!test
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1295 %! a = 2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1296 %! f = @(x) a + x;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1297 %! g = @(x) 2 * x;
11541
28bae9cd7ea9 ov-fcn-handle.cc: use version instead of flops in test
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
1298 %! hm = @version;
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
1299 %! hdld = @svd;
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1300 %! hbi = @log2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1301 %! f2 = f;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1302 %! g2 = g;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1303 %! hm2 = hm;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1304 %! hdld2 = hdld;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1305 %! hbi2 = hbi;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1306 %! modes = {"-text", "-binary"};
16170
2a4f83826024 new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents: 15572
diff changeset
1307 %! if (isfield (octave_config_info, "HAVE_HDF5")
2a4f83826024 new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents: 15572
diff changeset
1308 %! && octave_config_info ("HAVE_HDF5"))
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1309 %! modes(end+1) = "-hdf5";
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1310 %! endif
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
1311 %! for i = 1:numel (modes)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
1312 %! mode = modes{i};
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1313 %! nm = tmpnam ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1314 %! unwind_protect
15572
859c8bf6d134 Fix saved struct with function handle fails to load (bug #33857)
Max Brister <max@2bass.com>
parents: 15235
diff changeset
1315 %! f2 (1); # bug #33857
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1316 %! 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
1317 %! clear f2 g2 hm2 hdld2 hbi2
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1318 %! load (nm);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1319 %! assert (f (2), f2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1320 %! assert (g (2), g2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1321 %! assert (g (3), g2 (3));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1322 %! unlink (nm);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1323 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1324 %! unwind_protect_cleanup
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1325 %! unlink (nm);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1326 %! end_unwind_protect
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1327 %! endfor
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1328 */
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1329
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1330 /*
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1331 %!function fcn_handle_save_recurse (n, mode, nm, f2, g2, hm2, hdld2, hbi2)
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16442
diff changeset
1332 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1333 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1334 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1335 %! fcn_handle_save_recurse (n - 1, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1336 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1337 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1338 %!function [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n, nm)
16933
e39f00a32dc7 maint: Use parentheses around condition for switch(),while(),if() statements.
Rik <rik@octave.org>
parents: 16442
diff changeset
1339 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1340 %! load (nm)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1341 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1342 %! [f2, g2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (n - 1, nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1343 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1344 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1345
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1346 Test for bug #35876
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1347 %!test
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1348 %! a = 2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1349 %! f = @(x) a + x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1350 %! g = @(x) 2 * x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1351 %! hm = @version;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1352 %! hdld = @svd;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1353 %! hbi = @log2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1354 %! f2 = f;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1355 %! g2 = g;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1356 %! hm2 = hm;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1357 %! hdld2 = hdld;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1358 %! hbi2 = hbi;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1359 %! modes = {"-text", "-binary"};
16170
2a4f83826024 new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents: 15572
diff changeset
1360 %! if (isfield (octave_config_info, "HAVE_HDF5")
2a4f83826024 new way to test for features in Octave scripts
John W. Eaton <jwe@octave.org>
parents: 15572
diff changeset
1361 %! && octave_config_info ("HAVE_HDF5"))
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1362 %! modes(end+1) = "-hdf5";
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1363 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1364 %! for i = 1:numel (modes)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1365 %! mode = modes{i};
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1366 %! nm = tmpnam ();
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1367 %! unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1368 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1369 %! clear f2 g2 hm2 hdld2 hbi2
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1370 %! [f2, f2, hm2, hdld2, hbi2] = fcn_handle_load_recurse (2, nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1371 %! load (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1372 %! assert (f (2), f2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1373 %! assert (g (2), g2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1374 %! assert (g (3), g2 (3));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1375 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1376 %! fcn_handle_save_recurse (2, mode, nm, f2, g2, hm2, hdld2, hbi2);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1377 %! unwind_protect_cleanup
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1378 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1379 %! end_unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1380 %! endfor
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1381 */
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1382
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1383 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1384 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
1385 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1386 print_raw (os, pr_as_read_syntax);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1387 newline (os);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1388 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1389
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1390 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1391 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
1392 {
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1393 bool printed = false;
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1394
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1395 if (nm == anonymous)
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1396 {
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1397 tree_print_code tpc (os);
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1398
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
1399 // 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
1400 // 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
1401
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1402 octave_value ftmp = fcn;
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1403
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1404 octave_user_function *f = ftmp.user_function_value ();
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1405
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1406 if (f)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1407 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1408 tree_parameter_list *p = f->parameter_list ();
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1409
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1410 os << "@(";
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1411
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1412 if (p)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1413 p->accept (tpc);
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1414
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1415 os << ") ";
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1416
11223
64e7538db12a fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents: 11220
diff changeset
1417 tpc.print_fcn_handle_body (f->body ());
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1418
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1419 printed = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1420 }
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1421 }
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1422
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1423 if (! printed)
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1424 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
1425 current_print_indent_level ());
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1426 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1427
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1428 octave_value
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1429 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
1430 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1431 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1432
9342
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1433 // 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
1434
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1435 // 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
1436 // 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
1437 // 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
1438 // 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
1439
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 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
1441
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1442 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
1443
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1444 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
1445 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
1446 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
1447 {
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1448 if (nm[0] == '.')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1449 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1450 switch (nm[1])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1451 {
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 = "transpose";
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 = "plus";
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 = "minus";
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 = "times";
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 = "rdivide";
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 = "power";
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 = "ldivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1478 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1479 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1480 }
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
1481 else if (nm[1] == '=')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1482 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1483 switch (nm[0])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1484 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1485 case '<':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1486 tnm = "le";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1487 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
1488
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1489 case '=':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1490 tnm = "eq";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1491 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
1492
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1493 case '>':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1494 tnm = "ge";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1495 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
1496
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1497 case '~':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1498 case '!':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1499 tnm = "ne";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1500 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1501 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1502 }
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
1503 else if (nm == "**")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1504 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
1505 }
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1506 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
1507 {
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1508 switch (nm[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1509 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1510 case '~':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1511 case '!':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1512 tnm = "not";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1513 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
1514
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1515 case '\'':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1516 tnm = "ctranspose";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1517 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
1518
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1519 case '+':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1520 tnm = "plus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1521 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
1522
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1523 case '-':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1524 tnm = "minus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1525 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
1526
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1527 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1528 tnm = "mtimes";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1529 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
1530
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1531 case '/':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1532 tnm = "mrdivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1533 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
1534
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1535 case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1536 tnm = "mpower";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1537 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
1538
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1539 case '\\':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1540 tnm = "mldivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1541 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
1542
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1543 case '<':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1544 tnm = "lt";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1545 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
1546
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1547 case '>':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1548 tnm = "gt";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1549 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
1550
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1551 case '&':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1552 tnm = "and";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1553 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
1554
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1555 case '|':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1556 tnm = "or";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1557 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1558 }
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
1559 }
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
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1561 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
1562 local_funcs);
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 11060
diff changeset
1563
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1564 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
1565
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 11060
diff changeset
1566 // Here we are just looking to see if FCN is a method or constructor
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 11060
diff changeset
1567 // for any class.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1568 if (local_funcs && fptr
11461
2b8531a6a3c9 Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents: 11223
diff changeset
1569 && (fptr->is_subfunction () || fptr->is_private_function ()
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1570 || fptr->is_class_constructor ()))
9458
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1571 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1572 // Locally visible function.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1573 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
1574 }
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1575 else
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1576 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1577 // Globally visible (or no match yet). Query overloads.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1578 std::list<std::string> classes = load_path::overloads (tnm);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1579 bool any_match = fptr != 0 || classes.size () > 0;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1580 if (! any_match)
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1581 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1582 // 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
1583 load_path::update ();
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1584 classes = load_path::overloads (tnm);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1585 any_match = classes.size () > 0;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1586 }
9458
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1587
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1588 if (any_match)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1589 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1590 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1591 retval = fh;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1592
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1593 for (std::list<std::string>::iterator iter = classes.begin ();
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1594 iter != classes.end (); iter++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1595 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1596 std::string class_name = *iter;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1597 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
1598
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1599 bool is_builtin = false;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1600 for (int i = 0; i < btyp_num_types; i++)
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1601 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1602 // FIXME: Too slow? Maybe binary lookup?
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1603 if (class_name == btyp_class_name[i])
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1604 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1605 is_builtin = true;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1606 fh->set_overload (static_cast<builtin_type_t> (i), fmeth);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1607 }
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1608 }
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1609
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1610 if (! is_builtin)
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1611 fh->set_overload (class_name, fmeth);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1612 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1613 }
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1614 else
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1615 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
1616 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1617
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1618 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1619 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1620
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
1621 /*
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1622 %!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
1623 %! 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
1624 %! ".'", "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
1625 %! ".+", "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
1626 %! ".-", "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
1627 %! ".*", "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
1628 %! "./", "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
1629 %! ".^", "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
1630 %! ".\\", "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
1631 %! "<=", "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
1632 %! "==", "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
1633 %! ">=", "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
1634 %! "~=", "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
1635 %! "!=", "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
1636 %! "**", "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
1637 %! "~", "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
1638 %! "!", "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
1639 %! "\'", "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
1640 %! "+", "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
1641 %! "-", "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
1642 %! "*", "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
1643 %! "/", "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
1644 %! "^", "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
1645 %! "\\", "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
1646 %! "<", "lt";
9343
70e0d3b1f26f fix typos in previous change
John W. Eaton <jwe@octave.org>
parents: 9342
diff changeset
1647 %! ">", "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
1648 %! "&", "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
1649 %! "|", "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
1650 %! for i = 1:rows (x)
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1651 %! assert (functions (str2func (x{i,1})).function, x{i,2});
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
1652 %! 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
1653 */
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1654
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1655 DEFUN (functions, args, ,
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1656 "-*- texinfo -*-\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1657 @deftypefn {Built-in Function} {} functions (@var{fcn_handle})\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1658 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
1659 @var{fcn_handle}.\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1660 @end deftypefn")
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1661 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1662 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1663
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1664 if (args.length () == 1)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1665 {
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1666 octave_fcn_handle *fh = args(0).fcn_handle_value ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1667
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1668 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1669 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1670 octave_function *fcn = fh ? fh->function_value () : 0;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1671
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1672 if (fcn)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1673 {
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1674 octave_scalar_map m;
4649
f7ce581b27fb [project @ 2003-11-23 21:46:44 by jwe]
jwe
parents: 4612
diff changeset
1675
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1676 std::string fh_nm = fh->fcn_name ();
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1677
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1678 if (fh_nm == octave_fcn_handle::anonymous)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1679 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1680 std::ostringstream buf;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1681 fh->print_raw (buf);
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1682 m.setfield ("function", buf.str ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1683
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1684 m.setfield ("type", "anonymous");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1685 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1686 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1687 {
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1688 m.setfield ("function", fh_nm);
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1689
11461
2b8531a6a3c9 Change mentions of "nested function" to the less misleading "subfunction"
David Grundberg <individ@acc.umu.se>
parents: 11223
diff changeset
1690 if (fcn->is_subfunction ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1691 {
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1692 m.setfield ("type", "subfunction");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1693 Cell parentage (dim_vector (1, 2));
14861
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1694 parentage.elem (0) = fh_nm;
f7afecdd87ef maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents: 14846
diff changeset
1695 parentage.elem (1) = fcn->parent_fcn_name ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1696 m.setfield ("parentage", octave_value (parentage));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1697 }
9509
c5330ef7aecd fix handles to private functions, simplify out-of-date checks in symtab
Jaroslav Hajek <highegg@gmail.com>
parents: 9466
diff changeset
1698 else if (fcn->is_private_function ())
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1699 m.setfield ("type", "private");
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1700 else if (fh->is_overloaded ())
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1701 m.setfield ("type", "overloaded");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1702 else
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1703 m.setfield ("type", "simple");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1704 }
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1705
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1706 std::string nm = fcn->fcn_file_name ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1707
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1708 if (fh_nm == octave_fcn_handle::anonymous)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1709 {
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1710 m.setfield ("file", nm);
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1711
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1712 octave_user_function *fu = fh->user_function_value ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1713
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1714 std::list<symbol_table::symbol_record> vars
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1715 = 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
1716
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1717 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1718
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1719 if (varlen > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1720 {
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1721 octave_scalar_map ws;
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1722 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
1723 p != vars.end (); p++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1724 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1725 ws.assign (p->name (), p->varval (0));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1726 }
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1727
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1728 m.setfield ("workspace", ws);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1729 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1730 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1731 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
1732 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1733 octave_function *fu = fh->function_value ();
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1734 m.setfield ("file", fu->fcn_file_name ());
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1735 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1736 else
11060
54697b37d8bf replace Octave_map->octave_scalar_map in oct-parse.yy and ov-fcn-handle.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 11029
diff changeset
1737 m.setfield ("file", "");
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1738
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1739 retval = m;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1740 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1741 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1742 error ("functions: FCN_HANDLE is not a valid function handle object");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1743 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1744 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1745 error ("functions: FCN_HANDLE argument must be a function handle object");
4343
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 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1748 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1749
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1750 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1751 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1752
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1753 DEFUN (func2str, args, ,
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1754 "-*- texinfo -*-\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1755 @deftypefn {Built-in Function} {} func2str (@var{fcn_handle})\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1756 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
1757 the function handle @var{fcn_handle}.\n\
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1758 @end deftypefn")
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1759 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1760 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1761
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1762 if (args.length () == 1)
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4925
diff changeset
1763 {
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1764 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
1765
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1766 if (! error_state && fh)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1767 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1768 std::string fh_nm = fh->fcn_name ();
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1769
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1770 if (fh_nm == octave_fcn_handle::anonymous)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1771 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1772 std::ostringstream buf;
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1773
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1774 fh->print_raw (buf);
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1775
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1776 retval = buf.str ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1777 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1778 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1779 retval = fh_nm;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1780 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1781 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1782 error ("func2str: FCN_HANDLE must be a valid function handle");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1783 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1784 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1785 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1786
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1787 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1788 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1789
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1790 DEFUN (str2func, args, ,
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1791 "-*- texinfo -*-\n\
10840
89f4d7e294cc Grammarcheck .cc files
Rik <octave@nomad.inbox5.com>
parents: 10322
diff changeset
1792 @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
1793 @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
1794 Return a function handle constructed from the string @var{fcn_name}.\n\
17281
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16933
diff changeset
1795 If the optional @qcode{\"global\"} argument is passed, locally visible\n\
bc924baa2c4e doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents: 16933
diff changeset
1796 functions are ignored in the lookup.\n\
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1797 @end deftypefn")
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1798 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1799 octave_value retval;
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1800 int nargin = args.length ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1801
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1802 if (nargin == 1 || nargin == 2)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1803 {
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1804 std::string nm = args(0).string_value ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1805
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1806 if (! error_state)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1807 retval = make_fcn_handle (nm, nargin != 2);
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1808 else
12483
7a5aacf65f81 Rewrite error strings in src/ to use variables named in documentation.
Rik <octave@nomad.inbox5.com>
parents: 11586
diff changeset
1809 error ("str2func: FCN_NAME must be a string");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1810 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1811 else
5823
080c08b192d8 [project @ 2006-05-19 05:32:17 by jwe]
jwe
parents: 5775
diff changeset
1812 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1813
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1814 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1815 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1816
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1817 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1818 %!function y = __testrecursionfunc (f, x, n)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1819 %! if (nargin < 3)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1820 %! n = 0;
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1821 %! endif
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1822 %! if (n > 2)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1823 %! y = f (x);
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1824 %! else
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1825 %! n++;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1826 %! y = __testrecursionfunc (@(x) f (2*x), x, n);
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1827 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1828 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1829 %!
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1830 %!assert (__testrecursionfunc (@(x) x, 1), 8)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1831 */
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1832
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1833 DEFUN (is_function_handle, args, ,
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1834 "-*- texinfo -*-\n\
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1835 @deftypefn {Built-in Function} {} is_function_handle (@var{x})\n\
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1836 Return true if @var{x} is a function handle.\n\
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1837 @seealso{isa, typeinfo, class}\n\
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1838 @end deftypefn")
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1839 {
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1840 octave_value retval;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1841
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1842 int nargin = args.length ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1843
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1844 if (nargin == 1)
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1845 retval = args(0).is_function_handle ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1846 else
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1847 print_usage ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1848
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1849 return retval;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1850 }
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1851
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1852 /*
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1853 %!shared fh
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1854 %! fh = @(x) x;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1855
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1856 %!assert (is_function_handle (fh))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1857 %!assert (! is_function_handle ({fh}))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1858 %!assert (! is_function_handle (1))
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1859
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1860 %!error is_function_handle ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1861 %!error is_function_handle (1, 2)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1862 */
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1863
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1864 octave_fcn_binder::octave_fcn_binder (const octave_value& f,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1865 const octave_value& root,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1866 const octave_value_list& templ,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1867 const std::vector<int>& mask,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1868 int exp_nargin)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1869 : octave_fcn_handle (f), root_handle (root), arg_template (templ),
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1870 arg_mask (mask), expected_nargin (exp_nargin)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1871 {
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
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1874 octave_fcn_handle *
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1875 octave_fcn_binder::maybe_binder (const octave_value& f)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1876 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1877 octave_fcn_handle *retval = 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1878
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1879 octave_user_function *usr_fcn = f.user_function_value (false);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1880 tree_parameter_list *param_list = usr_fcn ? usr_fcn->parameter_list () : 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1881
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1882 // Verify that the body is a single expression (always true in theory).
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1883
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1884 tree_statement_list *cmd_list = usr_fcn ? usr_fcn->body () : 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1885 tree_expression *body_expr = (cmd_list->length () == 1
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1886 ? cmd_list->front ()->expression () : 0);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1887
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1888
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1889 if (body_expr && body_expr->is_index_expression ()
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1890 && ! (param_list && param_list->takes_varargs ()))
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1891 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1892 // It's an index expression.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1893 tree_index_expression *idx_expr = dynamic_cast<tree_index_expression *> (body_expr);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1894 tree_expression *head_expr = idx_expr->expression ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1895 std::list<tree_argument_list *> arg_lists = idx_expr->arg_lists ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1896 std::string type_tags = idx_expr->type_tags ();
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 if (type_tags.length () == 1 && type_tags[0] == '('
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1899 && head_expr->is_identifier ())
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 assert (arg_lists.size () == 1);
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 // It's a single index expression: a(x,y,....)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1904 tree_identifier *head_id = dynamic_cast<tree_identifier *> (head_expr);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1905 tree_argument_list *arg_list = arg_lists.front ();
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 // Build a map of input params to their position.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1908 std::map<std::string, int> arginmap;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1909 int npar = 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1910
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1911 if (param_list)
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 for (tree_parameter_list::iterator it = param_list->begin ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1914 it != param_list->end (); ++it, ++npar)
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 tree_decl_elt *elt = *it;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1917 tree_identifier *id = elt ? elt->ident () : 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1918 if (id && ! id->is_black_hole ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1919 arginmap[id->name ()] = npar;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1920 }
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 if (arg_list && arg_list->length () > 0)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1924 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1925 bool bad = false;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1926 int nargs = arg_list->length ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1927 octave_value_list arg_template (nargs);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1928 std::vector<int> arg_mask (nargs);
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 // 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
1931 int iarg = 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1932 for (tree_argument_list::iterator it = arg_list->begin ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1933 it != arg_list->end (); ++it, ++iarg)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1934 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1935 tree_expression *elt = *it;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1936 if (elt && elt->is_constant ())
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 arg_template(iarg) = elt->rvalue1 ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1939 arg_mask[iarg] = -1;
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 if (elt && elt->is_identifier ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1942 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1943 tree_identifier *elt_id = dynamic_cast<tree_identifier *> (elt);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1944 if (arginmap.find (elt_id->name ()) != arginmap.end ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1945 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1946 arg_mask[iarg] = arginmap[elt_id->name ()];
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1947 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1948 else if (elt_id->is_defined ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1949 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1950 arg_template(iarg) = elt_id->rvalue1 ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1951 arg_mask[iarg] = -1;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1952 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1953 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1954 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1955 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1956 break;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1957 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1958 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1959 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1960 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1961 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1962 break;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1963 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1964 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1965
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1966 octave_value root_val;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1967
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1968 if (! bad)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1969 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1970 // If the head is a value, use it as root.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1971 if (head_id->is_defined ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1972 root_val = head_id->rvalue1 ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1973 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1974 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1975 // It's a name.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1976 std::string head_name = head_id->name ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1977 // Function handles can't handle legacy dispatch, so
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1978 // we make sure it's not defined.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1979 if (symbol_table::get_dispatch (head_name).size () > 0)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1980 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1981 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1982 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1983 // Simulate try/catch.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1984 unwind_protect frame;
11029
4ab04ea74b08 make an internal function for try simulation
Jaroslav Hajek <highegg@gmail.com>
parents: 10961
diff changeset
1985 interpreter_try (frame);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1986
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1987 root_val = make_fcn_handle (head_name);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1988 if (error_state)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1989 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1990 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1991 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1992 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1993
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1994 if (! bad)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1995 {
10961
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
1996 // Stash proper name tags.
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
1997 std::list<string_vector> arg_names = idx_expr->arg_names ();
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
1998 assert (arg_names.size () == 1);
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
1999 arg_template.stash_name_tags (arg_names.front ());
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2000
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2001 retval = new octave_fcn_binder (f, root_val, arg_template,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2002 arg_mask, npar);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2003 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2004 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2005 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2006 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2007
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2008 if (! retval)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2009 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2010
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2011 return retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2012 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2013
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2014 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2015 octave_fcn_binder::do_multi_index_op (int nargout,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2016 const octave_value_list& args)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2017 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2018 return do_multi_index_op (nargout, args, 0);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2019 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2020
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2021 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2022 octave_fcn_binder::do_multi_index_op (int nargout,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2023 const octave_value_list& args,
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2024 const std::list<octave_lvalue>* lvalue_list)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2025 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2026 octave_value_list retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2027
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2028 if (args.length () == expected_nargin)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2029 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2030 for (int i = 0; i < arg_template.length (); i++)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2031 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2032 int j = arg_mask[i];
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2033 if (j >= 0)
10961
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2034 arg_template(i) = args(j); // May force a copy...
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2035 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2036
10961
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2037 // Make a shallow copy of arg_template, to ensure consistency throughout the following
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2038 // call even if we happen to get back here.
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2039 octave_value_list tmp (arg_template);
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2040 retval = root_handle.do_multi_index_op (nargout, tmp, lvalue_list);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2041 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2042 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2043 retval = octave_fcn_handle::do_multi_index_op (nargout, args, lvalue_list);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2044
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2045 return retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2046 }
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2047
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2048 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
2049 %!function r = __f (g, i)
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2050 %! r = g(i);
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2051 %!endfunction
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2052 %!test
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2053 %! x = [1,2;3,4];
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
2054 %! assert (__f (@(i) x(:,i), 1), [1;3]);
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2055 */