annotate libinterp/octave-value/ov-fcn-handle.cc @ 31605:e88a07dec498 stable

maint: Use macros to begin/end C++ namespaces. * oct-conf-post-public.in.h: Define two macros (OCTAVE_BEGIN_NAMESPACE, OCTAVE_END_NAMESPACE) that can be used to start/end a namespace. * mk-opts.pl, build-env.h, build-env.in.cc, __betainc__.cc, __contourc__.cc, __dsearchn__.cc, __eigs__.cc, __expint__.cc, __ftp__.cc, __gammainc__.cc, __ichol__.cc, __ilu__.cc, __isprimelarge__.cc, __lin_interpn__.cc, __magick_read__.cc, __pchip_deriv__.cc, __qp__.cc, amd.cc, auto-shlib.cc, auto-shlib.h, balance.cc, base-text-renderer.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, ccolamd.cc, cellfun.cc, chol.cc, colamd.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, data.h, debug.cc, defaults.cc, defaults.h, defun-int.h, defun.cc, det.cc, dirfns.cc, display.cc, display.h, dlmread.cc, dmperm.cc, dot.cc, dynamic-ld.cc, dynamic-ld.h, eig.cc, ellipj.cc, environment.cc, environment.h, error.cc, error.h, errwarn.h, event-manager.cc, event-manager.h, event-queue.cc, event-queue.h, fcn-info.cc, fcn-info.h, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, ft-text-renderer.cc, ft-text-renderer.h, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, gl-render.cc, gl-render.h, gl2ps-print.cc, gl2ps-print.h, graphics-toolkit.cc, graphics-toolkit.h, graphics.cc, graphics.in.h, gsvd.cc, gtk-manager.cc, gtk-manager.h, hash.cc, help.cc, help.h, hess.cc, hex2num.cc, hook-fcn.cc, hook-fcn.h, input.cc, input.h, interpreter-private.cc, interpreter-private.h, interpreter.cc, interpreter.h, inv.cc, jsondecode.cc, jsonencode.cc, kron.cc, latex-text-renderer.cc, latex-text-renderer.h, load-path.cc, load-path.h, load-save.cc, load-save.h, lookup.cc, ls-ascii-helper.cc, ls-ascii-helper.h, ls-oct-text.cc, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, mappers.cc, matrix_type.cc, max.cc, mex-private.h, mex.cc, mgorth.cc, nproc.cc, oct-fstrm.cc, oct-fstrm.h, oct-hdf5-types.cc, oct-hdf5-types.h, oct-hist.cc, oct-hist.h, oct-iostrm.cc, oct-iostrm.h, oct-opengl.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-process.cc, oct-process.h, oct-stdstrm.h, oct-stream.cc, oct-stream.h, oct-strstrm.cc, oct-strstrm.h, oct-tex-lexer.in.ll, oct-tex-parser.yy, ordqz.cc, ordschur.cc, pager.cc, pager.h, pinv.cc, pow2.cc, pr-flt-fmt.cc, pr-output.cc, procstream.cc, procstream.h, psi.cc, qr.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, settings.cc, settings.h, sighandlers.cc, sighandlers.h, sparse-xdiv.cc, sparse-xdiv.h, sparse-xpow.cc, sparse-xpow.h, sparse.cc, spparms.cc, sqrtm.cc, stack-frame.cc, stack-frame.h, stream-euler.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symbfact.cc, syminfo.cc, syminfo.h, symrcm.cc, symrec.cc, symrec.h, symscope.cc, symscope.h, symtab.cc, symtab.h, syscalls.cc, sysdep.cc, sysdep.h, text-engine.cc, text-engine.h, text-renderer.cc, text-renderer.h, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, url-handle-manager.cc, url-handle-manager.h, urlwrite.cc, utils.cc, utils.h, variables.cc, variables.h, xdiv.cc, xdiv.h, xnorm.cc, xnorm.h, xpow.cc, xpow.h, __delaunayn__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, convhulln.cc, fftw.cc, gzip.cc, mk-build-env-features.sh, mk-builtins.pl, cdef-class.cc, cdef-class.h, cdef-fwd.h, cdef-manager.cc, cdef-manager.h, cdef-method.cc, cdef-method.h, cdef-object.cc, cdef-object.h, cdef-package.cc, cdef-package.h, cdef-property.cc, cdef-property.h, cdef-utils.cc, cdef-utils.h, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-builtin.h, ov-cell.cc, ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc, ov-fcn-handle.cc, ov-fcn-handle.h, ov-fcn.h, ov-java.cc, ov-java.h, ov-mex-fcn.h, ov-null-mat.cc, ov-oncleanup.cc, ov-struct.cc, ov-typeinfo.cc, ov-typeinfo.h, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, ov.h, octave.cc, octave.h, mk-ops.sh, 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-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-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-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-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-mi.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, anon-fcn-validator.cc, anon-fcn-validator.h, bp-table.cc, bp-table.h, comment-list.cc, comment-list.h, filepos.h, lex.h, lex.ll, oct-lvalue.cc, oct-lvalue.h, oct-parse.yy, parse.h, profiler.cc, profiler.h, pt-anon-scopes.cc, pt-anon-scopes.h, pt-arg-list.cc, pt-arg-list.h, pt-args-block.cc, pt-args-block.h, pt-array-list.cc, 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.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-id.cc, pt-id.h, pt-idx.cc, pt-idx.h, 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-spmd.cc, pt-spmd.h, pt-stmt.cc, pt-stmt.h, pt-tm-const.cc, pt-tm-const.h, pt-unop.cc, pt-unop.h, pt-vm-eval.cc, pt-walk.cc, pt-walk.h, pt.cc, pt.h, token.cc, token.h, Range.cc, Range.h, idx-vector.cc, idx-vector.h, range-fwd.h, CollocWt.cc, CollocWt.h, aepbalance.cc, aepbalance.h, chol.cc, chol.h, gepbalance.cc, gepbalance.h, gsvd.cc, gsvd.h, hess.cc, hess.h, lo-mappers.cc, lo-mappers.h, lo-specfun.cc, lo-specfun.h, lu.cc, lu.h, oct-convn.cc, oct-convn.h, oct-fftw.cc, oct-fftw.h, oct-norm.cc, oct-norm.h, oct-rand.cc, oct-rand.h, oct-spparms.cc, oct-spparms.h, qr.cc, qr.h, qrp.cc, qrp.h, randgamma.cc, randgamma.h, randmtzig.cc, randmtzig.h, randpoisson.cc, randpoisson.h, schur.cc, schur.h, sparse-chol.cc, sparse-chol.h, sparse-lu.cc, sparse-lu.h, sparse-qr.cc, sparse-qr.h, svd.cc, svd.h, child-list.cc, child-list.h, dir-ops.cc, dir-ops.h, file-ops.cc, file-ops.h, file-stat.cc, file-stat.h, lo-sysdep.cc, lo-sysdep.h, lo-sysinfo.cc, lo-sysinfo.h, mach-info.cc, mach-info.h, oct-env.cc, oct-env.h, oct-group.cc, oct-group.h, oct-password.cc, oct-password.h, oct-syscalls.cc, oct-syscalls.h, oct-time.cc, oct-time.h, oct-uname.cc, oct-uname.h, action-container.cc, action-container.h, base-list.h, cmd-edit.cc, cmd-edit.h, cmd-hist.cc, cmd-hist.h, f77-fcn.h, file-info.cc, file-info.h, lo-array-errwarn.cc, lo-array-errwarn.h, lo-hash.cc, lo-hash.h, lo-ieee.h, lo-regexp.cc, lo-regexp.h, lo-utils.cc, lo-utils.h, oct-base64.cc, oct-base64.h, oct-glob.cc, oct-glob.h, oct-inttypes.h, oct-mutex.cc, oct-mutex.h, oct-refcount.h, oct-shlib.cc, oct-shlib.h, oct-sparse.cc, oct-sparse.h, oct-string.h, octave-preserve-stream-state.h, pathsearch.cc, pathsearch.h, quit.cc, quit.h, unwind-prot.cc, unwind-prot.h, url-transfer.cc, url-transfer.h : Use new macros to begin/end C++ namespaces.
author Rik <rik@octave.org>
date Thu, 01 Dec 2022 14:23:45 -0800
parents 670a0d878af1
children aac27ad79be6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30006
diff changeset
3 // Copyright (C) 2003-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21691
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21211
diff changeset
27 # include "config.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
28 #endif
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
29
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25383
diff changeset
30 #include <istream>
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21751
diff changeset
31 #include <list>
25438
cb1606f78f6b prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents: 25383
diff changeset
32 #include <ostream>
5765
7ba9ad1fec11 [project @ 2006-04-17 05:05:15 by jwe]
jwe
parents: 5760
diff changeset
33 #include <sstream>
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
34 #include <string>
5164
57077d0ddc8e [project @ 2005-02-25 19:55:24 by jwe]
jwe
parents: 5105
diff changeset
35 #include <vector>
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
36
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
37 #include "file-ops.h"
8377
25bc2d31e1bf improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents: 8021
diff changeset
38 #include "oct-locbuf.h"
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
39
25460
627d6bde9b8d solve installation info initialization problem differently
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
40 #include "defaults.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
41 #include "defun.h"
4654
a9b22513b7a6 [project @ 2003-11-24 18:56:35 by jwe]
jwe
parents: 4649
diff changeset
42 #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
43 #include "errwarn.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
44 #include "file-stat.h"
5663
775e065f7dc4 [project @ 2006-03-13 21:30:06 by jwe]
jwe
parents: 5313
diff changeset
45 #include "input.h"
23438
d24d01273bd0 eliminate load-path singleton
John W. Eaton <jwe@octave.org>
parents: 23435
diff changeset
46 #include "interpreter-private.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22091
diff changeset
47 #include "interpreter.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
48 #include "load-path.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
49 #include "oct-env.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
50 #include "oct-hdf5.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
51 #include "oct-map.h"
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
52 #include "ov-base.h"
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
53 #include "ov-cell.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
54 #include "ov-fcn-handle.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
55 #include "ov-usr-fcn.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
56 #include "parse.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
57 #include "pr-output.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
58 #include "pt-arg-list.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
59 #include "pt-assign.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
60 #include "pt-cmd.h"
23435
c452180ab672 begin refactoring parse tree evaluator
John W. Eaton <jwe@octave.org>
parents: 23433
diff changeset
61 #include "pt-eval.h"
4980
003bbf6c13d8 [project @ 2004-09-09 15:47:17 by jwe]
jwe
parents: 4978
diff changeset
62 #include "pt-exp.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
63 #include "pt-idx.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
64 #include "pt-misc.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
65 #include "pt-pr-code.h"
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
66 #include "pt-stmt.h"
28430
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
67 #include "stack-frame.h"
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
68 #include "syminfo.h"
24356
8b14ba8296af refactor symbol_record object
John W. Eaton <jwe@octave.org>
parents: 24354
diff changeset
69 #include "symscope.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
70 #include "unwind-prot.h"
23127
5a91168a30be avoid including parse tree headers in other header files unnecessarily
John W. Eaton <jwe@octave.org>
parents: 23110
diff changeset
71 #include "variables.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
72
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
73 #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
74 #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
75 #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
76 #include "ls-oct-text.h"
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
77 #include "ls-oct-binary.h"
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
78 #include "ls-utils.h"
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
79
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
80
4612
d44675070f1a [project @ 2003-11-14 19:49:56 by jwe]
jwe
parents: 4346
diff changeset
81 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
82 "function handle",
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
83 "function_handle");
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
84
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
85 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
86
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
87 OCTAVE_BEGIN_NAMESPACE(octave)
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
88
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
89 class invalid_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
90 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
91 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
92
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
93 invalid_fcn_handle (void) : base_fcn_handle ("<invalid>") { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
94
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
95 invalid_fcn_handle (const invalid_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
96
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
97 ~invalid_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
98
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
99 invalid_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
100 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
101 return new invalid_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
102 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
103
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
104 std::string type (void) const { return "<invalid>"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
105
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
106 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
107 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
108
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
109 // Create a handle to an unnamed internal function. There will be no
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
110 // way to save and reload it. See, for example, the F__fltk_check__
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
111 // function in __init_fltk__.cc.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
112
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
113 class internal_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
114 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
115 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
116
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
117 internal_fcn_handle (const octave_value& fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
118 : base_fcn_handle ("<internal>"), m_fcn (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
119 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
120
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
121 internal_fcn_handle (const internal_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
122
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
123 ~internal_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
124
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
125 internal_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
126 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
127 return new internal_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
128 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
129
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
130 std::string type (void) const { return "<internal>"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
131
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
132 bool is_internal (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
133
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
134 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
135
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
136 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
137 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
138 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
139 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
140 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
141 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
142
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
143 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
144 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
145 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
146 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
147
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
148 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
149
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
150 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
151 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
152
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
153 friend bool is_equal_to (const internal_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
154 const internal_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
155
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
156 private:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
157
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
158 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
159 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
160
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
161 class simple_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
162 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
163 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
164
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
165 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
166 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
167
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
168 simple_fcn_handle (const std::string& name = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
169 const std::string& file = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
170 const std::string& /*octaveroot*/ = "")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
171 : base_fcn_handle (name, file), m_fcn ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
172 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
173
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
174 simple_fcn_handle (const octave_value& fcn, const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
175 : base_fcn_handle (name), m_fcn (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
176 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
177 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
178 {
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
179 octave_function *oct_fcn = m_fcn.function_value ();
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
180
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
181 if (oct_fcn)
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
182 m_file = oct_fcn->fcn_file_name ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
183 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
184 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
185
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
186 simple_fcn_handle (const simple_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
187
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
188 ~simple_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
189
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
190 simple_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
191 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
192 return new simple_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
193 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
194
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
195 std::string type (void) const { return "simple"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
196
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
197 bool is_simple (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
198
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
199 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
200
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
201 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
202 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
203 octave_function * function_value (bool);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
204
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
205 octave_user_function * user_function_value (bool);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
206
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
207 octave_value fcn_val (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
208
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
209 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
210 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
211
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
212 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
213
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
214 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
215
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
216 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
217
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
218 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
219
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
220 bool save_hdf5 (octave_hdf5_id loc_hid, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
221 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
222
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
223 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
224 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
225
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
226 void print_raw (std::ostream& os, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
227 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
228
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
229 friend bool is_equal_to (const simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
230 const simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
231
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
232 private:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
233
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
234 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
235 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
236
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
237 class scoped_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
238 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
239 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
240
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
241 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
242 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
243
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
244 scoped_fcn_handle (const std::string& name = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
245 const std::string& file = "",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
246 const std::string& /*octaveroot*/ = "")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
247 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
248 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
249
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
250 scoped_fcn_handle (const octave_value& fcn, const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
251 const std::list<std::string>& parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
252
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
253 scoped_fcn_handle (const scoped_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
254
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
255 ~scoped_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
256
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
257 scoped_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
258 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
259 return new scoped_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
260 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
261
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
262 std::string type (void) const { return "scopedfunction"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
263
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
264 bool is_scoped (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
265
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
266 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
267
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
268 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
269 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
270 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
271 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
272 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
273 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
274
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
275 octave_user_function * user_function_value (bool = false)
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
276 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
277 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
278 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
279
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
280 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
281
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
282 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
283 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
284
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
285 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
286
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
287 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
288
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
289 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
290
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
291 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
292
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
293 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
294 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
295
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
296 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
297 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
298
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
299 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
300 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
301
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
302 friend bool is_equal_to (const scoped_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
303 const scoped_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
304
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
305 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
306
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
307 void find_function (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
308
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
309 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
310 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
311
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
312 // List of parent function names. The first element is the name of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
313 // m_fcn.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
314 std::list<std::string> m_parentage;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
315 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
316
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
317 class base_nested_fcn_handle : public base_fcn_handle
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
318 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
319 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
320
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
321 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
322 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
323
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
324 base_nested_fcn_handle (const std::string& name = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
325 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
326 const std::string& /*octaveroot*/ = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
327 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
328 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
329
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
330 base_nested_fcn_handle (const octave_value& fcn, const std::string& name)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
331 : base_fcn_handle (name), m_fcn (fcn)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
332 { }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
333
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
334 std::string type (void) const { return "nested"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
335
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
336 using base_fcn_handle::is_nested;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
337
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
338 bool is_nested (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
339
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
340 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
341 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
342 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
343 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
344 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
345 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
346
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
347 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
348 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
349 return m_fcn.user_function_value ();
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
350 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
351
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
352 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
353
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
354 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
355
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
356 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
357 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
358
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
359 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
360
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
361 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
362
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
363 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
365 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
366
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
367 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
368 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
369
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
370 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
371 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
372
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
373 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
374 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
375
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
376 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
377
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
378 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
379 octave_value m_fcn;
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
380 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
381
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
382 class nested_fcn_handle : public base_nested_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
383 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
384 public:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
385
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
386 // FIXME: octaveroot is temporary information used when loading
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
387 // handles. Can we avoid using it in the constructor?
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
388
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
389 nested_fcn_handle (const std::string& name = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
390 const std::string& file = "",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
391 const std::string& octaveroot = "")
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
392 : base_nested_fcn_handle (name, file, octaveroot)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
393 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
394
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
395 nested_fcn_handle (const octave_value& fcn, const std::string& name,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
396 const std::shared_ptr<stack_frame>& stack_context)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
397 : base_nested_fcn_handle (fcn, name), m_stack_context (stack_context)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
398 {
31014
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
399 if (m_stack_context)
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
400 m_stack_context->mark_closure_context ();
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
401 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
402
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
403 nested_fcn_handle (const nested_fcn_handle&) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
404
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
405 ~nested_fcn_handle (void) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
406
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
407 using base_nested_fcn_handle::is_nested;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
408
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
409 bool is_nested (const std::shared_ptr<stack_frame>& frame) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
410 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
411 return frame == m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
412 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
413
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
414 nested_fcn_handle * clone (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
415 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
416 return new nested_fcn_handle (*this);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
417 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
418
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
419 octave_value make_weak_nested_handle (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
420
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
421 octave_value_list call (int nargout, const octave_value_list& args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
422
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
423 octave_value workspace (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
424
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
425 friend bool is_equal_to (const nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
426 const nested_fcn_handle& fh2);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
427
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
428 std::shared_ptr<stack_frame> stack_context (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
429 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
430 return m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
431 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
432
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
433 protected:
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
434
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
435 // Pointer to closure stack frames.
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
436 std::shared_ptr<stack_frame> m_stack_context;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
437 };
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
438
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
439 class weak_nested_fcn_handle : public base_nested_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
440 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
441 public:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
442
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
443 weak_nested_fcn_handle (const nested_fcn_handle& nfh)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
444 : base_nested_fcn_handle (nfh), m_stack_context (nfh.stack_context ())
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
445 { }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
446
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
447 weak_nested_fcn_handle (const weak_nested_fcn_handle&) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
448
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
449 ~weak_nested_fcn_handle (void) = default;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
450
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
451 weak_nested_fcn_handle * clone (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
452 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
453 return new weak_nested_fcn_handle (*this);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
454 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
455
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
456 bool is_weak_nested (void) const { return true; }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
457
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
458 octave_value_list call (int nargout, const octave_value_list& args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
459
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
460 octave_value workspace (void) const;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
461
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
462 friend bool is_equal_to (const weak_nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
463 const weak_nested_fcn_handle& fh2);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
464
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
465 protected:
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
466
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
467 // Pointer to closure stack frames.
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
468 std::weak_ptr<stack_frame> m_stack_context;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
469 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
470
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
471 class class_simple_fcn_handle : public base_fcn_handle
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
472 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
473 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
474
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
475 // FIXME: octaveroot is temporary information used when loading
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
476 // handles. Can we avoid using it in the constructor?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
477
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
478 class_simple_fcn_handle (const std::string& name,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
479 const std::string& file,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
480 const std::string& /*octaveroot*/)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
481 : base_fcn_handle (name, file)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
482 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
483
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
484 // FIXME: is the method name supposed to be just the method name or
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
485 // also contain the object name?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
486
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
487 class_simple_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
488 const std::string& meth_nm);
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
489
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
490 class_simple_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
491 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
492 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
493
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
494 class_simple_fcn_handle (const octave_value& obj, const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
495 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
496 const std::string& meth_nm);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
497
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
498 class_simple_fcn_handle (const class_simple_fcn_handle&) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
499
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
500 ~class_simple_fcn_handle (void) = default;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
501
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
502 class_simple_fcn_handle * clone (void) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
503 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
504 return new class_simple_fcn_handle (*this);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
505 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
506
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
507 std::string type (void) const { return "classsimple"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
508
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
509 bool is_class_simple (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
510
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
511 octave_value_list call (int nargout, const octave_value_list& args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
512
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
513 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
514 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
515 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
516 {
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
517 // FIXME: Shouldn't the lookup rules here match those used in the
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
518 // call method?
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
519
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
520 if (m_fcn.is_defined ())
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
521 return m_fcn.function_value ();
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
522
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
523 symbol_table& symtab = __get_symbol_table__ ();
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
524
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
525 // FIXME: is caching the correct thing to do?
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
526 // Cache this value so that the pointer will be valid as long as the
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
527 // function handle object is valid.
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
528
29207
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
529 // FIXME: This should probably dispatch to the respective class method.
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
530 // But that breaks if a function handle is used in a class method with
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
531 // e.g. bsxfun with arguments of a different class (see bug #59661).
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
532 // m_fcn = symtab.find_method (m_name, m_dispatch_class);
dd0ad2409ef7 Improve class_simple function handle function lookup (bug #59661).
Markus Mützel <markus.muetzel@gmx.de>
parents: 29185
diff changeset
533 m_fcn = symtab.find_function (m_name, octave_value_list ());
29182
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
534
e359e0fcd6e7 improve class_simple function handle function lookup (bug #59661)
Markus Mützel <markus.muetzel@gmx.de>
parents: 29062
diff changeset
535 return m_fcn.is_defined () ? m_fcn.function_value () : nullptr;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
536 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
537
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
538 octave_user_function * user_function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
539 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
540 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
541 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
542
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
543 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
544
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
545 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
546 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
547
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
548 std::string dispatch_class (void) const { return m_dispatch_class; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
549
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
550 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
551
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
552 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
553
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
554 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
555
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
556 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
557
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
558 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
559 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
560
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
561 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
562 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
563
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
564 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
565 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
566
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
567 friend bool is_equal_to (const class_simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
568 const class_simple_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
569
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
570 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
572 // The object containing the method we are handing.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
573 octave_value m_obj;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
574
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
575 // The method we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
576 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
577
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
578 // Name of the class that m_fcn belongs to.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
579 std::string m_dispatch_class;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
580 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
581
29541
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
582 // Handles to anonymous functions are similar to handles to nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
583 // functions. If they are created in a context that contains nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
584 // functions, then they store a link to the parent call stack frames
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
585 // that are active when they are created. These call stack frames
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
586 // (closure frames) provide access to variables needed by any nested
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
587 // functions that are called from the anonymous function. Anonymous
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
588 // functions also store a list of values from their parent scope
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
589 // corresponding to the symbols in the anonymous function. This list
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
590 // of values captures the variable values that are visible in the
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
591 // scope where they are created.
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
592 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
593 // Note that because handles to anonymous and nested functions capture
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
594 // call stack frames when they are created, they will cause deletion
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
595 // of the values in those frames to be deferred until the handles to
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
596 // the anonymous or nested functions are deleted.
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
597 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
598 // Would it be possible to avoid storing the closure frames for
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
599 // handles to anonymous functions if we can determine that the
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
600 // anonymous function has no unbound variables (or parameters, which
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
601 // could be handles to nested functions?) or if it is not created in a
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
602 // context that contains nested functions?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
603 //
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
604 // Would it be possible to define anonymous functions as a special
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
605 // type of nested function object that also has an variable
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
606 // initialization list associated with it?
ebf68dde5579 add some comments for anonymous function handles
John W. Eaton <jwe@octave.org>
parents: 29478
diff changeset
607
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
608 class base_anonymous_fcn_handle : public base_fcn_handle
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
609 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
610 public:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
611
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
612 static const std::string anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
613
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
614 // Setting NAME here is a bit of a kluge to cope with a bad choice
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
615 // made to append the number of local variables to the @<anonymous>
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
616 // tag in the binary file format. See also the save_binary and
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
617 // load_binary functions.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
618
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
619 base_anonymous_fcn_handle (const std::string& name = "")
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
620 : base_fcn_handle (name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
621 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
622
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
623 base_anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
624 const stack_frame::local_vars_map& local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
625 : base_fcn_handle (anonymous), m_fcn (fcn), m_local_vars (local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
626 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
627
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
628 base_anonymous_fcn_handle (const base_anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
629
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
630 ~base_anonymous_fcn_handle (void) = default;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
631
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
632 std::string type (void) const { return "anonymous"; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
633
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
634 bool is_anonymous (void) const { return true; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
635
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
636 // FIXME: These must go away. They don't do the right thing for
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
637 // scoping or overloads.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
638 octave_function * function_value (bool = false)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
639 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
640 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
641 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
642
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
643 octave_user_function * user_function_value (bool = false)
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
644 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
645 return m_fcn.user_function_value ();
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
646 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
647
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
648 octave_value fcn_val (void) { return m_fcn; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
649
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
650 virtual octave_value workspace (void) const = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
651
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
652 // Should be const.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
653 octave_scalar_map info (void);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
654
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
655 bool save_ascii (std::ostream& os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
656
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
657 bool load_ascii (std::istream& is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
658
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
659 bool save_binary (std::ostream& os, bool save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
660
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
661 bool load_binary (std::istream& is, bool swap, mach_info::float_format fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
662
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
663 bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
664 bool save_as_floats);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
665
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
666 bool load_hdf5 (octave_hdf5_id& group_hid, octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
667 octave_hdf5_id& type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
668
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
669 void print_raw (std::ostream&, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
670 int current_print_indent_level) const;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
671
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
672 // Anonymous function handles are printed without a newline.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
673 bool print_as_scalar (void) const { return false; }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
674
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
675 bool parse (const std::string& fcn_text);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
677 protected:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
678
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
679 // The function we are handling.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
680 octave_value m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
681
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
682 // List of captured variable values for anonymous fucntions.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
683 stack_frame::local_vars_map m_local_vars;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
684 };
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
685
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
686 class anonymous_fcn_handle : public base_anonymous_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
687 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
688 public:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
689
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
690 using base_anonymous_fcn_handle::anonymous;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
691
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
692 // Setting NAME here is a bit of a kluge to cope with a bad choice
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
693 // made to append the number of local variables to the @<anonymous>
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
694 // tag in the binary file format. See also the save_binary and
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
695 // load_binary functions.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
696
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
697 anonymous_fcn_handle (const std::string& name = "")
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
698 : base_anonymous_fcn_handle (name), m_stack_context ()
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
699 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
700
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
701 anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
702 const stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
703 const std::shared_ptr<stack_frame>& stack_context = std::shared_ptr<stack_frame> ());
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
704
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
705 anonymous_fcn_handle (const anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
706
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
707 ~anonymous_fcn_handle (void) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
708
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
709 anonymous_fcn_handle * clone (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
710 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
711 return new anonymous_fcn_handle (*this);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
712 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
713
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
714 octave_value make_weak_anonymous_handle (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
715
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
716 octave_value_list call (int nargout, const octave_value_list& args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
717
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
718 octave_value workspace (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
719
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
720 friend bool is_equal_to (const anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
721 const anonymous_fcn_handle& fh2);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
722
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
723 std::shared_ptr<stack_frame> stack_context (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
724 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
725 return m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
726 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
727
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
728 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
729
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
730 // Pointer to closure stack frames.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
731 std::shared_ptr<stack_frame> m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
732 };
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
733
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
734 class weak_anonymous_fcn_handle : public base_anonymous_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
735 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
736 public:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
737
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
738 using base_anonymous_fcn_handle::anonymous;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
739
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
740 weak_anonymous_fcn_handle (const anonymous_fcn_handle& afh)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
741 : base_anonymous_fcn_handle (afh), m_stack_context (afh.stack_context ())
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
742 { }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
743
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
744 weak_anonymous_fcn_handle (const weak_anonymous_fcn_handle&) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
745
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
746 ~weak_anonymous_fcn_handle (void) = default;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
747
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
748 weak_anonymous_fcn_handle * clone (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
749 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
750 return new weak_anonymous_fcn_handle (*this);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
751 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
752
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
753 bool is_weak_anonymous (void) const { return true; }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
754
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
755 octave_value_list call (int nargout, const octave_value_list& args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
756
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
757 octave_value workspace (void) const;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
758
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
759 friend bool is_equal_to (const weak_anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
760 const weak_anonymous_fcn_handle& fh2);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
761
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
762 protected:
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
763
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
764 // Pointer to closure stack frames.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
765 std::weak_ptr<stack_frame> m_stack_context;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
766 };
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
767
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
768 extern bool is_equal_to (const anonymous_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
769 const anonymous_fcn_handle& fh2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
770
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
771 static void err_invalid_fcn_handle (const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
772 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
773 error ("invalid function handle, unable to find function for @%s",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
774 name.c_str ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
775 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
776
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
777 octave_value base_fcn_handle::make_weak_nested_handle (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
778 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
779 std::string type_str = type ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
780 error ("invalid conversion from %s handle to weak nestead handle",
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
781 type_str.c_str ());
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
782 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
783
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
784 octave_value base_fcn_handle::make_weak_anonymous_handle (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
785 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
786 std::string type_str = type ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
787 error ("invalid conversion from %s handle to weak anonymous handle",
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
788 type_str.c_str ());
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
789 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
790
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
791 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
792 base_fcn_handle::subsref (const std::string& type,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
793 const std::list<octave_value_list>& idx,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
794 int nargout)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
795 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
796 octave_value_list retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
797
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
798 switch (type[0])
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
799 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
800 case '(':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
801 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
802 int tmp_nargout = (type.length () > 1 && nargout == 0) ? 1 : nargout;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
803
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
804 retval = call (tmp_nargout, idx.front ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
805 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
806 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
807
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
808 case '{':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
809 case '.':
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
810 error ("function handle cannot be indexed with %c", type[0]);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
811
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
812 default:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
813 panic_impossible ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
814 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
815
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
816 // FIXME: perhaps there should be an
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
817 // octave_value_list::next_subsref member function? See also
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
818 // octave_builtin::subsref.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
819
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
820 if (idx.size () > 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
821 retval = retval(0).next_subsref (nargout, type, idx);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
822
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
823 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
824 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
825
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
826 octave_value
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
827 base_fcn_handle::convert_to_str_internal (bool, bool, char type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
828 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
829 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
830 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
831 return octave_value (buf.str (), type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
832 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
833
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
834 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
835 base_fcn_handle::save_ascii (std::ostream&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
836 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
837 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
838
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
839 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
840 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
841
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
842 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
843 base_fcn_handle::load_ascii (std::istream&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
844 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
845 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
846
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
847 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
848 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
849
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
850 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
851 base_fcn_handle::save_binary (std::ostream&, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
852 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
853 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
854
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
855 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
856 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
857
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
858 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
859 base_fcn_handle::load_binary (std::istream&, bool, mach_info::float_format)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
860 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
861 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
862
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
863 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
864 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
865
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
866 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
867 base_fcn_handle::save_hdf5 (octave_hdf5_id, const char *, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
868 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
869 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
870
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
871 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
872 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
873
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
874 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
875 base_fcn_handle::load_hdf5 (octave_hdf5_id&, octave_hdf5_id&, octave_hdf5_id&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
876 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
877 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
878
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
879 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
880 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
881
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
882 void base_fcn_handle::warn_load (const char *file_type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
883 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
884 std::string obj_type = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
885
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
886 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
887 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
888 "%s: loading %s files not available in this version of Octave",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
889 obj_type.c_str (), file_type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
890 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
891
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
892 void base_fcn_handle::warn_save (const char *file_type) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
893 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
894 std::string obj_type = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
895
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
896 warning_with_id
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
897 ("Octave:load-save-unavailable",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
898 "%s: saving %s files not available in this version of Octave",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
899 obj_type.c_str (), file_type);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
900 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
901
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
902 void base_fcn_handle::unimplemented (const char *op, const char *fmt) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
903 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
904 std::string htype = type ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
905
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
906 warning ("%s for %s handles with %s format is not implemented",
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
907 op, htype.c_str (), fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
908 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
909
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
910 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
911 invalid_fcn_handle::call (int, const octave_value_list&)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
912 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
913 error ("invalid call to invalid function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
914 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
915
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
916 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
917 internal_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
918 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
919 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
920
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
921 return interp.feval (m_fcn, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
922 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
923
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
924 octave_scalar_map internal_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
925 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
926 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
927
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
928 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
929 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
930 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
931
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
932 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
933 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
934
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
935 bool is_equal_to (const internal_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
936 const internal_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
937 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
938 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
939 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
940 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
941 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
942 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
943 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
944
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
945 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
946 simple_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
947 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
948 // FIXME: if m_name has a '.' in the name, lookup first component. If
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
949 // it is a classdef meta object, then build TYPE and IDX arguments and
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
950 // make a subsref call using them.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
951
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
952 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
953
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
954 octave_value fcn_to_call;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
955
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
956 // The following code is similar to part of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
957 // tree_evaluator::visit_index_expression but simpler because it
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
958 // handles a more restricted case.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
959
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
960 symbol_table& symtab = interp.get_symbol_table ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
961
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
962 std::size_t pos = m_name.find ('.');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
963
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
964 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
965 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
966 // FIXME: check to see which of these cases actually work in
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
967 // Octave and Matlab. For the last two, assume handle is
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
968 // created before object is defined as an object.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
969 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
970 // We can have one of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
971 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
972 // pkg-list . fcn (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
973 // pkg-list . cls . meth (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
974 // class-name . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
975 // class-name . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
976 // object . method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
977 // object . static-method (args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
978
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
979 // Evaluate package elements until we find a function,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
980 // classdef object, or classdef_meta object that is not a
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
981 // package. An object may only appear as the first element,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
982 // then it must be followed directly by a function name.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
983
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
984 std::size_t beg = 0;
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
985 std::size_t end = pos;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
986
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
987 std::vector<std::string> idx_elts;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
988
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
989 while (true)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
990 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
991 end = m_name.find ('.', beg);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
992
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
993 idx_elts.push_back (m_name.substr (beg, end-beg));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
994
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
995 if (end == std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
996 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
998 beg = end+1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
999 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1000
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
1001 std::size_t n_elts = idx_elts.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1002
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1003 bool have_object = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1004 octave_value partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1005
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1006 // Lazy evaluation. The first element was not known to be defined
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1007 // as an object in the scope where the handle was created. See if
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1008 // there is a definition in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1009
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1010 partial_expr_val = interp.varval (idx_elts[0]);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1011
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1012 if (partial_expr_val.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1013 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1014 if (! partial_expr_val.is_classdef_object () || n_elts != 2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1015 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1016
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1017 have_object = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1018 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1019 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1020 partial_expr_val = symtab.find_function (idx_elts[0], ovl ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1021
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1022 std::string type;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1023 std::list<octave_value_list> arg_list;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1024
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
1025 for (std::size_t i = 1; i < n_elts; i++)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1026 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1027 if (partial_expr_val.is_package ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1028 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1029 if (have_object)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1030 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1031
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1032 type = ".";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1033 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1034
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1035 try
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1036 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1037 // Silently ignore extra output values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1038
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1039 octave_value_list tmp_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1040 = partial_expr_val.subsref (type, arg_list, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1041
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1042 partial_expr_val
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1043 = tmp_list.length () ? tmp_list(0) : octave_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1044
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1045 if (partial_expr_val.is_cs_list ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1046 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1047
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1048 arg_list.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1049 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29063
diff changeset
1050 catch (const index_exception&)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1051 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1052 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1053 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1054 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1055 else if (have_object || partial_expr_val.is_classdef_meta ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1056 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1057 // Object or class name must be the next to the last
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1058 // element (it was the previous one, so if this is the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1059 // final element, it should be a classdef method,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1060 // but we'll let the classdef or classdef_meta subsref
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1061 // function sort that out.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1062
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1063 if (i != n_elts-1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1064 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1065
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1066 type = ".(";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1067 arg_list.push_back (ovl (idx_elts[i]));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1068 arg_list.push_back (args);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1069
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1070 return partial_expr_val.subsref (type, arg_list, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1071 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1072 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1073 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1074 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1075
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1076 // If we get here, we must have a function to call.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1077
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1078 if (! partial_expr_val.is_function ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1079 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1080
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1081 fcn_to_call = partial_expr_val;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1082 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1083 else
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1084 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1085 // No "." in the name.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1086
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1087 // Perform function lookup given current arguments. We'll need
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1088 // to do this regardless of whether a function was found when
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1089 // the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1090
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1091 octave_value ov_fcn = symtab.find_function (m_name, args);
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1092
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1093 if (m_fcn.is_defined ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1094 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1095 // A simple function was found when the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1096 // Use that unless we find a class method to override it.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1097
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1098 fcn_to_call = m_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1099
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1100 if (ov_fcn.is_defined ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1101 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1102 octave_function *fcn = ov_fcn.function_value ();
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1103
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1104 std::string dispatch_class = fcn->dispatch_class ();
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1105
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1106 if (fcn->is_class_method ())
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1107 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1108 // Function found through lookup is a class method
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1109 // so use it instead of the simple one found when
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1110 // the handle was created.
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1111
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1112 fcn_to_call = ov_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1113 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1114 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1115 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1116 else
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1117 {
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1118 // There was no simple function found when the handle was
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1119 // created so use the one found here (if any).
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1120
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1121 fcn_to_call = ov_fcn;
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1122 }
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1123 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1124
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1125 if (! fcn_to_call.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1126 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1127
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1128 return interp.feval (fcn_to_call, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1129 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1130
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1131 octave_function * simple_fcn_handle::function_value (bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1132 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1133 // FIXME: Shouldn't the lookup rules here match those used in the
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1134 // call method?
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1135
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1136 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1137 return m_fcn.function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1138
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1139 symbol_table& symtab = __get_symbol_table__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1140
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1141 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1142 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1143 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1144
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1145 m_fcn = symtab.find_function (m_name, octave_value_list ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1146
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1147 return m_fcn.is_defined () ? m_fcn.function_value () : nullptr;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1148 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1149
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1150 octave_user_function * simple_fcn_handle::user_function_value (bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1151 {
29062
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1152 // FIXME: Shouldn't the lookup rules here match those used in the
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1153 // call method?
9d42195f42e9 use fcn found at handle creation unless overloads are available (bug #59451)
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1154
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1155 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1156 return m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1157
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1158 symbol_table& symtab = __get_symbol_table__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1159
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1160 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1161 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1162 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1163
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1164 m_fcn = symtab.find_user_function (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1165
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1166 return m_fcn.is_defined () ? m_fcn.user_function_value () : nullptr;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1167 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1168
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1169 octave_value simple_fcn_handle::fcn_val (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1170 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1171 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1172 return m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1173
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1174 symbol_table& symtab = __get_symbol_table__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1175
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1176 // FIXME: is caching the correct thing to do?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1177 // Cache this value so that the pointer will be valid as long as the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1178 // function handle object is valid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1179
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1180 m_fcn = symtab.find_user_function (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1181
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1182 return m_fcn;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1183 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1184
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1185 octave_scalar_map simple_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1186 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1187 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1188
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1189 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1190 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1191 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1192 m.setfield ("file", file ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1193
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1194 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1195 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1196
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1197 bool simple_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1198 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1199 os << "# octaveroot: " << config::octave_exec_home () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1200
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1201 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1202 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1203 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1204
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1205 os << "# subtype: " << type () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1206
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1207 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1208
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1209 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1210 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1211
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1212 bool simple_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1213 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1214 // FIXME: If m_file is not empty, try to load the file and define
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1215 // the function? Is it an error if that fails? Or should this job
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1216 // always be deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1217
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1218 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1219 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1220
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1221 bool simple_fcn_handle::save_binary (std::ostream& os, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1222 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1223 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1224
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1225 // When is FILE defined for simple function handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1226 std::string fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1227
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1228 nmbuf << m_name << "@<simple>\n" << config::octave_exec_home ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1229 << "\n" << fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1230
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1231 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1232 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1233 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1234 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1235
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1236 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1237 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1238
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1239 bool simple_fcn_handle::load_binary (std::istream& is, bool,
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1240 mach_info::float_format)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1241 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1242 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1243 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1244
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1245 bool simple_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1246 bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1247 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1248 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1249
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1250 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1251
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1252 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1253 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1254 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1255 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1256 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1257 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1258 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1259 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1260 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1261
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1262 octave_hdf5_id space_hid, data_hid, type_hid;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1263 space_hid = data_hid = type_hid = -1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1264
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1265 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1266 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1267 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1268 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1269 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1270 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1271 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1272 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1273
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1274 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1275 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1276 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1277 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1278 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1279 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1280 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1281 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1282 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1283 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1284 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1285 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1286 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1287 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1288 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1289 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1290 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1291 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1292 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1293 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1294 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1295 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1296 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1297 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1298 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1299 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1300 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1301 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1302
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1303 std::string octaveroot = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1304
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1305 // When is FILE defined for simple fucntion handles?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1306 std::string fpath;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1307
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1308 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1309 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1310 hdims[1] = octaveroot.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1311 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1312 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1313 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1314 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1315 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1316 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1317 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1318
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1319 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1320 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1321 H5Tset_size (type_hid, octaveroot.length () + 1);
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1322 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1323 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1324 a_id = H5Acreate (group_hid, "OCTAVEROOT", type_hid, space_hid,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1325 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1326 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1327 a_id = H5Acreate (group_hid, "OCTAVEROOT", type_hid, space_hid,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
1328 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1329 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1330
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1331 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1332 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1333 retval = (H5Awrite (a_id, type_hid, octaveroot.c_str ()) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1334
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1335 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1336 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1337 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1338 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1339 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1340 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1341 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1342 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1343 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1344
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1345 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1346 hdims[0] = 1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1347 hdims[1] = fpath.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1348 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1349 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1350 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1351 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1352 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1353 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1354 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1355
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1356 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1357 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1358 H5Tset_size (type_hid, fpath.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1359
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1360 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1361 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1362 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1363 #else
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
1364 a_id = H5Acreate (group_hid, "FILE", type_hid, space_hid,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
1365 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1366 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1367
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1368 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1369 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1370 retval = (H5Awrite (a_id, type_hid, fpath.c_str ()) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1371
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1372 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1373 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1374 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1375 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1376
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1377 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1378 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1379 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1380
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1381 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1382
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1383 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1384
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1385 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1386 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1387
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1388 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1389
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1390 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1391
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1392 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1393 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1394
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1395 bool simple_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1396 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1397 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1398 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1399 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1400
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1401 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1402
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1403 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1404 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1405 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1406
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1407 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1408
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1409 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1410
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1411 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1412 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1413 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1414
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1415 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1416
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1417 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1418 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1419
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1420 void simple_fcn_handle::print_raw (std::ostream& os, bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1421 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1422 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1423 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1424 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1425 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1426
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1427 bool is_equal_to (const simple_fcn_handle& fh1, const simple_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1428 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1429 if (fh1.m_name == fh2.m_name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1430 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1431 if (fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1432 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1433
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1434 if (fh1.m_fcn.is_undefined () && fh2.m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1435 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1436 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1437
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1438 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1439 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1440
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1441 scoped_fcn_handle::scoped_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1442 const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1443 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1444 : base_fcn_handle (name), m_fcn (fcn), m_parentage (parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1445 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1446 // FIXME: should it be an error if FCN is undefined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1447
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1448 if (m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1449 {
28450
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1450 octave_function *oct_fcn = m_fcn.function_value ();
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1451
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1452 if (oct_fcn)
d0f5f42e2cf7 Avoid another shadowing warning.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28448
diff changeset
1453 m_file = oct_fcn->fcn_file_name ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1454 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1455
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1456 m_parentage.push_front (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1457 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1458
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1459 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1460 scoped_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1461 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1462 // FIXME: we aren't really using the scope yet. Hmm.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1463
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1464 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1465
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1466 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1467 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1468 // Try to find it?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1469
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1470 find_function ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1471 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1472
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1473 if (! m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1474 err_invalid_fcn_handle (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1475
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1476 return interp.feval (m_fcn, args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1477 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1478
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1479 octave_scalar_map scoped_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1480 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1481 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1482
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1483 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1484 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1485 m.setfield ("file", file ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1486
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1487 m.setfield ("parentage", Cell (m_parentage));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1488
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1489 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1490 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1491
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1492 bool scoped_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1493 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1494 os << "# octaveroot: " << config::octave_exec_home () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1495
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1496 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1497 if (! fnm.empty ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1498 os << "# path: " << fnm << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1499
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1500 os << "# subtype: " << type () << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1501
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1502 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1503
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1504 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1505 tmp.save_ascii (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1506
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1507 return os.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1508 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1509
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1510 bool scoped_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1511 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1512 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1513 ov_cell.load_ascii (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1514
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1515 if (ov_cell.iscellstr ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1516 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1517 Array<std::string> cellstr_val = ov_cell.cellstr_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1518
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1519 for (octave_idx_type i = 0; i < cellstr_val.numel (); i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1520 m_parentage.push_back (cellstr_val(i));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1521 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1522
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1523 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1524 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1525
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1526 bool scoped_fcn_handle::save_binary (std::ostream& os, bool save_as_floats)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1527 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1528 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1529
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1530 std::string fnm = file ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1531
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1532 nmbuf << m_name << "@<scopedfunction>\n" << config::octave_exec_home ()
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1533 << "\n" << fnm;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1534
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1535 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1536 int32_t len = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1537 os.write (reinterpret_cast<char *> (&len), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1538 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1539
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1540 octave_value tmp = Cell (m_parentage);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1541 tmp.save_binary (os, save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1542
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1543 return os.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1544 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1545
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1546 bool scoped_fcn_handle::load_binary (std::istream& is, bool swap,
28857
43ad651cf5a0 eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents: 28481
diff changeset
1547 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1548 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1549 octave_cell ov_cell;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1550 ov_cell.load_binary (is, swap, fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1551
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1552 if (ov_cell.iscellstr ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1553 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1554 Array<std::string> cellstr_val = ov_cell.cellstr_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1555
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1556 for (octave_idx_type i = 0; i < cellstr_val.numel (); i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1557 m_parentage.push_back (cellstr_val(i));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1558 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1559
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1560 return is.good ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1561 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1562
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1563 bool scoped_fcn_handle::save_hdf5 (octave_hdf5_id loc_id, const char *name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1564 bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1565 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1566 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1567
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1568 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1569
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1570 // FIXME: save parentage.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1572 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1573 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1574
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1575 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1576
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1577 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1578
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1579 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1580 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1581
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1582 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1583
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1584 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1585
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1586 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1587 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1588
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1589 bool scoped_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1590 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1591 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1592 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1593 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1594
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1595 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1596
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1597 // FIXME: load parentage.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1598
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1599 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1600 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1601 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1602
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1603 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1604
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1605 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1606
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1607 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1608 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1609 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1610
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1611 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1612
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1613 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1614 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1615
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1616 void scoped_fcn_handle::print_raw (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1617 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1618 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1619 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1620 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1621 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1622 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1623
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1624 bool is_equal_to (const scoped_fcn_handle& fh1, const scoped_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1625 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1626 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1627 && fh2.m_parentage == fh2.m_parentage
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1628 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1629 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1630 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1631 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1632 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1633
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1634 void scoped_fcn_handle::find_function (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1635 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1636 // Since a scoped function is not visible by itself, try to load the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1637 // file named in m_file then find and define the scoped function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1638 // It is not an error if this fails. We can report later that the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1639 // handle is invalid.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1640
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1641 symbol_table& symtab = __get_symbol_table__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1642
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1643 if (m_parentage.size () == 1)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1644 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1645 std::string dir_name = sys::file_ops::dirname (m_file);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1646
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
1647 std::size_t pos = dir_name.find_last_of (sys::file_ops::dir_sep_chars ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1648
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1649 if (pos != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1650 dir_name = dir_name.substr (0, pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1651 else if (dir_name == "private")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1652 dir_name = ".";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1653
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1654 std::string fcn_name = m_parentage.front ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1655
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1656 // FIXME: Does dir_name need to be in the load path for this to work?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1657
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1658 m_fcn = symtab.find_private_function (dir_name, m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1659
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1660 // FIXME: Verify that it is a private function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1661 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1662 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1663 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1664 std::string primary_parent_name = m_parentage.back ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1665
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1666 octave_value ov_parent_fcn
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1667 = symtab.find_user_function (primary_parent_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1668
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1669 if (ov_parent_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1670 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1671 octave_user_function *fcn = ov_parent_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1672
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1673 if (fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1674 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1675 std::string file_name = fcn->fcn_file_name ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1676
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1677 std::string oct_home = config::octave_exec_home ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1678
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1679 if (file_name.substr (0, oct_home.size ()) == oct_home)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1680 file_name = file_name.substr (oct_home.size ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1681
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1682 octave_value subfcn = fcn->find_subfunction (m_name);
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1683
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1684 if (subfcn.is_defined ())
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
1685 m_fcn = subfcn;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1686 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1687 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1688 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1689 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1690
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1691 octave_scalar_map base_nested_fcn_handle::info (void)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1692 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1693 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1694
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1695 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1696 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1697 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1698 m.setfield ("workspace", workspace ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1699
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1700 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1701 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1702
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1703 // FIXME: For save, we need a way to save the (possibly shared)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1704 // workspace. For load, we need a way to load and link to the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1705 // (possibly shared) workspace that was saved.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1706 //
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1707 // Since a nested function is not visible by itself, do we need to try
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1708 // to load the file named in m_file then find and define the function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1709 // Is it an error if that fails? Or should this job always be
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1710 // deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1711
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1712 bool base_nested_fcn_handle::save_ascii (std::ostream& os)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1713 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1714 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1715
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1716 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1717
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1718 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1719 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1720
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1721 bool base_nested_fcn_handle::load_ascii (std::istream& is)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1722 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1723 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1724
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1725 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1726
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1727 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1728 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1729
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1730 bool base_nested_fcn_handle::save_binary (std::ostream& os,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1731 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1732 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1733 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1734
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1735 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1736 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1737
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1738 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1739 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1740
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1741 bool base_nested_fcn_handle::load_binary (std::istream& is, bool swap,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1742 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1743 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1744 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1745
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1746 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1747 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1748 octave_unused_parameter (fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1749
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1750 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1751 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1752
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1753 bool base_nested_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1754 const char *name, bool)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1755 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1756 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1757
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1758 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1759
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1760 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1761 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1762
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1763 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1764
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1765 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1766
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1767 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1768 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1769
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1770 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1771
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1772 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1773
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1774 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1775 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1776
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1777 bool base_nested_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1778 octave_hdf5_id& space_hid,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1779 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1780 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1781 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1782
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1783 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1784
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1785 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1786 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1787 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1788
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1789 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1790
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1791 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1792
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1793 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1794 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1795 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1796
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1797 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1798
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1799 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1800 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1801
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1802 void base_nested_fcn_handle::print_raw (std::ostream& os,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1803 bool pr_as_read_syntax,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1804 int current_print_indent_level) const
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1805 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1806 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1807 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1808 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1809
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1810 octave_value nested_fcn_handle::make_weak_nested_handle (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1811 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1812 return octave_value (new octave_fcn_handle
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1813 (new weak_nested_fcn_handle (*this)));
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1814 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1815
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1816 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1817 nested_fcn_handle::call (int nargout, const octave_value_list& args)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1818 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1819 tree_evaluator& tw = __get_evaluator__ ();
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1820
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1821 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1822
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1823 tw.push_stack_frame (oct_usr_fcn, m_stack_context);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1824
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1825 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1826
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1827 return oct_usr_fcn->execute (tw, nargout, args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1828 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1829
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1830 octave_value nested_fcn_handle::workspace (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1831 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1832 return m_stack_context->workspace ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1833 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1834
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1835 bool is_equal_to (const nested_fcn_handle& fh1, const nested_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1836 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1837 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1838 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1839 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1840 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1841 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1842 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1843
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1844 octave_value_list
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1845 weak_nested_fcn_handle::call (int nargout, const octave_value_list& args)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1846 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1847 tree_evaluator& tw = __get_evaluator__ ();
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1848
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1849 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1850
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1851 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1852
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1853 tw.push_stack_frame (oct_usr_fcn, frames);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1854
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1855 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1856
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1857 return oct_usr_fcn->execute (tw, nargout, args);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1858 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1859
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1860 octave_value weak_nested_fcn_handle::workspace (void) const
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1861 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1862 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1863
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1864 return frames ? frames->workspace () : octave_value ();
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1865 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1866
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1867 bool is_equal_to (const weak_nested_fcn_handle& fh1,
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1868 const weak_nested_fcn_handle& fh2)
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1869 {
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1870 if (fh1.m_name == fh2.m_name
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1871 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1872 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1873 else
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1874 return false;
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1875 }
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1876
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1877 class_simple_fcn_handle::class_simple_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1878 const std::string& meth_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1879 : base_fcn_handle (meth_nm), m_obj (), m_fcn (),
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1880 m_dispatch_class (class_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1881 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1882
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1883 class_simple_fcn_handle::class_simple_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1884 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1885 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1886 : base_fcn_handle (meth_nm), m_obj (), m_fcn (fcn),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1887 m_dispatch_class (class_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1888 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1889
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1890 class_simple_fcn_handle::class_simple_fcn_handle (const octave_value& obj,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1891 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1892 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1893 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1894 : base_fcn_handle (meth_nm), m_obj (obj), m_fcn (fcn),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1895 m_dispatch_class (class_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1896 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1897
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1898 octave_value_list
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1899 class_simple_fcn_handle::call (int nargout, const octave_value_list& args)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1900 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
1901 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1902
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1903 if (m_obj.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1904 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1905 octave_value_list tmp_args = args;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1906 tmp_args.prepend (m_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1907
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1908 return interp.feval (m_fcn, tmp_args, nargout);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1909 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1910
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1911 // FIXME: is this the best approach? Should we be saving current
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1912 // dispatch class and restoring that value instead of
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1913 // unconditionally setting it to "" when we return from this
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1914 // function?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1915
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1916 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1917
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1918 unwind_action act ([&tw] () { tw.set_dispatch_class (""); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1919
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1920 tw.set_dispatch_class (m_dispatch_class);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1921
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1922 if (m_fcn.is_defined ())
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1923 return interp.feval (m_fcn, args, nargout);
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1924
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
1925 return interp.feval (fcn_name (), args, nargout);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1926 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1927
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1928 octave_scalar_map class_simple_fcn_handle::info (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1929 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1930 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1931
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1932 m.setfield ("function", fcn_name ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1933 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1934 m.setfield ("file", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1935 m.setfield ("class", dispatch_class ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1936
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1937 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1938 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1939
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1940 // FIXME: Since a class method is not visible by itself, do we need to
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1941 // try to load the file named in m_file then find and define the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1942 // function? Is it an error if that fails? Or should this job always
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1943 // be deferred until the handle is used?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1944
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1945 bool class_simple_fcn_handle::save_ascii (std::ostream& os)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1946 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1947 unimplemented ("save", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1948
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1949 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1950
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1951 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1952 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1953
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1954 bool class_simple_fcn_handle::load_ascii (std::istream& is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1955 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1956 unimplemented ("load", "text");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1957
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1958 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1959
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1960 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1961 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1962
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1963 bool class_simple_fcn_handle::save_binary (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1964 bool save_as_floats)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1965 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1966 unimplemented ("save", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1967
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1968 octave_unused_parameter (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1969 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1970
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1971 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1972 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1973
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1974 bool class_simple_fcn_handle::load_binary (std::istream& is, bool swap,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1975 mach_info::float_format fmt)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1976 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1977 unimplemented ("load", "binary");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1978
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1979 octave_unused_parameter (is);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1980 octave_unused_parameter (swap);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1981 octave_unused_parameter (fmt);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1982
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1983 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1984 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1985
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1986 bool class_simple_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1987 const char *name, bool)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1988 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1989 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1990
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1991 unimplemented ("save", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1992
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1993 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1994 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1995
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1996 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1998 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
1999
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2000 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2001 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2002
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2003 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2004
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2005 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2006
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2007 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2008 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2009
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2010 bool class_simple_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2011 octave_hdf5_id& space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2012 octave_hdf5_id& type_hid)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2013 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2014 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2015
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2016 unimplemented ("load", "hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2017
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2018 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2019 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2020 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2021
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2022 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2023
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2024 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2025
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2026 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2027 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2028 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2029
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2030 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2031
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2032 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2033 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2034
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2035 void class_simple_fcn_handle::print_raw (std::ostream& os,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2036 bool pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2037 int current_print_indent_level) const
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2038 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2039 octave_print_internal (os, '@' + m_name, pr_as_read_syntax,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2040 current_print_indent_level);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2041 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2042
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2043 bool is_equal_to (const class_simple_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2044 const class_simple_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2045 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2046 // FIXME: Also need to check object values are equivalent?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2047
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2048 if (fh1.m_name == fh2.m_name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2049 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2050 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2051 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2052 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2053 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2054
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2055 const std::string base_anonymous_fcn_handle::anonymous ("@<anonymous>");
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2056
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2057 octave_scalar_map base_anonymous_fcn_handle::info (void)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2058 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2059 octave_scalar_map m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2060
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2061 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2062 print_raw (buf, true, 0);
28455
925c169a4958 use "function" instead of "name" as field name returned from functions
John W. Eaton <jwe@octave.org>
parents: 28450
diff changeset
2063 m.setfield ("function", buf.str ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2064
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2065 m.setfield ("type", type ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2066 m.setfield ("file", "");
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2067 m.setfield ("workspace", workspace ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2068 m.setfield ("within_file_path", "");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2069
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2070 return m;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2071 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2072
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2073 bool base_anonymous_fcn_handle::save_ascii (std::ostream& os)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2074 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2075 // FIXME: can we ensure that m_fcn is always defined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2076
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2077 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2078 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2079
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2080 os << m_name << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2081
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2082 print_raw (os, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2083 os << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2084
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2085 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2086
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2087 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2088 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2089 os << "# length: " << varlen << "\n";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2090
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2091 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2092 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2093 if (! save_text_data (os, nm_val.second, nm_val.first, false, 0))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2094 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2095 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2096 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2097
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2098 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2099 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2100
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2101 bool base_anonymous_fcn_handle::load_ascii (std::istream& is)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2102 {
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2103 octave::skip_preceeding_newline (is);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2104
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2105 std::string buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2106
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2107 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2108 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2109 // Get a line of text whitespace characters included, leaving
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2110 // newline in the stream.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2111
30006
75dff8f2de2e move some load-save utilities to octave namespace
John W. Eaton <jwe@octave.org>
parents: 29961
diff changeset
2112 buf = octave::read_until_newline (is, true);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2113 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2114
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2115 std::streampos pos = is.tellg ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2116
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2117 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2118 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2119
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2120 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2121
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2122 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2123
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2124 tw.push_dummy_scope (buf);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2125 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2126
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2127 octave_idx_type len = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2128
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2129 if (extract_keyword (is, "length", len, true) && len >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2130 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2131 if (len > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2132 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2133 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2134 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2135 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2136 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2137
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2138 std::string name = read_text_data (is, "", dummy, t2, i);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2139
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2140 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2141 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2142
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2143 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2144 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2145 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2146 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2147 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2148 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2149 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2150 is.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2151 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2152
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2153 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2154 return parse (buf);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2155
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2156 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2157 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2158
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2159 bool base_anonymous_fcn_handle::save_binary (std::ostream& os,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2160 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2161 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2162 // FIXME: can we ensure that m_fcn is always defined?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2163
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2164 if (m_fcn.is_undefined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2165 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2166
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2167 std::ostringstream nmbuf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2168
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2169 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2170
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2171 nmbuf << anonymous;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2172 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2173 nmbuf << ' ' << varlen;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2174
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2175 std::string buf_str = nmbuf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2176 int32_t tmp = buf_str.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2177 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2178 os.write (buf_str.c_str (), buf_str.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2179
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2180 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2181 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2182 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2183 tmp = stmp.length ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2184 os.write (reinterpret_cast<char *> (&tmp), 4);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2185 os.write (stmp.c_str (), stmp.length ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2186
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2187 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2188 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2189 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2190 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2191 if (! save_binary_data (os, nm_val.second, nm_val.first,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2192 "", 0, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2193 return ! os.fail ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2194 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2195 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2196
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2197 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2198 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2199
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2200 bool base_anonymous_fcn_handle::load_binary (std::istream& is, bool swap,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2201 mach_info::float_format fmt)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2202 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2203 // Read extra characters in m_name as the number of local variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2204 // values in this anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2205
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2206 octave_idx_type len = 0;
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2207 std::size_t anl = anonymous.length ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2208 if (m_name.length () > anl)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2209 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2210 std::istringstream nm_is (m_name.substr (anl));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2211 nm_is >> len;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2212
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2213 // Anonymous functions don't have names. We just used this
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2214 // string as temporary storage to pass the number of local
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2215 // variable values.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2216
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2217 m_name = "";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2218 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2219
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2220 int32_t tmp;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2221
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2222 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2223 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2224 if (swap)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2225 swap_bytes<4> (&tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2226
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2227 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2228 // is.get (ctmp2, tmp+1, 0); caused is.eof () to be true though
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2229 // effectively not reading over file end
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2230 is.read (ctmp2, tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2231 ctmp2[tmp] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2232
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2233 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2234 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2235
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2236 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2237
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2238 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2239
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2240 tw.push_dummy_scope (ctmp2);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2241 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2242
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2243 if (len > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2244 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2245 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2246 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2247 octave_value t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2248 bool dummy;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2249 std::string doc;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2250
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2251 std::string name
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2252 = read_binary_data (is, swap, fmt, "", dummy, t2, doc);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2253
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2254 if (! is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2255 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2256
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2257 m_local_vars[name] = t2;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2258 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2259 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2260
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2261 if (is)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2262 return parse (ctmp2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2263
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2264 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2265 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2266
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2267 bool base_anonymous_fcn_handle::save_hdf5 (octave_hdf5_id loc_id,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2268 const char *name,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2269 bool save_as_floats)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2270 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2271 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2272
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2273 bool retval = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2274
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2275 octave_hdf5_id group_hid = -1;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2276 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2277 group_hid = H5Gcreate (loc_id, name, octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2278 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2279 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2280 group_hid = H5Gcreate (loc_id, name, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2281 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2282 if (group_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2283 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2284
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2285 octave_hdf5_id space_hid, data_hid, type_hid;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2286 space_hid = data_hid = type_hid = -1;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2287
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2288 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2289 type_hid = H5Tcopy (H5T_C_S1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2290 H5Tset_size (type_hid, m_name.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2291 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2292 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2293 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2294 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2295 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2296
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2297 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2298 hdims[0] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2299 hdims[1] = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2300 space_hid = H5Screate_simple (0, hdims, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2301 if (space_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2302 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2303 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2304 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2305 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2306 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2307 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2308 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2309 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2310 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2311 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2312 data_hid = H5Dcreate (group_hid, "nm", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2313 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2314 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2315 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2316 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2317 octave_H5P_DEFAULT, m_name.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2318 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2319 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2320 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2321 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2322 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2323 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2324 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2325
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2326 std::ostringstream buf;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2327 print_raw (buf, true, 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2328 std::string stmp = buf.str ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2329
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2330 // attach the type of the variable
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2331 H5Tset_size (type_hid, stmp.length () + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2332 if (type_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2333 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2334 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2335 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2336 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2337 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2338
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2339 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2340 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2341 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2342 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2343 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2344 data_hid = H5Dcreate (group_hid, "fcn", type_hid, space_hid,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2345 octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2346 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2347 if (data_hid < 0
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2348 || H5Dwrite (data_hid, type_hid, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2349 octave_H5P_DEFAULT, stmp.c_str ()) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2350 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2351 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2352 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2353 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2354 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2355 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2356
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2357 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2358
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2359 std::size_t varlen = m_local_vars.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2360
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2361 if (varlen > 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2362 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2363 octave_hdf5_id as_id = H5Screate (H5S_SCALAR);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2364
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2365 if (as_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2366 {
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2367 octave_hdf5_id a_id;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2368 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2369 a_id = H5Acreate (group_hid, "SYMBOL_TABLE", H5T_NATIVE_IDX, as_id,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2370 octave_H5P_DEFAULT, octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2371
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2372 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2373 a_id = H5Acreate (group_hid, "SYMBOL_TABLE", H5T_NATIVE_IDX, as_id,
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2374 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2375 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2376
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2377 if (a_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2378 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2379 retval = (H5Awrite (a_id, H5T_NATIVE_IDX, &varlen) >= 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2380
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2381 H5Aclose (a_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2382 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2383 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2384 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2385
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2386 H5Sclose (as_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2387 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2388 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2389 retval = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2390 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2391 data_hid = H5Gcreate (group_hid, "symbol table",
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2392 octave_H5P_DEFAULT, octave_H5P_DEFAULT,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2393 octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2394 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2395 data_hid = H5Gcreate (group_hid, "symbol table", 0);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2396 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2397 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2398 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2399 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2400 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2401 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2402 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2403 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2404
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2405 for (const auto& nm_val : m_local_vars)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2406 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2407 if (! add_hdf5_data (data_hid, nm_val.second, nm_val.first,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2408 "", false, save_as_floats))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2409 break;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2410 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2411
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2412 H5Gclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2413 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2414
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2415 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2416 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2417 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2418
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2419 return retval;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2420
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2421 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2422
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2423 octave_unused_parameter (loc_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2424 octave_unused_parameter (name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2425 octave_unused_parameter (save_as_floats);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2426
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2427 warn_save ("hdf5");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2428
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2429 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2430
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2431 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2432 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2433
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2434 bool base_anonymous_fcn_handle::load_hdf5 (octave_hdf5_id& group_hid,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2435 octave_hdf5_id& space_hid,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2436 octave_hdf5_id& type_hid)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2437 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2438 #if defined (HAVE_HDF5)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2440 bool success = true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2441
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2442 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2443 octave_hdf5_id data_hid = H5Dopen (group_hid, "fcn", octave_H5P_DEFAULT);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2444 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2445 octave_hdf5_id data_hid = H5Dopen (group_hid, "fcn");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2446 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2447
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2448 if (data_hid < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2449 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2450 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2451 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2452 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2453 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2454 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2455
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2456 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2457 type_hid = H5Dget_type (data_hid);
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2458 octave_hdf5_id type_class_hid = H5Tget_class (type_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2459
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2460 if (type_class_hid != H5T_STRING)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2461 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2462 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2463 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2464 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2465 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2466 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2467 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2468
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2469 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2470 space_hid = H5Dget_space (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2471 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2472
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2473 if (rank != 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2474 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2475 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2476 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2477 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2478 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2479 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2480 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2481
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2482 int slen = H5Tget_size (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2483 if (slen < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2484 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2485 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2486 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2487 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2488 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2489 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2490 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2491
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2492 OCTAVE_LOCAL_BUFFER (char, fcn_tmp, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2493
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2494 // create datatype for (null-terminated) string to read into:
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2495 octave_hdf5_id st_id = H5Tcopy (H5T_C_S1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2496 H5Tset_size (st_id, slen);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2497
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2498 if (H5Dread (data_hid, st_id, octave_H5S_ALL, octave_H5S_ALL,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2499 octave_H5P_DEFAULT, fcn_tmp)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2500 < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2501 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2502 H5Tclose (st_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2503 H5Sclose (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2504 H5Tclose (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2505 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2506 H5Gclose (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2507 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2508 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2509 H5Tclose (st_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2510 H5Dclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2511
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2512 octave_idx_type len = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2513
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2514 // we have to pull some shenanigans here to make sure
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2515 // HDF5 doesn't print out all sorts of error messages if we
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2516 // call H5Aopen for a non-existing attribute
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2517
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2518 H5E_auto_t err_fcn;
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2519 void *err_fcn_data;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2520
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2521 // turn off error reporting temporarily, but save the error
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2522 // reporting function:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2523 #if defined (HAVE_HDF5_18)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2524 H5Eget_auto (octave_H5E_DEFAULT, &err_fcn, &err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2525 H5Eset_auto (octave_H5E_DEFAULT, nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2526 #else
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2527 H5Eget_auto (&err_fcn, &err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2528 H5Eset_auto (nullptr, nullptr);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2529 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2530
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
2531 octave_hdf5_id attr_id = H5Aopen_name (group_hid, "SYMBOL_TABLE");
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2532
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2533 if (attr_id >= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2534 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2535 if (H5Aread (attr_id, H5T_NATIVE_IDX, &len) < 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2536 success = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2537
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2538 H5Aclose (attr_id);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2539 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2540
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2541 // restore error reporting:
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2542 #if defined (HAVE_HDF5_18)
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2543 H5Eset_auto (octave_H5E_DEFAULT, err_fcn, err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2544 #else
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
2545 H5Eset_auto (err_fcn, err_fcn_data);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2546 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2547
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2548 // Set up temporary scope to use for evaluating the text that
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2549 // defines the anonymous function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2550
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2551 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2552
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2553 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2554
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2555 tw.push_dummy_scope (fcn_tmp);
29253
28913793f678 prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents: 29209
diff changeset
2556 unwind_action_safe restore_scope (&tree_evaluator::pop_scope, &tw);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2557
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2558 if (len > 0 && success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2559 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2560 hsize_t num_obj = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2561 #if defined (HAVE_HDF5_18)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2562 data_hid = H5Gopen (group_hid, "symbol table", octave_H5P_DEFAULT);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2563 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2564 data_hid = H5Gopen (group_hid, "symbol table");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2565 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2566 H5Gget_num_objs (data_hid, &num_obj);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2567 H5Gclose (data_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2568
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2569 if (num_obj != static_cast<hsize_t> (len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2570 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2571
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2572 hdf5_callback_data dsub;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2573 int current_item = 0;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2574 for (octave_idx_type i = 0; i < len; i++)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2575 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2576 if (hdf5_h5g_iterate (group_hid, "symbol table", &current_item,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2577 &dsub) <= 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2578 error ("load: failed to load anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2579
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2580 m_local_vars[dsub.name] = dsub.tc;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2581 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2582 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2583
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2584 if (success)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2585 return parse (fcn_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2586
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2587 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2588
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2589 #else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2590
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2591 octave_unused_parameter (group_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2592 octave_unused_parameter (space_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2593 octave_unused_parameter (type_hid);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2594
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2595 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2596
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2597 #endif
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2598 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2599
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2600 void base_anonymous_fcn_handle::print_raw (std::ostream& os, bool, int) const
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2601 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2602 tree_print_code tpc (os);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2603
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2604 octave_user_function *f = m_fcn.user_function_value ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2605
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2606 if (! f)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2607 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2608
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2609 os << "@";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2610
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2611 // The parameter list should always be valid for anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2612 // functions, so we should always call accept for it, and it will
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2613 // print the parens for us.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2614
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2615 tree_parameter_list *p = f->parameter_list ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2616
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2617 if (p)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2618 p->accept (tpc);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2619
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2620 os << " ";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2621
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2622 tree_statement_list *b = f->body ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2623
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
2624 panic_if (b->length () != 1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2625
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2626 tree_statement *s = b->front ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2627
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2628 if (! s)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2629 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2630
30723
08b08b7f05b2 Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753)
Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
parents: 30565
diff changeset
2631 panic_unless (s->is_expression ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2632
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2633 tree_expression *e = s->expression ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2634
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2635 if (! e)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2636 error ("invalid anonymous function handle");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2637
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2638 tpc.print_fcn_handle_body (e);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2639 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2640
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2641 bool base_anonymous_fcn_handle::parse (const std::string& fcn_text)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2642 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2643 // FIXME: If evaluation of the string gives us an anonymous function
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2644 // handle object, then why extract the function and create a new
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2645 // anonymous function object? Why not just attach the workspace
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2646 // values to the object returned by eval_string? This code is also is
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2647 // duplicated in read_mat5_binary_element in ls-mat5.cc.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2648
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2649 interpreter& interp = __get_interpreter__ ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2650
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2651 // Set up temporary scope to use for evaluating the text that defines
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2652 // the anonymous function so that we don't pick up values of random
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2653 // variables that might be in the current scope.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2654
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2655 tree_evaluator& tw = interp.get_evaluator ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2656 tw.push_dummy_scope ("read_mat5_binary_element");
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2657
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2658 unwind_action act ([&tw] () { tw.pop_scope (); });
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2659
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2660 int parse_status;
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2661 octave_value anonymous_fcn_hdl
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2662 = interp.eval_string (fcn_text, true, parse_status);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2663
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2664 if (parse_status != 0)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2665 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2666
28448
97a8ec57c33e Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents: 28439
diff changeset
2667 octave_fcn_handle *fh = anonymous_fcn_hdl.fcn_handle_value ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2668
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2669 if (! fh)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2670 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2671
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2672 m_fcn = fh->fcn_val ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2673
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2674 octave_user_function *uf = m_fcn.user_function_value (true);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2675
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2676 if (uf)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2677 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2678 symbol_scope uf_scope = uf->scope ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2679
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2680 if (uf_scope)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2681 uf_scope.cache_name (m_name);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2682 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2683
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2684 return true;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2685 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2686
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2687 anonymous_fcn_handle::anonymous_fcn_handle (const octave_value& fcn,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2688 const stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2689 const std::shared_ptr<stack_frame>& stack_context)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2690 : base_anonymous_fcn_handle (fcn, local_vars),
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2691 m_stack_context (stack_context)
31014
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
2692 {
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
2693 if (m_stack_context)
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
2694 m_stack_context->mark_closure_context ();
490e8a6107d0 Fix memory leak with nested functions and anonymous functions (bug #62459)
John W. Eaton <jwe@octave.org>
parents: 30564
diff changeset
2695 }
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2696
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2697 octave_value anonymous_fcn_handle::make_weak_anonymous_handle (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2698 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2699 return octave_value (new octave_fcn_handle
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2700 (new weak_anonymous_fcn_handle (*this)));
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2701 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2702
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2703 octave_value_list
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2704 anonymous_fcn_handle::call (int nargout, const octave_value_list& args)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2705 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2706 tree_evaluator& tw = __get_evaluator__ ();
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2707
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2708 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2709
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2710 tw.push_stack_frame (oct_usr_fcn, m_local_vars, m_stack_context);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2711
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2712 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2713
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2714 return oct_usr_fcn->execute (tw, nargout, args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2715 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2716
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2717 octave_value anonymous_fcn_handle::workspace (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2718 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2719 octave_scalar_map local_vars_map;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2720
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2721 for (const auto& nm_val : m_local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2722 local_vars_map.assign (nm_val.first, nm_val.second);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2723
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2724 // FIXME: it would be more convenient if stack_frame::workspace
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2725 // returned a Cell object directly instead of a Cell in an
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2726 // octave_value object.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2727
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2728 Cell cell_frames;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2729
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2730 if (m_stack_context)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2731 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2732 octave_value ov_frames = m_stack_context->workspace ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2733 cell_frames = ov_frames.cell_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2734 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2735
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2736 octave_idx_type num_frames = cell_frames.numel ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2737 // FIXME: It seems there should be a simple way to concatenate cells...
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2738 Cell retval = Cell (num_frames+1, 1);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2739 retval(0) = m_local_vars;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2740 for (octave_idx_type i = 0; i < num_frames; i++)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2741 retval(i+1) = cell_frames(i);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2742
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2743 return retval;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2744 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2745
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2746 bool is_equal_to (const anonymous_fcn_handle& fh1,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2747 const anonymous_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2748 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2749 if (fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2750 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2751 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2752 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2753 }
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2754
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2755 octave_value_list
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2756 weak_anonymous_fcn_handle::call (int nargout, const octave_value_list& args)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2757 {
31105
670a0d878af1 eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents: 31015
diff changeset
2758 tree_evaluator& tw = __get_evaluator__ ();
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2759
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2760 octave_user_function *oct_usr_fcn = m_fcn.user_function_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2761
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2762 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2763
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2764 tw.push_stack_frame (oct_usr_fcn, m_local_vars, frames);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2765
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2766 unwind_action act ([&tw] () { tw.pop_stack_frame (); });
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2767
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2768 return oct_usr_fcn->execute (tw, nargout, args);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2769 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2770
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2771 octave_value weak_anonymous_fcn_handle::workspace (void) const
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2772 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2773 octave_scalar_map local_vars_map;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2774
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2775 for (const auto& nm_val : m_local_vars)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2776 local_vars_map.assign (nm_val.first, nm_val.second);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2777
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2778 // FIXME: it would be more convenient if stack_frame::workspace
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2779 // returned a Cell object directly instead of a Cell in an
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2780 // octave_value object.
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2781
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2782 std::shared_ptr<stack_frame> frames = m_stack_context.lock ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2783
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2784 Cell cell_frames;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2785
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2786 if (frames)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2787 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2788 octave_value ov_frames = frames->workspace ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2789 cell_frames = ov_frames.cell_value ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2790 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2791
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2792 octave_idx_type num_frames = cell_frames.numel ();
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2793
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2794 // FIXME: It seems there should be a simple way to concatenate
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2795 // cells...
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2796 Cell retval = Cell (num_frames+1, 1);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2797 retval(0) = m_local_vars;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2798 for (octave_idx_type i = 0; i < num_frames; i++)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2799 retval(i+1) = cell_frames(i);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2800
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2801 return retval;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2802 }
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2803
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2804 bool is_equal_to (const weak_anonymous_fcn_handle& fh1,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2805 const weak_anonymous_fcn_handle& fh2)
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2806 {
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2807 if (fh1.m_name == fh2.m_name
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2808 && fh1.m_fcn.is_defined () && fh2.m_fcn.is_defined ())
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2809 return fh1.m_fcn.is_copy_of (fh2.m_fcn);
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2810 else
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2811 return false;
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2812 }
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
2813
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
2814 OCTAVE_END_NAMESPACE(octave)
26962
b033cf021048 allow @obj.meth to work (bug #51709)
John W. Eaton <jwe@octave.org>
parents: 26958
diff changeset
2815
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2816 octave_fcn_handle::octave_fcn_handle (void)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2817 : octave_base_value (), m_rep (new octave::invalid_fcn_handle ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2818 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2819
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2820 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2821 : octave_base_value (), m_rep (new octave::internal_fcn_handle (fcn))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2822 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2823
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2824 octave_fcn_handle::octave_fcn_handle (const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2825 : octave_base_value (), m_rep (new octave::simple_fcn_handle (name))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2826 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2827
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2828 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2829 const std::string& name)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2830 : octave_base_value (), m_rep (new octave::simple_fcn_handle (fcn, name))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2831 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2832
28481
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2833 octave_fcn_handle::octave_fcn_handle (const std::string& class_nm,
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2834 const std::string& meth_nm)
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2835 : octave_base_value (),
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2836 m_rep (new octave::class_simple_fcn_handle (class_nm, meth_nm))
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2837 { }
1be719d8b375 fix dispatch error with classsimple function handle (bug #58572)
John W. Eaton <jwe@octave.org>
parents: 28461
diff changeset
2838
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2839 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2840 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2841 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2842 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2843 m_rep (new octave::class_simple_fcn_handle (fcn, class_nm, meth_nm))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2844 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2845
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2846 octave_fcn_handle::octave_fcn_handle (const octave_value& obj,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2847 const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2848 const std::string& class_nm,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2849 const std::string& meth_nm)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2850 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2851 m_rep (new octave::class_simple_fcn_handle (obj, fcn, class_nm, meth_nm))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2852 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2853
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2854 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2855 const std::string& name,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2856 const std::list<std::string>& parentage)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2857 : octave_base_value (),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2858 m_rep (new octave::scoped_fcn_handle (fcn, name, parentage))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2859 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2860
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2861 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2862 const std::string& name,
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
2863 const std::shared_ptr<octave::stack_frame>& stack_context)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2864 : octave_base_value (),
29476
c74ff452e2bb avoid memory leaks when returning handles to nested functions
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
2865 m_rep (new octave::nested_fcn_handle (fcn, name, stack_context))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2866 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2867
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2868 octave_fcn_handle::octave_fcn_handle (const octave_value& fcn,
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2869 const octave::stack_frame::local_vars_map& local_vars,
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2870 const std::shared_ptr<octave::stack_frame>& stack_context)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2871 : octave_base_value (),
29477
34d06c73b48d hold references to closure frames in anon functions if needed (bug #60237)
John W. Eaton <jwe@octave.org>
parents: 29476
diff changeset
2872 m_rep (new octave::anonymous_fcn_handle (fcn, local_vars, stack_context))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2873 { }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2874
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2875 octave_fcn_handle::octave_fcn_handle (octave::base_fcn_handle *rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2876 : octave_base_value (), m_rep (rep)
28430
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2877 { }
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2878
5bfa8e018704 store local init vars for anonymous functions in handle, not function object
John W. Eaton <jwe@octave.org>
parents: 28429
diff changeset
2879 octave_fcn_handle::octave_fcn_handle (const octave_fcn_handle& fh)
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2880 : octave_base_value (fh)
9450
cf714e75c656 implement overloaded function handles
Jaroslav Hajek <highegg@gmail.com>
parents: 9419
diff changeset
2881 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2882 m_rep.reset (fh.m_rep->clone ());
4924
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2883 }
9a3a32f5a27d [project @ 2004-08-02 19:04:20 by jwe]
jwe
parents: 4675
diff changeset
2884
21573
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2885 dim_vector
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2886 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
2887 {
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2888 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
2889 return dv;
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2890 }
f3f8e1d3e399 avoid mulitple definitions of static function-scope vars (bug #47372)
John W. Eaton <jwe@octave.org>
parents: 20496
diff changeset
2891
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2892 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6695
diff changeset
2893 octave_fcn_handle::save_ascii (std::ostream& os)
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2894 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2895 return m_rep->save_ascii (os);
24108
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2896 }
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2897
1a53f0c855db move some duplicate code into a separate function
John W. Eaton <jwe@octave.org>
parents: 23829
diff changeset
2898 bool
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2899 octave_fcn_handle::load_ascii (std::istream& is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2900 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2901 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2902
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2903 // Read enough to detect type then create new rep object and dispatch
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2904 // to finish loading object.
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2905
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2906 std::streampos pos = is.tellg ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2907
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2908 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
2909 if (octaveroot.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2910 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2911 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2912 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2913 }
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2914
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2915 pos = is.tellg ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2916
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2917 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
2918 if (fpath.empty ())
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2919 {
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2920 is.seekg (pos);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2921 is.clear ();
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2922 }
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
2923
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2924 if (! (octaveroot.empty () || fpath.empty ()))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2925 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
2926 std::size_t len = octaveroot.size ();
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2927 if (octaveroot == fpath.substr (0, len))
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2928 fpath = octave::config::octave_exec_home () + fpath.substr (len);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2929 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2930
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2931 pos = is.tellg ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2932
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2933 std::string subtype = extract_keyword (is, "subtype", true);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2934 if (subtype.empty ())
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2935 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2936 is.seekg (pos);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2937 is.clear ();
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2938
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2939 // We have a legacy file that can contain either an anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2940 // function or a simple function handle.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2941
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2942 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2943 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2944
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2945 if (name == anonymous)
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2946 new_rep.reset (new octave::anonymous_fcn_handle ());
4989
19b73a80e1d9 [project @ 2004-09-11 13:31:43 by jwe]
jwe
parents: 4988
diff changeset
2947 else
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2948 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2949 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2950 else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2951 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2952 // Load individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2953
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2954 if (subtype == "simple")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2955 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2956 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2957 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2958
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2959 new_rep.reset (new octave::simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2960 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2961 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2962 else if (subtype == "scopedfunction")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2963 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2964 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2965 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2966
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2967 new_rep.reset (new octave::scoped_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2968 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2969 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2970 else if (subtype == "anonymous")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2971 new_rep.reset (new octave::anonymous_fcn_handle ());
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2972 else if (subtype == "nested")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2973 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2974 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2975 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2976
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2977 new_rep.reset (new octave::nested_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2978 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2979 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2980 else if (subtype == "classsimple")
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2981 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2982 std::string name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2983 is >> name;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2984
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2985 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
2986 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2987 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2988 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2989
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2990 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2991 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2992
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2993 if (! new_rep->load_ascii (is))
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2994 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
2995
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2996 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2997
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
2998 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
2999 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3000
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3001 bool
26399
586413770c7f pass save_as_floats by value in octave_value save_binary functions
John W. Eaton <jwe@octave.org>
parents: 26376
diff changeset
3002 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
3003 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3004 return m_rep->save_binary (os, save_as_floats);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3005 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3006
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3007 bool
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3008 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
3009 octave::mach_info::float_format fmt)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3010 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3011 // Read enough to detect type then create new rep object and dispatch
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3012 // to finish loading object.
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3013
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5823
diff changeset
3014 int32_t tmp;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5663
diff changeset
3015 if (! is.read (reinterpret_cast<char *> (&tmp), 4))
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3016 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3017 if (swap)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3018 swap_bytes<4> (&tmp);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3019
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3020 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
3021 // 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
3022 // 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
3023 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
3024 ctmp1[tmp] = 0;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3025 std::string name (ctmp1);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3026
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3027 if (! is)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3028 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3029
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3030 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3031
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3032 std::size_t anl = anonymous.length ();
10261
a4fb4675accb make printing of handles more Matlab-compatible
Jaroslav Hajek <highegg@gmail.com>
parents: 10250
diff changeset
3033
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3034 if (name.length () >= anl && name.substr (0, anl) == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3035 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3036 // Even with extra info stored in the function name, anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3037 // functions look the same. Note that NAME here may have the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3038 // number of local variables appended. We decode that inside the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3039 // load_binary function.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3040
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3041 new_rep.reset (new octave::anonymous_fcn_handle (name));
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3042 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3043 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3044 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3045 // Unpack extra info stored with the function name and load
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3046 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3047 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3048
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3049 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3050 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3051 std::string subtype = "simple";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3052
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3053 if (name.find_first_of ('\n') != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3054 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3055 std::size_t pos1 = name.find_first_of ('\n');
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3056 std::size_t pos2 = name.find_first_of ('\n', pos1 + 1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3057 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3058 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3059 name = name.substr (0, pos1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3060 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3061
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3062 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3063 if (pos1 != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3064 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3065 if (name[pos1+1] == '<')
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3066 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3067 std::size_t pos2 = name.find ('>', pos1 + 2);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3068
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3069 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3070 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3071 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3072
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3073 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3074 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3075
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3076 // Anonymous should have been handled above so it is not in the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3077 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3078
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3079 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3080 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3081 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3082 new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3083 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3084 new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3085 else if (subtype == "classsimple")
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3086 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3087 octaveroot));
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
3088 }
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3089
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3090 if (! new_rep)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3091 return false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3092
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3093 if (! new_rep->load_binary (is, swap, fmt))
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3094 return false;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3095
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3096 m_rep = new_rep;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3097
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3098 return true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3099 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3100
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3101 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
3102 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
3103 bool save_as_floats)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3104 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3105 return m_rep->save_hdf5 (loc_id, name, save_as_floats);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3106 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3107
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3108 bool
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3109 octave_fcn_handle::load_hdf5 (octave_hdf5_id loc_id, const char *name_arg)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3110 {
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
3111 #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
3112
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
3113 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3114 octave_hdf5_id group_hid = H5Gopen (loc_id, name_arg, 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
3115 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3116 octave_hdf5_id group_hid = H5Gopen (loc_id, name_arg);
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
3117 #endif
7336
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3118 if (group_hid < 0)
745a8299c2b5 [project @ 2007-12-28 20:56:55 by jwe]
jwe
parents: 7065
diff changeset
3119 return false;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3120
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
3121 #if defined (HAVE_HDF5_18)
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3122 octave_hdf5_id 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
3123 #else
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3124 octave_hdf5_id 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
3125 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3126
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3127 if (data_hid < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3128 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3129 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3130 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3131 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3132
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3133 octave_hdf5_id type_hid = H5Dget_type (data_hid);
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3134 octave_hdf5_id type_class_hid = H5Tget_class (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3135
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3136 if (type_class_hid != H5T_STRING)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3137 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3138 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3139 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3140 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3141 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3142 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3143
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3144 octave_hdf5_id space_hid = H5Dget_space (data_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3145 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3146
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3147 if (rank != 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3148 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3149 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3150 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3151 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3152 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3153 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3154 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3155
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3156 int slen = H5Tget_size (type_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3157 if (slen < 0)
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3158 {
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3159 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3160 H5Tclose (type_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3161 H5Dclose (data_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3162 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3163 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3164 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3165
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3166 OCTAVE_LOCAL_BUFFER (char, nm_tmp, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3167
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3168 // create datatype for (null-terminated) string to read into:
28461
1ab57f86aac6 Restore compatibility with older versions of hdf5 (bug #58549).
Markus Mützel <markus.muetzel@gmx.de>
parents: 28455
diff changeset
3169 octave_hdf5_id st_id = H5Tcopy (H5T_C_S1);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3170 H5Tset_size (st_id, slen);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3171
22407
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3172 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
3173 octave_H5P_DEFAULT, nm_tmp)
34ce5be04942 maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents: 22327
diff changeset
3174 < 0)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3175 {
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3176 H5Tclose (st_id);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3177 H5Sclose (space_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3178 H5Tclose (type_hid);
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3179 H5Dclose (data_hid);
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3180 H5Gclose (group_hid);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3181 return false;
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3182 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3183 H5Tclose (st_id);
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3184 H5Dclose (data_hid);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3185
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3186 std::string name (nm_tmp);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3187
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3188 std::shared_ptr<octave::base_fcn_handle> new_rep;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3189
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3190 if (name == anonymous)
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3191 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3192 // Even with extra info stored in the function name, anonymous
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3193 // functions look the same.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3194
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3195 new_rep.reset (new octave::anonymous_fcn_handle ());
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3196 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3197 else
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3198 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3199 // Unpack extra info stored with the function name and load
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3200 // individual function handle types.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3201 // FIXME: is there a better way?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3202
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3203 std::string octaveroot;
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3204 std::string fpath;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3205 std::string subtype = "simple";
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3206
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3207 if (name.find_first_of ('\n') != std::string::npos)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3208 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3209 std::size_t pos1 = name.find_first_of ('\n');
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3210 std::size_t pos2 = name.find_first_of ('\n', pos1 + 1);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3211 octaveroot = name.substr (pos1 + 1, pos2 - pos1 - 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3212 fpath = name.substr (pos2 + 1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3213 name = name.substr (0, pos1);
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3214 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3215
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3216 std::size_t pos1 = name.find ('@');
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3217 if (pos1 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3218 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3219 if (name[pos1+1] == '<')
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3220 {
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29477
diff changeset
3221 std::size_t pos2 = name.find ('>', pos1 + 2);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3222
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3223 if (pos2 != std::string::npos)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3224 subtype = name.substr (pos1 + 2, pos2 - pos1 - 2);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3225 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3226
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3227 name = name.substr (0, pos1);
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10261
diff changeset
3228 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3229
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3230 // Anonymous should have been handled above so it is not in the
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3231 // following list.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3232
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3233 if (subtype == "simple")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3234 new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3235 else if (subtype == "scopedfunction")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3236 new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3237 else if (subtype == "nested")
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3238 new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3239 else if (subtype == "classsimple")
30346
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3240 new_rep.reset (new octave::class_simple_fcn_handle (name, fpath,
91c6288781ba maint: Shorten some long lines in libinterp to <= 80 characters (bug #57599)
Rik <rik@octave.org>
parents: 30337
diff changeset
3241 octaveroot));
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3242 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3243
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3244 bool status = false;
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3245
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3246 if (new_rep && new_rep->load_hdf5 (group_hid, space_hid, type_hid))
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3247 {
29185
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3248 m_rep = new_rep;
76c94c998d7b avoid memory leak with function handles (bug #59659)
John W. Eaton <jwe@octave.org>
parents: 29182
diff changeset
3249 status = true;
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3250 }
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3251
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3252 // FIXME: manage these with an unwind_action object?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3253
6695
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3254 H5Tclose (type_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3255 H5Sclose (space_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3256 H5Gclose (group_hid);
c45431c845f3 [project @ 2007-06-07 21:30:39 by dbateman]
dbateman
parents: 6657
diff changeset
3257
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3258 return status;
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
3259
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
3260 #else
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3261
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3262 octave_unused_parameter (loc_id);
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3263 octave_unused_parameter (name_arg);
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3264
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
3265 warn_load ("hdf5");
21691
263d18409fdf Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents: 21580
diff changeset
3266
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
3267 return false;
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3268
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
3269 #endif
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3270 }
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3271
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11541
diff changeset
3272 /*
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3273 %!test <*33857>
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3274 %! a = 2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3275 %! f = @(x) a + x;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3276 %! 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
3277 %! hm = @version;
7745
0ff0fc033f28 better handling of functions found by relative lookup
John W. Eaton <jwe@octave.org>
parents: 7744
diff changeset
3278 %! hdld = @svd;
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3279 %! hbi = @log2;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3280 %! f2 = f;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3281 %! g2 = g;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3282 %! hm2 = hm;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3283 %! hdld2 = hdld;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3284 %! hbi2 = hbi;
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3285 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3286 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3287 %! && __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
3288 %! modes(end+1) = "-hdf5";
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3289 %! endif
7901
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3290 %! for i = 1:numel (modes)
3e4c9b69069d call stack changes
John W. Eaton <jwe@octave.org>
parents: 7767
diff changeset
3291 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3292 %! nm = tempname ();
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3293 %! unwind_protect
22489
93ea313301f9 test: Add bug ids (<#####>) to BIST tests.
Rik <rik@octave.org>
parents: 22417
diff changeset
3294 %! f2 (1);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3295 %! 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
3296 %! clear f2 g2 hm2 hdld2 hbi2
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3297 %! load (nm);
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3298 %! assert (f (2), f2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3299 %! assert (g (2), g2 (2));
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3300 %! assert (g (3), g2 (3));
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3301 %! unlink (nm);
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3302 %! save (mode, nm, "f2", "g2", "hm2", "hdld2", "hbi2");
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3303 %! unwind_protect_cleanup
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3304 %! unlink (nm);
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3305 %! end_unwind_protect
7744
14b841c47a5f handle load/save for handles to built-in functions
John W. Eaton <jwe@octave.org>
parents: 7740
diff changeset
3306 %! endfor
6625
5d02dfacfc9e [project @ 2007-05-16 08:49:47 by dbateman]
dbateman
parents: 6481
diff changeset
3307 */
4988
352d228d409b [project @ 2004-09-11 13:05:38 by jwe]
jwe
parents: 4980
diff changeset
3308
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3309 /*
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3310 %!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
3311 %! if (n == 0)
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3312 %! 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
3313 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3314 %! 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
3315 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3316 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3317 %!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
3318 %! if (n == 0)
21580
ecce63c99c3f maint: Add semicolons to terminate code in %! blocks.
Rik <rik@octave.org>
parents: 21574
diff changeset
3319 %! load (nm);
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3320 %! else
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3321 %! [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
3322 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3323 %!endfunction
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3324
23573
1b4f4ec53b4a use new script to tag fixed bugs in tests
John W. Eaton <jwe@octave.org>
parents: 23572
diff changeset
3325 %!test <*35876>
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3326 %! a = 2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3327 %! f = @(x) a + x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3328 %! g = @(x) 2 * x;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3329 %! hm = @version;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3330 %! hdld = @svd;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3331 %! hbi = @log2;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3332 %! f2 = f;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3333 %! g2 = g;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3334 %! hm2 = hm;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3335 %! hdld2 = hdld;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3336 %! hbi2 = hbi;
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3337 %! modes = {"-text", "-binary"};
21434
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3338 %! if (isfield (__octave_config_info__, "HAVE_HDF5")
1da428cbf401 deprecate octave_config_info
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
3339 %! && __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
3340 %! modes(end+1) = "-hdf5";
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3341 %! endif
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3342 %! for i = 1:numel (modes)
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3343 %! mode = modes{i};
19278
6ca096827123 Use tempname() rather than tmpnam() in core Octave.
Rik <rik@octave.org>
parents: 18537
diff changeset
3344 %! nm = tempname ();
15235
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3345 %! unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3346 %! 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
3347 %! 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
3348 %! [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
3349 %! load (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3350 %! assert (f (2), f2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3351 %! assert (g (2), g2 (2));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3352 %! assert (g (3), g2 (3));
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3353 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3354 %! 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
3355 %! unwind_protect_cleanup
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3356 %! unlink (nm);
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3357 %! end_unwind_protect
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3358 %! endfor
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3359 */
ab3d4c1affee Use correct context when saving anonymous functions (bug #35876)
Max Brister <max@2bass.com>
parents: 15195
diff changeset
3360
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3361 void
18416
bcd71a2531d3 Support disp/display overloading in classdef
Michael Goffioul <michael.goffioul@gmail.com>
parents: 18409
diff changeset
3362 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
3363 {
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3364 print_raw (os, pr_as_read_syntax);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3365 newline (os);
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3366 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3367
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3368 void
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3369 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
3370 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3371 m_rep->print_raw (os, pr_as_read_syntax, current_print_indent_level ());
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3372 }
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3373
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3374 bool
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3375 is_equal_to (const octave_fcn_handle& fh1, const octave_fcn_handle& fh2)
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3376 {
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3377 // FIXME: Maybe there is a better way? Possibly by using typeid or
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3378 // typeindex?
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3379
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3380 // Don't include invalid_fcn_handle in the list of types to compare.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3381 // Consider them to be like NaN values so comparisons between any two
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3382 // invalid handles are always false.
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3383
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3384 if (fh1.is_internal () && fh2.is_internal ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3385 return is_equal_to (*dynamic_cast<octave::internal_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3386 *dynamic_cast<octave::internal_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3387 else if (fh1.is_simple () && fh2.is_simple ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3388 return is_equal_to (*dynamic_cast<octave::simple_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3389 *dynamic_cast<octave::simple_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3390 else if (fh1.is_scoped () && fh2.is_scoped ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3391 return is_equal_to (*dynamic_cast<octave::scoped_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3392 *dynamic_cast<octave::scoped_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3393 else if (fh1.is_nested () && fh2.is_nested ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3394 return is_equal_to (*dynamic_cast<octave::nested_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3395 *dynamic_cast<octave::nested_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3396 else if (fh1.is_class_simple () && fh2.is_class_simple ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3397 return is_equal_to (*dynamic_cast<octave::class_simple_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3398 *dynamic_cast<octave::class_simple_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3399 else if (fh1.is_anonymous () && fh2.is_anonymous ())
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3400 return is_equal_to (*dynamic_cast<octave::anonymous_fcn_handle *> (fh1.get_rep ()),
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3401 *dynamic_cast<octave::anonymous_fcn_handle *> (fh2.get_rep ()));
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3402 else
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3403 return false;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3404 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3405
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
3406 OCTAVE_BEGIN_NAMESPACE(octave)
29960
939bef0b66e0 merge "namespace octave" and OCTAVE_NAMESPACE_BEGIN/END blocks
John W. Eaton <jwe@octave.org>
parents: 29958
diff changeset
3407
23611
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3408 DEFUN (functions, args, ,
91c8f006ed8b remove additional functions from symbol_table class
John W. Eaton <jwe@octave.org>
parents: 23603
diff changeset
3409 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3410 @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
3411 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
3412 @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
3413
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3414 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
3415
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3416 @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
3417 @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
3418 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
3419 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
3420
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3421 @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
3422 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
3423
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3424 @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
3425 @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
3426 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
3427
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3428 @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
3429 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
3430
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3431 @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
3432 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
3433
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3434 @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
3435 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
3436
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3437 @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
3438 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
3439 @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
3440
26825
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3441 @item nested
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3442 The function is nested.
6e9034836239 allow handles to nested functions to work (bug #39257)
John W. Eaton <jwe@octave.org>
parents: 26796
diff changeset
3443
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3444 @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
3445 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
3446 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
3447 @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
3448
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3449 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
3450 fields.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3451
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3452 @strong{Warning:} @code{functions} is provided for debugging purposes only.
22982
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3453 Its behavior may change in the future and programs should not depend on any
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3454 particular output format.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3455
22982
aca714a80cfc doc: Add more sealso links between docstrings.
Rik <rik@octave.org>
parents: 22489
diff changeset
3456 @seealso{func2str, str2func}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3457 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3458 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3459 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3460 print_usage ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3461
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3462 octave_fcn_handle *fh = args(0).xfcn_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
3463
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3464 return ovl (fh->info ());
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3465 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3466
4933
cd58733c326b [project @ 2004-08-05 16:08:28 by jwe]
jwe
parents: 4930
diff changeset
3467 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
3468 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3469 @deftypefn {} {@var{str} =} func2str (@var{fcn_handle})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3470 Return a string containing the name of the function referenced by the function
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3471 handle @var{fcn_handle}.
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3472 @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
3473 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3474 {
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3475 if (args.length () != 1)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3476 print_usage ();
4930
bdb307dc8613 [project @ 2004-08-05 04:55:26 by jwe]
jwe
parents: 4925
diff changeset
3477
26367
4aebddba871c ov-fcn-handle.cc: Fix static analyzer detected V601 issue (bug #55347)
Andreas Weber <octave@josoansi.de>
parents: 26294
diff changeset
3478 octave_fcn_handle *fh = args(0).xfcn_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
3479
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3480 if (! fh)
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3481 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
3482
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3483 octave_value retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3484
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3485 std::string fh_nm = fh->fcn_name ();
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3486
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3487 if (fh->is_anonymous ())
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3488 {
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3489 std::ostringstream buf;
6416
59a4304b7cc5 [project @ 2007-03-15 20:37:44 by jwe]
jwe
parents: 6351
diff changeset
3490
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3491 fh->print_raw (buf);
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3492
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3493 retval = buf.str ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3494 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3495 else
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3496 retval = fh_nm;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3497
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3498 return retval;
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3499 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3500
26113
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3501 DEFMETHOD (str2func, interp, args, ,
8a15f3bace49 move eval_string inside interpreter/evaluator class
John W. Eaton <jwe@octave.org>
parents: 25969
diff changeset
3502 doc: /* -*- texinfo -*-
30888
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3503 @deftypefn {} {@var{hfcn} =} str2func (@var{str})
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3504 Return a function handle constructed from the string @var{str}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3505
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3506 The input may be the name of a function such as @qcode{"sin"} or a string
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3507 defining a function such as @qcode{"@@(x) sin (x + pi)"}.
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3508
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3509 Programming Note: In most cases it will be better to use anonymous function
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3510 syntax and let the Octave parser create the function handle rather than use
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3511 @code{str2func}. For example:
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3512
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3513 @example
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3514 @group
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3515 hfcn = @@sin ;
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3516 hfcn = @@(x) sin (x + pi) ;
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3517 @end group
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3518 @end example
32d2b6604a9f doc: Ensure documentation lists output argument when it exists for functions in libinterp/
Rik <rik@octave.org>
parents: 30723
diff changeset
3519
28432
71c34141cc2d refactor handling of parent functions and localfunctions
John W. Eaton <jwe@octave.org>
parents: 28430
diff changeset
3520 @seealso{func2str, functions}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3521 @end deftypefn */)
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3522 {
9463
d34baf412786 support non-local function lookups in str2func
Jaroslav Hajek <highegg@gmail.com>
parents: 9458
diff changeset
3523 int nargin = args.length ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3524
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3525 if (nargin < 1 || nargin > 2)
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3526 print_usage ();
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3527
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3528 std::string nm
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3529 = 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
3530
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3531 if (nm.empty ())
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3532 error ("str2func: invalid function name");
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3533
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3534 if (nm[0] == '@')
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3535 {
28439
e760fef2829c refactor octave_fcn_handle class
John W. Eaton <jwe@octave.org>
parents: 28433
diff changeset
3536 // Unlike the anonymous_fcn_handle::parse method, don't set up
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3537 // temporary scope to use for evaluating the text that defines
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3538 // the anonymous function. Here we want
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3539 //
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3540 // str2func ("@(args) expr")
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3541 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3542 // to behave the same as if
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3543 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3544 // @(args) expr
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3545 //
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3546 // were evaluated in the current scope.
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3547
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3548 int parse_status;
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3549 octave_value afh = interp.eval_string (nm, true, parse_status);
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3550
20797
492738d32c60 eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents: 20756
diff changeset
3551 if (parse_status == 0)
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3552 return afh;
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3553 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3554 else
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3555 {
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3556 if (nargin == 2)
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3557 warning_with_id ("Octave:str2func-global-argument",
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3558 "str2func: second argument ignored");
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3559
29961
7d6709900da7 eliminate octave:: namespace tags in DEFUN and DEFMETHOD and more
John W. Eaton <jwe@octave.org>
parents: 29960
diff changeset
3560 tree_evaluator& tw = interp.get_evaluator ();
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3561
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3562 return tw.make_fcn_handle (nm);
26118
7502fce4cd3a str2func: eliminate optional second "global" argument
John W. Eaton <jwe@octave.org>
parents: 26113
diff changeset
3563 }
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3564
28433
d05a4194f1ad move make_fcn_handle to tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 28432
diff changeset
3565 return ovl ();
4343
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3566 }
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3567
db5e0814277a [project @ 2003-02-20 16:44:16 by jwe]
jwe
parents:
diff changeset
3568 /*
20508
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3569 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3570 %! f = str2func ("<");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3571 %! assert (class (f), "function_handle");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3572 %! assert (func2str (f), "lt");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3573 %! assert (f (1, 2), true);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3574 %! assert (f (2, 1), false);
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3575
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3576 %!test
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3577 %! f = str2func ("@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3578 %! assert (func2str (f), "@(x) sin (x)");
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3579 %! assert (f (0:3), sin (0:3));
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3580
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3581 %!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
3582 */
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3583
df7d34a1c7e6 str2func: Allow anonymous function string inputs (bug #45682).
Rik <rik@octave.org>
parents: 20501
diff changeset
3584 /*
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3585 %!function y = __testrecursionfcn (f, x, n)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3586 %! if (nargin < 3)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3587 %! n = 0;
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3588 %! endif
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3589 %! if (n > 2)
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3590 %! y = f (x);
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3591 %! else
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3592 %! n++;
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3593 %! y = __testrecursionfcn (@(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
3594 %! endif
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3595 %!endfunction
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3596 %!
30896
c9788d7f6e65 maint: Use "fcn" as preferred abbreviation for "function" in libinterp/.
Rik <rik@octave.org>
parents: 30888
diff changeset
3597 %!assert (__testrecursionfcn (@(x) x, 1), 8)
7767
71f068b22fcc scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents: 7761
diff changeset
3598 */
10960
409ceee18acc binders optimization
Jaroslav Hajek <highegg@gmail.com>
parents: 10849
diff changeset
3599
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3600 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
3601 doc: /* -*- texinfo -*-
30559
841a10208c38 doc: Use TF for output variable in documentation for isXXX functions in libinterp/ directory.
Rik <rik@octave.org>
parents: 30346
diff changeset
3602 @deftypefn {} {@var{tf} =} is_function_handle (@var{x})
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21885
diff changeset
3603 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
3604 @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
3605 @end deftypefn */)
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3606 {
20818
cef0448a6ed2 eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents: 20797
diff changeset
3607 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
3608 print_usage ();
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3609
20939
b17fda023ca6 maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents: 20853
diff changeset
3610 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
3611 }
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3612
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3613 /*
28427
7a8c69c4eb55 convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents: 28426
diff changeset
3614 %!shared fh
14175
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3615 %! fh = @(x) x;
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3616
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3617 %!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
3618 %!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
3619 %!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
3620
14429
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3621 %!error is_function_handle ()
eff4a5933e28 Update %!tests in src/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents: 14175
diff changeset
3622 %!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
3623 */
3972c4caa60a Add new function is_function_handle (patch #7695)
Juan Pablo Carbajal <carbajal@ifi.uzh.ch>
parents: 14138
diff changeset
3624
20605
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3625 /*
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3626 %!test
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3627 %! f = @(t) eval ('2*t');
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3628 %! assert (f (21), 42);
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3629 */
f9c991dc5c1a avoid scope error in anonymous functions (bug #45835)
John W. Eaton <jwe@octave.org>
parents: 20580
diff changeset
3630
13696
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3631 /*
28317
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3632 %!test <*58389>
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3633 %! s = "x";
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3634 %! a.(s) = [e, pi];
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3635 %! f = @(x) a.(s)(x);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3636 %! assert (f(1), e);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3637 %! assert (f(2), pi);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3638 %! assert (f([2,1]), [pi, e]);
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3639 */
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3640
ac87763b1949 capture dynamic field variable values in anonymous functions (bug #58389)
John W. Eaton <jwe@octave.org>
parents: 28257
diff changeset
3641 /*
14085
4e8f23ccadce test: Use internal prefix "__" for %!functions to avoid polluting workspace
Rik <octave@nomad.inbox5.com>
parents: 13696
diff changeset
3642 %!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
3643 %! r = g(i);
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3644 %!endfunction
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3645 %!test
d6118a2c0644 fix indexing bug for matrices inside anonymous functions
John W. Eaton <jwe@octave.org>
parents: 13193
diff changeset
3646 %! 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
3647 %! 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
3648 */
29958
32c3a5805893 move DEFUN and DEFMETHOD functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 29655
diff changeset
3649
31605
e88a07dec498 maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents: 31105
diff changeset
3650 OCTAVE_END_NAMESPACE(octave)