annotate libinterp/octave-value/ov-fcn-handle.cc @ 22407:34ce5be04942

maint: Style check C++ code in libinterp/. * build-env.h, build-env.in.cc, builtins.h, Cell.cc, Cell.h, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ilu__.cc, __lin_interpn__.cc, __luinc__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, base-text-renderer.h, besselj.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, call-stack.cc, call-stack.h, cdisplay.c, cdisplay.h, cellfun.cc, coct-hdf5-types.c, comment-list.cc, comment-list.h, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, debug.h, defaults.cc, defaults.in.h, defun-dld.h, defun-int.h, defun.h, det.cc, dirfns.cc, dirfns.h, display.cc, display.h, dlmread.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, error.cc, error.h, errwarn.h, event-queue.cc, event-queue.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, file-io.h, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics.cc, graphics.in.h, gripes.h, gsvd.cc, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter.cc, interpreter.h, inv.cc, jit-ir.cc, jit-ir.h, jit-typeinfo.cc, jit-typeinfo.h, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-hdf5.cc, ls-hdf5.h, ls-mat-ascii.cc, ls-mat-ascii.h, ls-mat4.cc, ls-mat4.h, ls-mat5.h, ls-oct-binary.cc, ls-oct-binary.h, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, matrix_type.cc, max.cc, mex.cc, mex.h, mexproto.h, mgorth.cc, mxarray.in.h, nproc.cc, oct-errno.h, oct-errno.in.cc, oct-fstrm.cc, oct-fstrm.h, oct-handle.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hdf5.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-lvalue.cc, oct-lvalue.h, oct-map.h, oct-obj.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct.h, octave-default-image.h, octave-link.h, octave-preserve-stream-state.h, ordschur.cc, pager.cc, pager.h, pinv.cc, pr-output.cc, pr-output.h, procstream.cc, procstream.h, profiler.h, psi.cc, pt-jit.cc, pt-jit.h, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, toplev.h, tril.cc, tsearch.cc, txt-eng.cc, txt-eng.h, typecast.cc, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, workspace-element.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, zfstream.cc, zfstream.h, deprecated-config.h, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, gzip.cc, oct-qhull.h, qr.cc, symbfact.cc, symrcm.cc, liboctinterp-build-info.h, liboctinterp-build-info.in.cc, ov-base-diag.h, ov-base-int.cc, ov-base-int.h, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.h, ov-base-sparse.cc, ov-base-sparse.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-mat.h, ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h, ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.cc, ov-ch-mat.h, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-colon.cc, ov-colon.h, ov-complex.cc, ov-complex.h, ov-cs-list.h, ov-cx-diag.cc, ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc, ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.cc, ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc, ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h, ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc, ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int-traits.h, ov-int16.cc, ov-int16.h, ov-int32.cc, ov-int32.h, ov-int64.cc, ov-int64.h, ov-int8.cc, ov-int8.h, ov-intx.h, ov-java.cc, ov-java.h, ov-lazy-idx.cc, ov-lazy-idx.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-null-mat.cc, ov-null-mat.h, ov-oncleanup.cc, ov-oncleanup.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc, ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h, ov-typeinfo.cc, ov-typeinfo.h, ov-uint16.cc, ov-uint16.h, ov-uint32.cc, ov-uint32.h, ov-uint64.cc, ov-uint64.h, ov-uint8.cc, ov-uint8.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.h, ovl.cc, ovl.h, octave.cc, octave.h, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-pm.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-dm-template.cc, op-dms-template.cc, op-fcdm-fcdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcm-pm.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fm-pm.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int.h, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-pm.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-cm.cc, op-pm-fcm.cc, op-pm-fm.cc, op-pm-m.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-pm-template.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, ops.h, options-usage.h, lex.h, parse.h, pt-all.h, pt-arg-list.cc, pt-arg-list.h, pt-array-list.h, pt-assign.cc, pt-assign.h, pt-binop.cc, pt-binop.h, pt-bp.cc, pt-bp.h, pt-cbinop.cc, pt-cbinop.h, pt-cell.cc, pt-cell.h, pt-check.cc, pt-check.h, pt-classdef.cc, pt-classdef.h, pt-cmd.cc, pt-cmd.h, pt-colon.cc, pt-colon.h, pt-const.cc, pt-const.h, pt-decl.cc, pt-decl.h, pt-eval.cc, pt-eval.h, pt-except.cc, pt-except.h, pt-exp.cc, pt-exp.h, pt-fcn-handle.cc, pt-fcn-handle.h, pt-funcall.cc, pt-funcall.h, pt-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, pt-jump.cc, pt-jump.h, pt-loop.cc, pt-loop.h, pt-mat.cc, pt-mat.h, pt-misc.cc, pt-misc.h, pt-pr-code.cc, pt-pr-code.h, pt-select.cc, pt-select.h, pt-stmt.cc, pt-stmt.h, pt-unop.cc, pt-unop.h, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Array-jit.cc, Array-tc.cc, version.cc, version.in.h: Style check C++ code in libinterp/
author Rik <rik@octave.org>
date Tue, 30 Aug 2016 21:46:47 -0700
parents d0562b3159c7
children 48c00363dc74
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
22323
bac0d6f07a3e maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents: 22105
diff changeset
3 Copyright (C) 2003-2016 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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
26 # include "config.h"
4343
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>
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
30 #include <list>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
31 #include <sstream>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5105
diff changeset
32 #include <vector>
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
33
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
34 #include "file-ops.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
35 #include "oct-locbuf.h"
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
36
22091
0f6fc2ec3b1a move call_stack class to a separate file
John W. Eaton <jwe@octave.org>
parents: 22028
diff changeset
37 #include "call-stack.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
38 #include "defun.h"
4654
a9b22513b7a6 [project @ 2003-11-24 18:56:35 by jwe]
jwe
parents: 4649
diff changeset
39 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21079
diff changeset
40 #include "errwarn.h"
5663
775e065f7dc4 [project @ 2006-03-13 21:30:06 by jwe]
jwe
parents: 5313
diff changeset
41 #include "input.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
42 #include "interpreter.h"
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
43 #include "oct-hdf5.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
44 #include "oct-map.h"
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
45 #include "ov-base.h"
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
46 #include "ov-fcn-handle.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
47 #include "ov-usr-fcn.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
48 #include "pr-output.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
49 #include "pt-pr-code.h"
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
50 #include "pt-misc.h"
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
51 #include "pt-stmt.h"
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
52 #include "pt-cmd.h"
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
53 #include "pt-exp.h"
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
54 #include "pt-assign.h"
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
55 #include "pt-arg-list.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
56 #include "variables.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
57 #include "parse.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
58 #include "unwind-prot.h"
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
59 #include "defaults.h"
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
60 #include "file-stat.h"
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
61 #include "load-path.h"
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
62 #include "oct-env.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
63
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
64 #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
65 #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
66 #include "ls-hdf5.h"
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20435
diff changeset
67 #include "ls-oct-text.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
68 #include "ls-oct-binary.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
69 #include "ls-utils.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
70
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
71
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4346
diff changeset
72 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
73 "function handle",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
74 "function_handle");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
75
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
76 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
77
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
78 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
79 const std::string& n)
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
80 : fcn (f), nm (n), has_overloads (false)
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
81 {
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
82 octave_user_function *uf = fcn.user_function_value (true);
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
83
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
84 if (uf && nm != anonymous)
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
85 symbol_table::cache_name (uf->scope (), nm);
14544
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14429
diff changeset
86
be18c9e359bf Nested function support (bug #35772)
Max Brister <max@2bass.com>
parents: 14429
diff changeset
87 if (uf && uf->is_nested_function ())
20428
7ac907da9fba Use error() rather than ::error() unless explicitly required.
Rik <rik@octave.org>
parents: 20163
diff changeset
88 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
89 }
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
90
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
91 octave_value_list
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
92 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
93 const std::list<octave_value_list>& idx,
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
94 int nargout)
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
95 {
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
96 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
97 }
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
98
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
99 octave_value_list
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
100 octave_fcn_handle::subsref (const std::string& type,
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
101 const std::list<octave_value_list>& idx,
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
102 int nargout,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
103 const std::list<octave_lvalue>* lvalue_list)
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
104 {
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
105 octave_value_list retval;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
106
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
107 switch (type[0])
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
108 {
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
109 case '(':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
110 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
111 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
112
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
113 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
114 idx.size () == 1 ? lvalue_list : 0);
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
115 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
116 break;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
117
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
118 case '{':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
119 case '.':
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
120 {
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
121 std::string tnm = type_name ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
122 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
123 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
124 break;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
125
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
126 default:
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
127 panic_impossible ();
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
128 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
129
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
130 // FIXME: perhaps there should be an
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
131 // octave_value_list::next_subsref member function? See also
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
132 // octave_builtin::subsref.
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
133
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
134 if (idx.size () > 1)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
135 retval = retval(0).next_subsref (nargout, type, idx);
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
136
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
137 return retval;
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
138 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
139
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
140 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
141 octave_fcn_handle::do_multi_index_op (int nargout,
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
142 const octave_value_list& args)
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
143 {
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
144 return do_multi_index_op (nargout, args, 0);
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
145 }
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
146
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
147 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
148 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
149 const octave_value_list& args,
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
150 const std::list<octave_lvalue>* lvalue_list)
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
151 {
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
152 octave_value_list retval;
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
153
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
154 out_of_date_check (fcn, "", false);
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
155
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
156 if (has_overloads)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
157 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
158 // Possibly overloaded function.
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
159 octave_value ov_fcn;
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 // Compute dispatch type.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
162 builtin_type_t btyp;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
163 std::string dispatch_type = get_dispatch_type (args, btyp);
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
164
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
165 // Retrieve overload.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
166 if (btyp != btyp_unknown)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
167 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
168 out_of_date_check (builtin_overloads[btyp], dispatch_type, false);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
169 ov_fcn = builtin_overloads[btyp];
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
170 }
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
171 else
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
172 {
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
173 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
174
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
175 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
176 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
177 // 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
178
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
179 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
180 = 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
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::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
183
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
184 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
185 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
186 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
187
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
188 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
189
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
190 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
191
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
192 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
193 {
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
194 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
195
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
196 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
197 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
198
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
199 break;
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
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
202 pit++;
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
203 }
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
204 }
a00ff5cedb9b also look to parent classes for overloaded functions called through handles
John W. Eaton <jwe@octave.org>
parents: 12714
diff changeset
205 else
9466
2ebd0717c12d also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9463
diff changeset
206 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
207 out_of_date_check (it->second, dispatch_type, false);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
208 ov_fcn = it->second;
9466
2ebd0717c12d also cache class dispatch lookups in function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9463
diff changeset
209 }
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
210 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
211
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
212 if (ov_fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
213 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
214 else if (fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
215 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
216 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
217 error ("%s: no method for class %s",
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
218 nm.c_str (), dispatch_type.c_str ());
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
219 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
220 else
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
221 {
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
222 // Non-overloaded function (anonymous, subfunction, private function).
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
223 if (fcn.is_defined ())
10849
f1a45913662a propagate isargout info through function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10840
diff changeset
224 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
225 else
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
226 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
227 }
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
228
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
229 return retval;
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
230 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
231
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
232 dim_vector
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
233 octave_fcn_handle::dims (void) const
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
234 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
235 static dim_vector dv (1, 1);
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
236 return dv;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
237 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
238
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
239 bool
10322
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
240 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
241 {
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
242 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
243 retval = retval && (overloads.size () == h.overloads.size ());
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 if (retval && has_overloads)
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
246 {
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
247 for (int i = 0; i < btyp_num_types && retval; i++)
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
248 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
249
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 str_ov_map::const_iterator iter = overloads.begin ();
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
251 str_ov_map::const_iterator hiter = h.overloads.begin ();
10322
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
252 for (; iter != overloads.end () && retval; iter++, hiter++)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
253 retval = (iter->first == hiter->first)
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
254 && (iter->second.is_copy_of (hiter->second));
10322
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
255 }
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
256
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
257 return retval;
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
258 }
21551cc88061 improve function handles comparison
Jaroslav Hajek <highegg@gmail.com>
parents: 10321
diff changeset
259
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
260 bool
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
261 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
262 const std::string& fpath)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
263 {
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
264 if (octaveroot.length () != 0
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
265 && fpath.length () >= octaveroot.length ()
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
266 && 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
267 && OCTAVE_EXEC_PREFIX != octaveroot)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
268 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
269 // 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
270 std::string str = OCTAVE_EXEC_PREFIX +
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
271 fpath.substr (octaveroot.length ());
21736
0504351a45e6 use namespace for file_stat classes
John W. Eaton <jwe@octave.org>
parents: 21733
diff changeset
272 octave::sys::file_stat fs (str);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
273
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
274 if (fs.exists ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
275 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
276 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
277
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
278 std::string dir_name = str.substr (0, xpos);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
279
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
280 octave_function *xfcn
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16442
diff changeset
281 = load_fcn_from_file (str, dir_name, "", "", nm);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
282
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
283 if (! xfcn)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
284 error ("function handle points to non-existent function");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
285
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
286 octave_value tmp (xfcn);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
287
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
288 fcn = octave_value (new octave_fcn_handle (tmp, nm));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
289 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
290 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
291 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
292 // Next just search for it anywhere in the system path
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
293 std::list<std::string> names;
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
294 names.push_back (nm + ".oct");
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
295 names.push_back (nm + ".mex");
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
296 names.push_back (nm + ".m");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
297
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
298 octave::directory_path p (load_path::system_path ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
299
21732
6a1eded90355 use namespace for system env class
John W. Eaton <jwe@octave.org>
parents: 21724
diff changeset
300 str = octave::sys::env::make_absolute (p.find_first_of (names));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
301
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
302 size_t xpos = str.find_last_of (octave::sys::file_ops::dir_sep_chars ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
303
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
304 std::string dir_name = str.substr (0, xpos);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
305
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16442
diff changeset
306 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
307
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
308 if (! xfcn)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
309 error ("function handle points to non-existent function");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
310
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
311 octave_value tmp (xfcn);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
312
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
313 fcn = octave_value (new octave_fcn_handle (tmp, nm));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
314 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
315 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
316 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
317 {
15005
74c7265c057a fix failure with function handles caused by changeset ea6997657614
John W. Eaton <jwe@octave.org>
parents: 15004
diff changeset
318 if (fpath.length () > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
319 {
21733
cb0fdd941d84 use namespace for system file_ops class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
320 size_t xpos = fpath.find_last_of (octave::sys::file_ops::dir_sep_chars ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
321
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
322 std::string dir_name = fpath.substr (0, xpos);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
323
16676
7368654f302f Initial support for (classdef) packages.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 16442
diff changeset
324 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
325
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
326 if (! xfcn)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
327 error ("function handle points to non-existent function");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
328
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
329 octave_value tmp (xfcn);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
330
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
331 fcn = octave_value (new octave_fcn_handle (tmp, nm));
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
332 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
333 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
334 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
335 fcn = symbol_table::find_function (nm);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
336
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
337 if (! fcn.is_function ())
20953
758b71e964ce maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20952
diff changeset
338 error ("function handle points to non-existent function");
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
339 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
340 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
341
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21102
diff changeset
342 return true;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
343 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
344
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
345 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6695
diff changeset
346 octave_fcn_handle::save_ascii (std::ostream& os)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
347 {
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
348 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
349 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
350 os << nm << "\n";
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
351
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
352 print_raw (os, true);
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
353 os << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
354
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
355 if (fcn.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
356 return false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
357
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
358 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
359
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
360 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
361 = symbol_table::all_variables (f->scope (), 0);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
362
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
363 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
364
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
365 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
366 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
367 os << "# length: " << varlen << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
368
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
369 for (std::list<symbol_table::symbol_record>::const_iterator
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
370 p = vars.begin (); p != vars.end (); p++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
371 {
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20435
diff changeset
372 if (! save_text_data (os, p->varval (0), p->name (), false, 0))
18384
bd9d34f28b0f Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents: 17898
diff changeset
373 return ! os.fail ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
374 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
375 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
376 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
377 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
378 {
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
379 octave_function *f = function_value ();
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
380 std::string fnm = f ? f->fcn_file_name () : "";
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
381
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
382 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
383 if (! fnm.empty ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
384 os << "# path: " << fnm << "\n";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
385 os << nm << "\n";
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
386 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
387
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
388 return true;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
389 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
390
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
391 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
392 octave_fcn_handle::load_ascii (std::istream& is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
393 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
394 bool success = true;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
395
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
396 std::streampos pos = is.tellg ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
397 std::string octaveroot = extract_keyword (is, "octaveroot", true);
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21867
diff changeset
398 if (octaveroot.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
399 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
400 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
401 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
402 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
403 pos = is.tellg ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
404 std::string fpath = extract_keyword (is, "path", true);
21885
0806871e3e1e maint: Prefer is_empty() rather than "length () == 0".
Rik <rik@octave.org>
parents: 21867
diff changeset
405 if (fpath.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
406 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
407 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
408 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
409 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
410
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
411 is >> nm;
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
412
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
413 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
414 {
8946
e7e928088e90 fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents: 8920
diff changeset
415 skip_preceeding_newline (is);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
416
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
417 std::string buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
418
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
419 if (is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
420 {
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
421
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
422 // 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
423 // newline in the stream.
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
424 buf = read_until_newline (is, true);
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
425
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
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
428 pos = is.tellg ();
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
429
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
430 octave::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
431
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
432 // 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
433 // 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
434
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
435 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
436 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
437
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
438 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
439
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
440 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
441 frame.add_fcn (octave_call_stack::pop);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
442
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
443 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
444
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
445 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
446 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
447 if (len > 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
448 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
449 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
450 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
451 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
452 bool dummy;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
453
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
454 std::string name
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
455 = read_text_data (is, "", dummy, t2, i);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
456
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20953
diff changeset
457 if (! is)
20956
850e3d2533d4 maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20955
diff changeset
458 error ("load: failed to load anonymous function handle");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
459
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16170
diff changeset
460 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
461 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
462 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
463 }
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
464 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
465 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
466 is.seekg (pos);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
467 is.clear ();
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
468 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
469
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
470 if (is && success)
10315
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 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
473 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
474 eval_string (buf, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
475
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
476 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
477 {
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
478 octave_fcn_handle *fh =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
479 anon_fcn_handle.fcn_handle_value ();
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
480
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
481 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
482 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
483 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
484
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
485 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
486
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
487 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
488 symbol_table::cache_name (uf->scope (), nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
489 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
490 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
491 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
492 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
493 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
494 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
495 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
496 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
497 success = false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
498 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
499 else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
500 success = set_fcn (octaveroot, fpath);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
501
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
502 return success;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
503 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
504
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
505 bool
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
506 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
507 {
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
508 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
509 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
510 std::ostringstream nmbuf;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
511
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
512 if (fcn.is_undefined ())
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
513 return false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
514
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
515 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
516
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
517 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
518 = symbol_table::all_variables (f->scope (), 0);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
519
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
520 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
521
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
522 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
523 nmbuf << nm << " " << varlen;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
524 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
525 nmbuf << nm;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
526
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
527 std::string buf_str = nmbuf.str ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
528 int32_t tmp = buf_str.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
529 os.write (reinterpret_cast<char *> (&tmp), 4);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
530 os.write (buf_str.c_str (), buf_str.length ());
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
531
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
532 std::ostringstream buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
533 print_raw (buf, true);
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
534 std::string stmp = buf.str ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
535 tmp = stmp.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
536 os.write (reinterpret_cast<char *> (&tmp), 4);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
537 os.write (stmp.c_str (), stmp.length ());
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
538
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
539 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
540 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
541 for (std::list<symbol_table::symbol_record>::const_iterator
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
542 p = vars.begin (); p != vars.end (); p++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
543 {
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
544 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
545 "", 0, save_as_floats))
18384
bd9d34f28b0f Use std::ostream::fail instead of unsafe implicit bool conversion (bug #41335)
Mike Miller <mtmiller@ieee.org>
parents: 17898
diff changeset
546 return ! os.fail ();
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
547 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
548 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
549 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
550 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
551 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
552 std::ostringstream nmbuf;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
553
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
554 octave_function *f = function_value ();
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
555 std::string fnm = f ? f->fcn_file_name () : "";
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
556
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
557 nmbuf << nm << "\n" << OCTAVE_EXEC_PREFIX << "\n" << fnm;
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 std::string buf_str = nmbuf.str ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
560 int32_t tmp = buf_str.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
561 os.write (reinterpret_cast<char *> (&tmp), 4);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
562 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
563 }
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
564
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
565 return true;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
566 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
567
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
568 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
569 octave_fcn_handle::load_binary (std::istream& is, bool swap,
21739
c4ab2e54f100 use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents: 21736
diff changeset
570 octave::mach_info::float_format fmt)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
571 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
572 bool success = true;
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
573
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
574 int32_t tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
575 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
576 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
577 if (swap)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
578 swap_bytes<4> (&tmp);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
579
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
580 OCTAVE_LOCAL_BUFFER (char, 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
581 // 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
582 // 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
583 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
584 ctmp1[tmp] = 0;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
585 nm = std::string (ctmp1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
586
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
587 if (! is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
588 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
589
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
590 size_t anl = anonymous.length ();
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
591
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
592 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
593 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
594 octave_idx_type len = 0;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
595
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
596 if (nm.length () > anl)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
597 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
598 std::istringstream nm_is (nm.substr (anl));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
599 nm_is >> len;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
600 nm = nm.substr (0, anl);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
601 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
602
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
603 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
604 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
605 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
606 swap_bytes<4> (&tmp);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
607
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
608 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
609 // 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
610 // 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
611 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
612 ctmp2[tmp] = 0;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
613
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
614 octave::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
615
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
616 // 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
617 // 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
618
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
619 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
620 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
621
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
622 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
623
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
624 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
625 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
626
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
627 if (len > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
628 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
629 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
630 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
631 octave_value t2;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
632 bool dummy;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
633 std::string doc;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
634
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
635 std::string name =
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
636 read_binary_data (is, swap, fmt, "",
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
637 dummy, t2, doc);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
638
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20953
diff changeset
639 if (! is)
20956
850e3d2533d4 maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20955
diff changeset
640 error ("load: failed to load anonymous function handle");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
641
16442
302157614308 deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents: 16170
diff changeset
642 symbol_table::assign (name, t2, local_scope);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
643 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
644 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
645
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
646 if (is && success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
647 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
648 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
649 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
650 eval_string (ctmp2, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
651
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
652 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
653 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
654 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
655
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
656 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
657 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
658 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
659
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
660 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
661
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
662 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
663 symbol_table::cache_name (uf->scope (), nm);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
664 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
665 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
666 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
667 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
668 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
669 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
670 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
671 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
672 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
673 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
674 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
675 std::string fpath;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
676
8021
85184151822e fix typo in NPOS change
John W. Eaton <jwe@octave.org>
parents: 8019
diff changeset
677 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
678 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
679 size_t pos1 = nm.find_first_of ("\n");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
680 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
681 octaveroot = nm.substr (pos1 + 1, pos2 - pos1 - 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
682 fpath = nm.substr (pos2 + 1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
683 nm = nm.substr (0, pos1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
684 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
685
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
686 success = set_fcn (octaveroot, fpath);
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
687 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
688
12714
65b7ce254ba3 Fix loading of function handles saved in binary format. Bug #33456.
Olaf Till <olaf.till@uni-jena.de>
parents: 12483
diff changeset
689 return success;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
690 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
691
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
692 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
693 octave_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
694 bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
695 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
696 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
697
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
698 bool retval = true;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
699
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
700 hid_t group_hid = -1;
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
701 #if defined (HAVE_HDF5_18)
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
702 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
703 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
704 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
705 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
706 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
707 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
708 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
709
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18019
diff changeset
710 hid_t space_hid, data_hid, type_hid;
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 18019
diff changeset
711 space_hid = data_hid = type_hid = -1;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
712
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
713 // attach the type of the variable
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
714 type_hid = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
715 H5Tset_size (type_hid, nm.length () + 1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
716 if (type_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
717 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
718 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
719 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
720 }
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 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
723 hdims[0] = 0;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
724 hdims[1] = 0;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
725 space_hid = H5Screate_simple (0 , hdims, 0);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
726 if (space_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
727 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
728 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
729 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
730 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
731 }
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
732 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
733 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
734 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
735 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
736 #else
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
737 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
738 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
739 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
740 if (data_hid < 0
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
741 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
742 octave_H5P_DEFAULT, nm.c_str ()) < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
743 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
744 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
745 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
746 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
747 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
748 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
749 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
750
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
751 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
752 {
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
753 std::ostringstream buf;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
754 print_raw (buf, true);
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
755 std::string stmp = buf.str ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
756
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
757 // attach the type of the variable
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
758 H5Tset_size (type_hid, stmp.length () + 1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
759 if (type_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
760 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
761 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
762 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
763 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
764 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
765
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
766 #if defined (HAVE_HDF5_18)
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
767 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
768 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
769 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
770 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
771 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
772 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
773 #endif
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
774 if (data_hid < 0
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
775 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
776 octave_H5P_DEFAULT, stmp.c_str ()) < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
777 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
778 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
779 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
780 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
781 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
782 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
783
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
784 H5Dclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
785
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
786 octave_user_function *f = fcn.user_function_value ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
787
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
788 std::list<symbol_table::symbol_record> vars
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
789 = symbol_table::all_variables (f->scope (), 0);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
790
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
791 size_t varlen = vars.size ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
792
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
793 if (varlen > 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
794 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
795 hid_t as_id = H5Screate (H5S_SCALAR);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
796
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
797 if (as_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
798 {
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
799 #if defined (HAVE_HDF5_18)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
800 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
801 H5T_NATIVE_IDX, as_id,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
802 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
803
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
804 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
805 hid_t a_id = H5Acreate (group_hid, "SYMBOL_TABLE",
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
806 H5T_NATIVE_IDX, as_id, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
807 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
808
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
809 if (a_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
810 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
811 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
812
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
813 H5Aclose (a_id);
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 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
816 retval = false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
817
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
818 H5Sclose (as_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
819 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
820 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
821 retval = false;
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
822 #if defined (HAVE_HDF5_18)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
823 data_hid = H5Gcreate (group_hid, "symbol table",
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
824 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
825 #else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
826 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
827 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
828 if (data_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
829 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
830 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
831 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
832 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
833 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
834 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
835
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
836 for (std::list<symbol_table::symbol_record>::const_iterator
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
837 p = vars.begin (); p != vars.end (); p++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
838 {
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
839 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
840 "", false, save_as_floats))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
841 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
842 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
843 H5Gclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
844 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
845 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
846 else
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
847 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
848 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
849
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
850 octave_function *f = function_value ();
21017
93748bcaec17 maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents: 20962
diff changeset
851 std::string fpath = f ? f->fcn_file_name () : "";
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
852
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
853 H5Sclose (space_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
854 hdims[0] = 1;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
855 hdims[1] = octaveroot.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
856 space_hid = H5Screate_simple (0 , hdims, 0);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
857 if (space_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
858 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
859 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
860 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
861 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
862 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
863
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
864 H5Tclose (type_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
865 type_hid = H5Tcopy (H5T_C_S1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
866 H5Tset_size (type_hid, octaveroot.length () + 1);
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
867 #if defined (HAVE_HDF5_18)
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
868 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT",
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
869 type_hid, space_hid, octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
870 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
871 hid_t a_id = H5Acreate (group_hid, "OCTAVEROOT",
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
872 type_hid, space_hid, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
873 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
874
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
875 if (a_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
876 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
877 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
878
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
879 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
880 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
881 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
882 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
883 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
884 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
885 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
886 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
887 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
888
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
889 H5Sclose (space_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
890 hdims[0] = 1;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
891 hdims[1] = fpath.length ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
892 space_hid = H5Screate_simple (0 , hdims, 0);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
893 if (space_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
894 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
895 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
896 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
897 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
898 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
899
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
900 H5Tclose (type_hid);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
901 type_hid = H5Tcopy (H5T_C_S1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
902 H5Tset_size (type_hid, fpath.length () + 1);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
903
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
904 #if defined (HAVE_HDF5_18)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
905 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
906 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
907 #else
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
908 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
909 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
910
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
911 if (a_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
912 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
913 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
914
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
915 H5Aclose (a_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
916 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
917 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
918 retval = false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
919 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
920
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
921 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
922 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
923 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
924
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
925 return retval;
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
926
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
927 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
928 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
929 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
930 octave_unused_parameter (save_as_floats);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
931
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
932 warn_save ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
933
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
934 return false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
935 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
936 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
937
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
938 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
939 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
940 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
941 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
942
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
943 bool success = true;
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
944
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
945 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
946 hsize_t rank;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
947 int slen;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
948
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
949 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
950 group_hid = H5Gopen (loc_id, name, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
951 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
952 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
953 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
954 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
955 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
956
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
957 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
958 data_hid = H5Dopen (group_hid, "nm", octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
959 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
960 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
961 #endif
4988
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 (data_hid < 0)
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 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
966 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
967 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
968
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
969 type_hid = H5Dget_type (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
970 type_class_hid = H5Tget_class (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
971
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
972 if (type_class_hid != H5T_STRING)
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 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
975 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
976 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
977 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
978 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
979
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
980 space_hid = H5Dget_space (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
981 rank = H5Sget_simple_extent_ndims (space_hid);
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 if (rank != 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
984 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
985 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
986 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
987 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
988 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
989 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
990 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
991
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
992 slen = H5Tget_size (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
993 if (slen < 0)
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 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
996 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
997 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
998 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
999 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1000 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1001
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1002 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1003
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1004 // create datatype for (null-terminated) string to read into:
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1005 st_id = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1006 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1007
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1008 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1009 octave_H5P_DEFAULT, nm_tmp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1010 < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1011 {
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1012 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1013 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1014 H5Tclose (type_hid);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1015 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1016 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1017 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1018 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1019 H5Tclose (st_id);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1020 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1021 nm = nm_tmp;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1022
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1023 if (nm == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1024 {
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1025 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1026 data_hid = H5Dopen (group_hid, "fcn", octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1027 #else
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1028 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
1029 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1030
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1031 if (data_hid < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1032 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1033 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1034 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1035 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1036 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1037 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1038
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1039 H5Tclose (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1040 type_hid = H5Dget_type (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1041 type_class_hid = H5Tget_class (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1042
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1043 if (type_class_hid != H5T_STRING)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1044 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1045 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1046 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1047 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1048 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1049 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1050 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1051
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1052 H5Sclose (space_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1053 space_hid = H5Dget_space (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1054 rank = H5Sget_simple_extent_ndims (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1055
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1056 if (rank != 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1057 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1058 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1059 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1060 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1061 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1062 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1063 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1064
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1065 slen = H5Tget_size (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1066 if (slen < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1067 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1068 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1069 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1070 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1071 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1072 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1073 }
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1074
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1075 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1076
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1077 // create datatype for (null-terminated) string to read into:
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1078 st_id = H5Tcopy (H5T_C_S1);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1079 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1080
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1081 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1082 octave_H5P_DEFAULT, fcn_tmp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1083 < 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1084 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1085 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1086 H5Sclose (space_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1087 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1088 H5Dclose (data_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1089 H5Gclose (group_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1090 return false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1091 }
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1092 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1093 H5Dclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1094
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1095 octave_idx_type len = 0;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1096
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1097 // 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
1098 // 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
1099 // call H5Aopen for a non-existing attribute
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 H5E_auto_t err_func;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1102 void *err_func_data;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1103
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1104 // turn off error reporting temporarily, but save the error
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1105 // reporting function:
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1106 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1107 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data);
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1108 H5Eset_auto (octave_H5E_DEFAULT, 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
1109 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1110 H5Eget_auto (&err_func, &err_func_data);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1111 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
1112 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1113
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1114 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
1115
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1116 if (attr_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1117 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1118 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
1119 success = false;
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1120
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1121 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1122 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1123
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1124 // restore error reporting:
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1125 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1126 H5Eset_auto (octave_H5E_DEFAULT, 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
1127 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1128 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
1129 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1130
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
1131 octave::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
1132
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1133 // 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
1134 // 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
1135
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
1136 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
1137 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
1138
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1139 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
1140
c6463412aebb eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents: 8946
diff changeset
1141 octave_call_stack::push (local_scope, 0);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1142 frame.add_fcn (octave_call_stack::pop);
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
1143
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1144 if (len > 0 && success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1145 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1146 hsize_t num_obj = 0;
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1147 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1148 data_hid = H5Gopen (group_hid, "symbol table", octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
1149 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1150 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
1151 #endif
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1152 H5Gget_num_objs (data_hid, &num_obj);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1153 H5Gclose (data_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1154
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1155 if (num_obj != static_cast<hsize_t>(len))
20953
758b71e964ce maint: Eliminate more useless statements after error().
Rik <rik@octave.org>
parents: 20952
diff changeset
1156 error ("load: failed to load anonymous function handle");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1157
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1158 hdf5_callback_data dsub;
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1159 int current_item = 0;
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1160 for (octave_idx_type i = 0; i < len; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1161 {
22028
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 21966
diff changeset
1162 if (hdf5_h5g_iterate (group_hid, "symbol table", &current_item,
5c949eecb6dd use int64_t for octave_hdf5_id (bug #47858)
Stefan Miereis <stefan.miereis@gmx.de>
parents: 21966
diff changeset
1163 &dsub) <= 0)
20957
9db35d2042be maint: eliminate special cases of statements after error.
Rik <rik@octave.org>
parents: 20956
diff changeset
1164 error ("load: failed to load anonymous function handle");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1165
20555
f90c8372b7ba eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents: 20535
diff changeset
1166 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
1167 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1168 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1169
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1170 if (success)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1171 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1172 int parse_status;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1173 octave_value anon_fcn_handle =
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1174 eval_string (fcn_tmp, true, parse_status);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1175
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1176 if (parse_status == 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1177 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1178 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
1179
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1180 if (fh)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1181 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1182 fcn = fh->fcn;
7761
5adeea5de26c symbol table reporting functions
John W. Eaton <jwe@octave.org>
parents: 7756
diff changeset
1183
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1184 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
1185
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1186 if (uf)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1187 symbol_table::cache_name (uf->scope (), nm);
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 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1192 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1193 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1194 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1195
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
1196 frame.run ();
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1197 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1198 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1199 {
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1200 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1201 std::string fpath;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1202
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1203 // 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
1204 // 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
1205 // call H5Aopen for a non-existing attribute
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 H5E_auto_t err_func;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1208 void *err_func_data;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1209
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1210 // turn off error reporting temporarily, but save the error
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1211 // reporting function:
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1212 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1213 H5Eget_auto (octave_H5E_DEFAULT, &err_func, &err_func_data);
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1214 H5Eset_auto (octave_H5E_DEFAULT, 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 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1216 H5Eget_auto (&err_func, &err_func_data);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1217 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
1218 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1219
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1220 hid_t attr_id = H5Aopen_name (group_hid, "OCTAVEROOT");
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1221 if (attr_id >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1222 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1223 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1224 type_hid = H5Aget_type (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1225 type_class_hid = H5Tget_class (type_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1226
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1227 if (type_class_hid != H5T_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1228 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1229 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1230 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1231 slen = H5Tget_size (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1232 st_id = H5Tcopy (H5T_C_S1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1233 H5Tset_size (st_id, slen);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1234 OCTAVE_LOCAL_BUFFER (char, root_tmp, slen);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1235
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1236 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
1237 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1238 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1239 octaveroot = root_tmp;
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1240
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1241 H5Tclose (st_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
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1244 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1245 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1246
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1247 if (success)
10315
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 attr_id = H5Aopen_name (group_hid, "FILE");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1250 if (attr_id >= 0)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1251 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1252 H5Tclose (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1253 type_hid = H5Aget_type (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1254 type_class_hid = H5Tget_class (type_hid);
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1255
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1256 if (type_class_hid != H5T_STRING)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1257 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1258 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1259 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1260 slen = H5Tget_size (type_hid);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1261 st_id = H5Tcopy (H5T_C_S1);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1262 H5Tset_size (st_id, slen);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1263 OCTAVE_LOCAL_BUFFER (char, path_tmp, slen);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1264
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1265 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
1266 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1267 else
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1268 fpath = path_tmp;
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 H5Tclose (st_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1271 }
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1272
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1273 H5Aclose (attr_id);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1274 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1275 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1276
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1277 // restore error reporting:
21211
2cf8bc5c7017 use "#if defined (HAVE_FOO)" instead of "#if HAVE_FOO" for feature tests
John W. Eaton <jwe@octave.org>
parents: 21200
diff changeset
1278 #if defined (HAVE_HDF5_18)
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 21017
diff changeset
1279 H5Eset_auto (octave_H5E_DEFAULT, 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
1280 #else
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1281 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
1282 #endif
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1283
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1284 success = (success ? set_fcn (octaveroot, fpath) : success);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1285 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1286
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1287 H5Tclose (type_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1288 H5Sclose (space_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1289 H5Gclose (group_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
1290
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1291 return success;
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
1292
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
1293 #else
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
1294 octave_unused_parameter (loc_id);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
1295 octave_unused_parameter (name);
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
1296
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
1297 warn_load ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
1298
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
1299 return false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
1300 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1301 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1302
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1303 /*
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1304 %!test
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1305 %! a = 2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1306 %! f = @(x) a + x;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1307 %! 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
1308 %! hm = @version;
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
1309 %! hdld = @svd;
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1310 %! hbi = @log2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1311 %! f2 = f;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1312 %! g2 = g;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1313 %! hm2 = hm;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1314 %! hdld2 = hdld;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1315 %! hbi2 = hbi;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1316 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1317 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1318 %! && __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
1319 %! modes(end+1) = "-hdf5";
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1320 %! endif
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
1321 %! for i = 1:numel (modes)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
1322 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
1323 %! nm = tempname ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1324 %! unwind_protect
15572
859c8bf6d134 Fix saved struct with function handle fails to load (bug #33857)
Max Brister <max@2bass.com>
parents: 15235
diff changeset
1325 %! 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
1326 %! 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
1327 %! clear f2 g2 hm2 hdld2 hbi2
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1328 %! load (nm);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1329 %! assert (f (2), f2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1330 %! assert (g (2), g2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1331 %! assert (g (3), g2 (3));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1332 %! unlink (nm);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1333 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1334 %! unwind_protect_cleanup
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1335 %! unlink (nm);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1336 %! end_unwind_protect
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
1337 %! endfor
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
1338 */
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
1339
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1340 /*
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1341 %!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
1342 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1343 %! 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
1344 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1345 %! 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
1346 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1347 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1348 %!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
1349 %! if (n == 0)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21574
diff changeset
1350 %! load (nm);
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1351 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1352 %! [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
1353 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1354 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1355
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1356 Test for bug #35876
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1357 %!test
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1358 %! a = 2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1359 %! f = @(x) a + x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1360 %! g = @(x) 2 * x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1361 %! hm = @version;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1362 %! hdld = @svd;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1363 %! hbi = @log2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1364 %! f2 = f;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1365 %! g2 = g;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1366 %! hm2 = hm;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1367 %! hdld2 = hdld;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1368 %! hbi2 = hbi;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1369 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1370 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
1371 %! && __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
1372 %! modes(end+1) = "-hdf5";
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1373 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1374 %! for i = 1:numel (modes)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1375 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
1376 %! nm = tempname ();
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1377 %! unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1378 %! 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
1379 %! 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
1380 %! [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
1381 %! load (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1382 %! assert (f (2), f2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1383 %! assert (g (2), g2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1384 %! assert (g (3), g2 (3));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1385 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1386 %! 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
1387 %! unwind_protect_cleanup
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1388 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1389 %! end_unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1390 %! endfor
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1391 */
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
1392
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1393 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
1394 octave_fcn_handle::print (std::ostream& os, bool pr_as_read_syntax)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1395 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1396 print_raw (os, pr_as_read_syntax);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1397 newline (os);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1398 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1399
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1400 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1401 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
1402 {
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1403 bool printed = false;
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1404
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1405 if (nm == anonymous)
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1406 {
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1407 tree_print_code tpc (os);
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1408
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
1409 // 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
1410 // 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
1411
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1412 octave_value ftmp = fcn;
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1413
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1414 octave_user_function *f = ftmp.user_function_value ();
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1415
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1416 if (f)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1417 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1418 tree_parameter_list *p = f->parameter_list ();
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1419
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1420 os << "@(";
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1421
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1422 if (p)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1423 p->accept (tpc);
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1424
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1425 os << ") ";
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1426
11223
64e7538db12a fix printing of newlines for anonymous function handle bodies
John W. Eaton <jwe@octave.org>
parents: 11220
diff changeset
1427 tpc.print_fcn_handle_body (f->body ());
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1428
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1429 printed = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1430 }
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1431 }
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1432
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
1433 if (! printed)
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
1434 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
1435 current_print_indent_level ());
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1436 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1437
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1438 octave_value
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1439 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
1440 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1441 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1442
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
1443 // 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
1444
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1445 // FIXME: it seems ugly to put this here, but there is no single
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
1446 // 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
1447 // 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
1448 // 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
1449
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1450 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
1451
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1452 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
1453
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1454 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
1455 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
1456 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
1457 {
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1458 if (nm[0] == '.')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1459 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1460 switch (nm[1])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1461 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1462 case '\'':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1463 tnm = "transpose";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1464 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
1465
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1466 case '+':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1467 tnm = "plus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1468 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
1469
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1470 case '-':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1471 tnm = "minus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1472 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
1473
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1474 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1475 tnm = "times";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1476 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
1477
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1478 case '/':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1479 tnm = "rdivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1480 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
1481
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1482 case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1483 tnm = "power";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1484 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
1485
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1486 case '\\':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1487 tnm = "ldivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1488 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1489 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1490 }
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
1491 else if (nm[1] == '=')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1492 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1493 switch (nm[0])
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1494 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1495 case '<':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1496 tnm = "le";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1497 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
1498
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1499 case '=':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1500 tnm = "eq";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1501 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
1502
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1503 case '>':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1504 tnm = "ge";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1505 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
1506
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1507 case '~':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1508 case '!':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1509 tnm = "ne";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1510 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1511 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1512 }
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
1513 else if (nm == "**")
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1514 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
1515 }
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1516 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
1517 {
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 switch (nm[0])
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1519 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1520 case '~':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1521 case '!':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1522 tnm = "not";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1523 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
1524
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1525 case '\'':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1526 tnm = "ctranspose";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1527 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
1528
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1529 case '+':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1530 tnm = "plus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1531 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
1532
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1533 case '-':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1534 tnm = "minus";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1535 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
1536
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1537 case '*':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1538 tnm = "mtimes";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1539 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
1540
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1541 case '/':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1542 tnm = "mrdivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1543 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
1544
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1545 case '^':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1546 tnm = "mpower";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1547 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
1548
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1549 case '\\':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1550 tnm = "mldivide";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1551 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
1552
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1553 case '<':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1554 tnm = "lt";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1555 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
1556
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1557 case '>':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1558 tnm = "gt";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1559 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
1560
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1561 case '&':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1562 tnm = "and";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1563 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
1564
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1565 case '|':
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1566 tnm = "or";
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1567 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
1568 }
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
1569 }
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1570
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1571 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
1572 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
1573
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1574 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
1575
11220
883b9308353c allow class function to be called from methods as well as constructors
John W. Eaton <jwe@octave.org>
parents: 11060
diff changeset
1576 // 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
1577 // for any class.
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1578 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
1579 && (fptr->is_subfunction () || fptr->is_private_function ()
18441
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
1580 || fptr->is_class_constructor ()
b0aba84cf80f Support handle to classdef constructor.
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18416
diff changeset
1581 || fptr->is_classdef_constructor ()))
9458
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1582 {
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1583 // Locally visible function.
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1584 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
1585 }
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1586 else
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1587 {
21751
b571fc85953f maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents: 21745
diff changeset
1588 // Globally visible (or no match yet). Query overloads.
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1589 std::list<std::string> classes = load_path::overloads (tnm);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1590 bool any_match = fptr != 0 || classes.size () > 0;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1591 if (! any_match)
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 // 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
1594 load_path::update ();
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1595 classes = load_path::overloads (tnm);
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1596 any_match = classes.size () > 0;
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1597 }
9458
0c7d84a65386 allow taking handles of methods with no base overload
Jaroslav Hajek <highegg@gmail.com>
parents: 9450
diff changeset
1598
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1599 if (! any_match)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1600 error ("@%s: no function and no method found", tnm.c_str ());
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1601
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1602 octave_fcn_handle *fh = new octave_fcn_handle (f, tnm);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1603 retval = fh;
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1604
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1605 for (std::list<std::string>::iterator iter = classes.begin ();
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1606 iter != classes.end (); iter++)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1607 {
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1608 std::string class_name = *iter;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1609 octave_value fmeth = symbol_table::find_method (tnm, class_name);
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1610
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1611 bool is_builtin = false;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1612 for (int i = 0; i < btyp_num_types; i++)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1613 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1614 // FIXME: Too slow? Maybe binary lookup?
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1615 if (class_name == btyp_class_name[i])
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1616 {
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1617 is_builtin = true;
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1618 fh->set_overload (static_cast<builtin_type_t> (i), fmeth);
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1619 }
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1620 }
10321
97b4bd6f0925 partially rewrite function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 10315
diff changeset
1621
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1622 if (! is_builtin)
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20957
diff changeset
1623 fh->set_overload (class_name, fmeth);
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1624 }
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
1625 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1626
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1627 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1628 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1629
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
1630 /*
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 %!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
1632 %! 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
1633 %! ".'", "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
1634 %! ".+", "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
1635 %! ".-", "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
1636 %! ".*", "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
1637 %! "./", "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
1638 %! ".^", "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
1639 %! ".\\", "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
1640 %! "<=", "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
1641 %! "==", "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
1642 %! ">=", "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
1643 %! "~=", "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
1644 %! "!=", "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
1645 %! "**", "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
1646 %! "~", "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
1647 %! "!", "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
1648 %! "\'", "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
1649 %! "+", "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
1650 %! "-", "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
1651 %! "*", "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
1652 %! "/", "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
1653 %! "^", "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
1654 %! "\\", "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
1655 %! "<", "lt";
9343
70e0d3b1f26f fix typos in previous change
John W. Eaton <jwe@octave.org>
parents: 9342
diff changeset
1656 %! ">", "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
1657 %! "&", "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
1658 %! "|", "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
1659 %! 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
1660 %! 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
1661 %! 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
1662 */
2ca8879a140c allow function handles to be created from operators that correspond to named functions
John W. Eaton <jwe@octave.org>
parents: 9144
diff changeset
1663
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1664 DEFUN (functions, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1665 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1666 @deftypefn {} {@var{s} =} functions (@var{fcn_handle})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1667 Return a structure containing information about the function handle
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1668 @var{fcn_handle}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1669
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1670 The structure @var{s} always contains these three fields:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1671
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1672 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1673 @item function
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1674 The function name. For an anonymous function (no name) this will be the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1675 actual function definition.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1676
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1677 @item type
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1678 Type of the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1679
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1680 @table @asis
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1681 @item anonymous
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1682 The function is anonymous.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1683
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1684 @item private
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1685 The function is private.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1687 @item overloaded
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1688 The function overloads an existing function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1689
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1690 @item simple
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1691 The function is a built-in or m-file function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1692
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1693 @item subfunction
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1694 The function is a subfunction within an m-file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1695 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1696
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1697 @item file
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1698 The m-file that will be called to perform the function. This field is empty
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1699 for anonymous and built-in functions.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1700 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1701
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1702 In addition, some function types may return more information in additional
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1703 fields.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1704
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1705 @strong{Warning:} @code{functions} is provided for debugging purposes only.
22105
3f5f1234c619 main: Fix typos "It's" -> "Its" and "it's" -> "its" (Bug #48508)
Andreas Weber <andy.weber.aw@gmail.com>
parents: 22094
diff changeset
1706 Its behavior may change in the future and programs should not depend on a
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1707 particular output.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1708
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1709 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1710 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1711 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1712 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1713
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1714 octave_fcn_handle *fh = args(0).fcn_handle_value ("functions: FCN_HANDLE argument must be a function handle object");
4649
f7ce581b27fb [project @ 2003-11-23 21:46:44 by jwe]
jwe
parents: 4612
diff changeset
1715
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1716 octave_function *fcn = fh ? fh->function_value () : 0;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1717
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1718 if (! fcn)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1719 error ("functions: FCN_HANDLE is not a valid function handle object");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1720
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1721 octave_scalar_map m;
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1722
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1723 std::string fh_nm = fh->fcn_name ();
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1724
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1725 if (fh_nm == octave_fcn_handle::anonymous)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1726 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1727 std::ostringstream buf;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1728 fh->print_raw (buf);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1729 m.setfield ("function", buf.str ());
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1730
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1731 m.setfield ("type", "anonymous");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1732 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1733 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1734 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1735 m.setfield ("function", fh_nm);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1736
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1737 if (fcn->is_subfunction ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1738 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1739 m.setfield ("type", "subfunction");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1740 Cell parentage (dim_vector (1, 2));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1741 parentage.elem (0) = fh_nm;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1742 parentage.elem (1) = fcn->parent_fcn_name ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1743 m.setfield ("parentage", octave_value (parentage));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1744 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1745 else if (fcn->is_private_function ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1746 m.setfield ("type", "private");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1747 else if (fh->is_overloaded ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1748 m.setfield ("type", "overloaded");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1749 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1750 m.setfield ("type", "simple");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1751 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1752
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1753 std::string nm = fcn->fcn_file_name ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1754
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1755 if (fh_nm == octave_fcn_handle::anonymous)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1756 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1757 m.setfield ("file", nm);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1758
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1759 octave_user_function *fu = fh->user_function_value ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1760
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1761 std::list<symbol_table::symbol_record> vars
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1762 = symbol_table::all_variables (fu->scope (), 0);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1763
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1764 size_t varlen = vars.size ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1765
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1766 if (varlen > 0)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1767 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1768 octave_scalar_map ws;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1769 for (std::list<symbol_table::symbol_record>::const_iterator
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
1770 p = vars.begin (); p != vars.end (); p++)
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1771 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1772 ws.assign (p->name (), p->varval (0));
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1773 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1774
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1775 m.setfield ("workspace", ws);
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1776 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1777 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1778 else if (fcn->is_user_function () || fcn->is_user_script ())
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1779 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1780 octave_function *fu = fh->function_value ();
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1781 m.setfield ("file", fu->fcn_file_name ());
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1782 }
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1783 else
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1784 m.setfield ("file", "");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1785
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1786 return ovl (m);
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1787 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1788
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1789 DEFUN (func2str, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1790 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1791 @deftypefn {} {} func2str (@var{fcn_handle})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1792 Return a string containing the name of the function referenced by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1793 function handle @var{fcn_handle}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1794 @seealso{str2func, functions}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1795 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1796 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1797 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1798 print_usage ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4925
diff changeset
1799
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1800 octave_fcn_handle *fh = args(0).fcn_handle_value ("func2str: FCN_HANDLE argument must be a function handle object");
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1801
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1802 if (! fh)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1803 error ("func2str: FCN_HANDLE must be a valid function handle");
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1804
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1805 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1806
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1807 std::string fh_nm = fh->fcn_name ();
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1808
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1809 if (fh_nm == octave_fcn_handle::anonymous)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1810 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1811 std::ostringstream buf;
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
1812
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1813 fh->print_raw (buf);
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1814
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1815 retval = buf.str ();
4343
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 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1818 retval = fh_nm;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1819
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1820 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1821 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1822
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
1823 DEFUN (str2func, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1824 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1825 @deftypefn {} {} str2func (@var{fcn_name})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1826 @deftypefnx {} {} str2func (@var{fcn_name}, "global")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1827 Return a function handle constructed from the string @var{fcn_name}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1828
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1829 If the optional @qcode{"global"} argument is passed, locally visible
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1830 functions are ignored in the lookup.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1831 @seealso{func2str, inline}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1832 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1833 {
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
1834 int nargin = args.length ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1835
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1836 if (nargin < 1 || nargin > 2)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1837 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1838
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1839 std::string nm = args(0).xstring_value ("str2func: FCN_NAME must be a string");
20580
729a85dafba8 use new string_value method to handle value extraction errors
John W. Eaton <jwe@octave.org>
parents: 20555
diff changeset
1840
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1841 octave_value retval;
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1842
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1843 if (nm[0] == '@')
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1844 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1845 int parse_status;
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1846 octave_value anon_fcn_handle =
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1847 eval_string (nm, true, parse_status);
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1848
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1849 if (parse_status == 0)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1850 retval = anon_fcn_handle;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1851 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1852 else
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
1853 retval = make_fcn_handle (nm, nargin != 2);
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1854
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1855 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1856 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1857
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
1858 /*
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1859 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1860 %! f = str2func ("<");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1861 %! assert (class (f), "function_handle");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1862 %! assert (func2str (f), "lt");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1863 %! assert (f (1, 2), true);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1864 %! assert (f (2, 1), false);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1865
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1866 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1867 %! f = str2func ("@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1868 %! assert (func2str (f), "@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1869 %! assert (f (0:3), sin (0:3));
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1870
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1871 %!error <FCN_NAME must be a string> str2func ({"sin"})
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1872 */
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1873
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
1874 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1875 %!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
1876 %! if (nargin < 3)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1877 %! n = 0;
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1878 %! endif
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1879 %! if (n > 2)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1880 %! y = f (x);
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1881 %! else
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
1882 %! n++;
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1883 %! 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
1884 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1885 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1886 %!
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
1887 %!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
1888 */
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1889
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1890 DEFUN (is_function_handle, args, ,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1891 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1892 @deftypefn {} {} is_function_handle (@var{x})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1893 Return true if @var{x} is a function handle.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1894 @seealso{isa, typeinfo, class, functions}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
1895 @end deftypefn */)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1896 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20797
diff changeset
1897 if (args.length () != 1)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1898 print_usage ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1899
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
1900 return ovl (args(0).is_function_handle ());
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1901 }
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1902
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1903 /*
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1904 %!shared fh
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1905 %! fh = @(x) x;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1906
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1907 %!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
1908 %!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
1909 %!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
1910
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1911 %!error is_function_handle ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
1912 %!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
1913 */
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
1914
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1915 octave_fcn_binder::octave_fcn_binder (const octave_value& f,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1916 const octave_value& root,
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1917 const octave_value_list& templ,
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1918 const std::vector<int>& mask,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1919 int exp_nargin)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1920 : octave_fcn_handle (f), root_handle (root), arg_template (templ),
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1921 arg_mask (mask), expected_nargin (exp_nargin)
10960
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 }
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 octave_fcn_handle *
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1926 octave_fcn_binder::maybe_binder (const octave_value& f)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1927 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1928 octave_fcn_handle *retval = 0;
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 octave_user_function *usr_fcn = f.user_function_value (false);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1931 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
1932
17898
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17896
diff changeset
1933 tree_statement_list *cmd_list = 0;
8c33abdd2f9a maint: Avoid using NULL in C++ code.
John W. Eaton <jwe@octave.org>
parents: 17896
diff changeset
1934 tree_expression *body_expr = 0;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1935
17896
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1936 if (usr_fcn)
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1937 {
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1938 cmd_list = usr_fcn->body ();
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1939 if (cmd_list)
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1940 {
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1941 // Verify that body is a single expression (always true in theory).
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1942 body_expr = (cmd_list->length () == 1
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1943 ? cmd_list->front ()->expression () : 0);
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1944 }
f05f571ff1fa Fix null pointer access in octave_fcn_binder::maybe_binder
PrasannaKumar Muralidharan <prasannatsmkumar@gmail.com>
parents: 17787
diff changeset
1945 }
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1946
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
1947 if (body_expr && body_expr->is_index_expression ()
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1948 && ! (param_list && param_list->takes_varargs ()))
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 // It's an index expression.
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1951 tree_index_expression *idx_expr = dynamic_cast<tree_index_expression *>
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1952 (body_expr);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1953 tree_expression *head_expr = idx_expr->expression ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1954 std::list<tree_argument_list *> arg_lists = idx_expr->arg_lists ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1955 std::string type_tags = idx_expr->type_tags ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1956
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1957 if (type_tags.length () == 1 && type_tags[0] == '('
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1958 && head_expr->is_identifier ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1959 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1960 assert (arg_lists.size () == 1);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1961
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1962 // It's a single index expression: a(x,y,....)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1963 tree_identifier *head_id =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1964 dynamic_cast<tree_identifier *> (head_expr);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1965 tree_argument_list *arg_list = arg_lists.front ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1966
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1967 // Build a map of input params to their position.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1968 std::map<std::string, int> arginmap;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1969 int npar = 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1970
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1971 if (param_list)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1972 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1973 for (tree_parameter_list::iterator it = param_list->begin ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1974 it != param_list->end (); ++it, ++npar)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1975 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1976 tree_decl_elt *elt = *it;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1977 tree_identifier *id = elt ? elt->ident () : 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1978 if (id && ! id->is_black_hole ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1979 arginmap[id->name ()] = npar;
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1980 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1981 }
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 if (arg_list && arg_list->length () > 0)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1984 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1985 bool bad = false;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1986 int nargs = arg_list->length ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1987 octave_value_list arg_template (nargs);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1988 std::vector<int> arg_mask (nargs);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1989
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1990 // Verify that each argument is either a named param, a constant,
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
1991 // or a defined identifier.
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1992 int iarg = 0;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1993 for (tree_argument_list::iterator it = arg_list->begin ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1994 it != arg_list->end (); ++it, ++iarg)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1995 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1996 tree_expression *elt = *it;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1997 if (elt && elt->is_constant ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1998 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
1999 arg_template(iarg) = elt->rvalue1 ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2000 arg_mask[iarg] = -1;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2001 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2002 else if (elt && elt->is_identifier ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2003 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2004 tree_identifier *elt_id =
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2005 dynamic_cast<tree_identifier *> (elt);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2006 if (arginmap.find (elt_id->name ()) != arginmap.end ())
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 arg_mask[iarg] = arginmap[elt_id->name ()];
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2009 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2010 else if (elt_id->is_defined ())
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2011 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2012 arg_template(iarg) = elt_id->rvalue1 ();
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2013 arg_mask[iarg] = -1;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2014 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2015 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2016 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2017 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2018 break;
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 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2022 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2023 bad = true;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2024 break;
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 }
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 octave_value root_val;
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 if (! bad)
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 // If the head is a value, use it as root.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2033 if (head_id->is_defined ())
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2034 root_val = head_id->rvalue1 ();
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2035 else
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2036 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2037 // It's a name.
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2038 std::string head_name = head_id->name ();
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2039
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2040 if (head_name == "eval" || head_name == "feval")
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2041 bad = true;
10960
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 {
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2044 // Function handles can't handle legacy
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2045 // dispatch, so we make sure it's not
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2046 // defined.
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2047
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2048 if (symbol_table::get_dispatch (head_name).size () > 0)
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2049 bad = true;
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2050 else
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20531
diff changeset
2051 {
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2052 // Simulate try/catch.
21743
f4d7d0eb5b0c use namespace for unwind_protect class
John W. Eaton <jwe@octave.org>
parents: 21739
diff changeset
2053 octave::unwind_protect frame;
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2054 interpreter_try (frame);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2055
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2056 try
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2057 {
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2058 root_val = make_fcn_handle (head_name);
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2059 }
22327
d0562b3159c7 move more classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 22323
diff changeset
2060 catch (const octave::execution_exception&)
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2061 {
20756
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
2062 recover_from_exception ();
200ae1d650b7 propagate octave_execution_exception objects through try/catch blocks
John W. Eaton <jwe@octave.org>
parents: 20741
diff changeset
2063
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2064 bad = true;
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2065 }
20535
b70cc4bd8109 begin removal of global error_state variable
John W. Eaton <jwe@octave.org>
parents: 20531
diff changeset
2066 }
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2067 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2068 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2069 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2070
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2071 if (! bad)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2072 {
10961
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2073 // Stash proper name tags.
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2074 std::list<string_vector> arg_names = idx_expr->arg_names ();
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2075 assert (arg_names.size () == 1);
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2076 arg_template.stash_name_tags (arg_names.front ());
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2077
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2078 retval = new octave_fcn_binder (f, root_val, arg_template,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2079 arg_mask, npar);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2080 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2081 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2082 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2083 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2084
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2085 if (! retval)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2086 retval = new octave_fcn_handle (f, octave_fcn_handle::anonymous);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2087
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2088 return retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2089 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2090
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2091 /*
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2092 %!test
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2093 %! f = @(t) eval ('2*t');
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2094 %! assert (f (21), 42);
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2095 */
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
2096
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2097 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2098 octave_fcn_binder::do_multi_index_op (int nargout,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2099 const octave_value_list& args)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2100 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2101 return do_multi_index_op (nargout, args, 0);
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2102 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2103
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2104 octave_value_list
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
2105 octave_fcn_binder::do_multi_index_op (int nargout,
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2106 const octave_value_list& args,
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2107 const std::list<octave_lvalue>* lvalue_list)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2108 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2109 octave_value_list retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2110
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2111 if (args.length () == expected_nargin)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2112 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2113 for (int i = 0; i < arg_template.length (); i++)
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2114 {
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2115 int j = arg_mask[i];
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2116 if (j >= 0)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2117 arg_template(i) = args(j); // May force a copy...
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2118 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2119
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2120 // Make a shallow copy of arg_template, to ensure consistency throughout
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2121 // the following call even if we happen to get back here.
10961
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2122 octave_value_list tmp (arg_template);
2cc9b08bfd39 fixes in binders code
Jaroslav Hajek <highegg@gmail.com>
parents: 10960
diff changeset
2123 retval = root_handle.do_multi_index_op (nargout, tmp, lvalue_list);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2124 }
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2125 else
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
2126 retval = octave_fcn_handle::do_multi_index_op (nargout, args, lvalue_list);
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2127
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2128 return retval;
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
2129 }
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2130
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2131 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
2132 %!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
2133 %! r = g(i);
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2134 %!endfunction
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2135 %!test
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
2136 %! 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
2137 %! 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
2138 */
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
2139