Mercurial > octave-nkf
annotate libinterp/corefcn/mex.cc @ 17787:175b392e91fe
Use GNU style coding conventions for code in libinterp/
* libinterp/corefcn/Cell.h, libinterp/corefcn/__contourc__.cc,
libinterp/corefcn/__dispatch__.cc, libinterp/corefcn/__lin_interpn__.cc,
libinterp/corefcn/__pchip_deriv__.cc, libinterp/corefcn/__qp__.cc,
libinterp/corefcn/balance.cc, libinterp/corefcn/besselj.cc,
libinterp/corefcn/betainc.cc, libinterp/corefcn/bitfcns.cc,
libinterp/corefcn/bsxfun.cc, libinterp/corefcn/c-file-ptr-stream.cc,
libinterp/corefcn/c-file-ptr-stream.h, libinterp/corefcn/cellfun.cc,
libinterp/corefcn/colloc.cc, libinterp/corefcn/comment-list.h,
libinterp/corefcn/conv2.cc, libinterp/corefcn/daspk.cc,
libinterp/corefcn/dasrt.cc, libinterp/corefcn/dassl.cc,
libinterp/corefcn/data.cc, libinterp/corefcn/debug.cc,
libinterp/corefcn/defaults.cc, libinterp/corefcn/defaults.in.h,
libinterp/corefcn/defun-int.h, libinterp/corefcn/defun.cc,
libinterp/corefcn/det.cc, libinterp/corefcn/dirfns.cc,
libinterp/corefcn/display.cc, libinterp/corefcn/dlmread.cc,
libinterp/corefcn/dot.cc, libinterp/corefcn/dynamic-ld.cc,
libinterp/corefcn/dynamic-ld.h, libinterp/corefcn/eig.cc,
libinterp/corefcn/ellipj.cc, libinterp/corefcn/error.cc,
libinterp/corefcn/error.h, libinterp/corefcn/event-queue.h,
libinterp/corefcn/fft.cc, libinterp/corefcn/fft2.cc, libinterp/corefcn/fftn.cc,
libinterp/corefcn/file-io.cc, libinterp/corefcn/filter.cc,
libinterp/corefcn/find.cc, libinterp/corefcn/gammainc.cc,
libinterp/corefcn/gcd.cc, libinterp/corefcn/getgrent.cc,
libinterp/corefcn/getpwent.cc, libinterp/corefcn/getrusage.cc,
libinterp/corefcn/givens.cc, libinterp/corefcn/gl-render.cc,
libinterp/corefcn/gl2ps-renderer.cc, libinterp/corefcn/gl2ps-renderer.h,
libinterp/corefcn/graphics.cc, libinterp/corefcn/graphics.in.h,
libinterp/corefcn/gripes.cc, libinterp/corefcn/gripes.h,
libinterp/corefcn/help.cc, libinterp/corefcn/hess.cc,
libinterp/corefcn/hex2num.cc, libinterp/corefcn/input.cc,
libinterp/corefcn/input.h, libinterp/corefcn/inv.cc,
libinterp/corefcn/jit-ir.h, libinterp/corefcn/jit-typeinfo.cc,
libinterp/corefcn/jit-typeinfo.h, libinterp/corefcn/jit-util.h,
libinterp/corefcn/kron.cc, libinterp/corefcn/load-path.cc,
libinterp/corefcn/load-path.h, libinterp/corefcn/load-save.cc,
libinterp/corefcn/load-save.h, libinterp/corefcn/lookup.cc,
libinterp/corefcn/ls-ascii-helper.cc, libinterp/corefcn/ls-hdf5.cc,
libinterp/corefcn/ls-hdf5.h, libinterp/corefcn/ls-mat-ascii.cc,
libinterp/corefcn/ls-mat-ascii.h, libinterp/corefcn/ls-mat4.cc,
libinterp/corefcn/ls-mat5.cc, libinterp/corefcn/ls-mat5.h,
libinterp/corefcn/ls-oct-ascii.cc, libinterp/corefcn/lsode.cc,
libinterp/corefcn/lu.cc, libinterp/corefcn/luinc.cc,
libinterp/corefcn/mappers.cc, libinterp/corefcn/matrix_type.cc,
libinterp/corefcn/max.cc, libinterp/corefcn/md5sum.cc,
libinterp/corefcn/mex.cc, libinterp/corefcn/mexproto.h,
libinterp/corefcn/mgorth.cc, libinterp/corefcn/mxarray.in.h,
libinterp/corefcn/nproc.cc, libinterp/corefcn/oct-hist.cc,
libinterp/corefcn/oct-lvalue.h, libinterp/corefcn/oct-map.cc,
libinterp/corefcn/oct-map.h, libinterp/corefcn/oct-obj.h,
libinterp/corefcn/oct-prcstrm.h, libinterp/corefcn/oct-stdstrm.h,
libinterp/corefcn/oct-stream.cc, libinterp/corefcn/oct-stream.h,
libinterp/corefcn/octave-link.cc, libinterp/corefcn/octave-link.h,
libinterp/corefcn/pager.cc, libinterp/corefcn/pinv.cc,
libinterp/corefcn/pr-output.cc, libinterp/corefcn/procstream.h,
libinterp/corefcn/profiler.cc, libinterp/corefcn/pt-jit.cc,
libinterp/corefcn/pt-jit.h, libinterp/corefcn/quad.cc,
libinterp/corefcn/quadcc.cc, libinterp/corefcn/qz.cc,
libinterp/corefcn/rand.cc, libinterp/corefcn/rcond.cc,
libinterp/corefcn/regexp.cc, libinterp/corefcn/schur.cc,
libinterp/corefcn/sighandlers.cc, libinterp/corefcn/sighandlers.h,
libinterp/corefcn/sparse-xdiv.cc, libinterp/corefcn/sparse-xdiv.h,
libinterp/corefcn/sparse-xpow.cc, libinterp/corefcn/sparse.cc,
libinterp/corefcn/spparms.cc, libinterp/corefcn/sqrtm.cc,
libinterp/corefcn/str2double.cc, libinterp/corefcn/strfind.cc,
libinterp/corefcn/strfns.cc, libinterp/corefcn/sub2ind.cc,
libinterp/corefcn/svd.cc, libinterp/corefcn/syl.cc,
libinterp/corefcn/symtab.cc, libinterp/corefcn/symtab.h,
libinterp/corefcn/syscalls.cc, libinterp/corefcn/sysdep.cc,
libinterp/corefcn/sysdep.h, libinterp/corefcn/time.cc,
libinterp/corefcn/toplev.cc, libinterp/corefcn/toplev.h,
libinterp/corefcn/tril.cc, libinterp/corefcn/txt-eng-ft.cc,
libinterp/corefcn/txt-eng-ft.h, libinterp/corefcn/txt-eng.h,
libinterp/corefcn/typecast.cc, libinterp/corefcn/urlwrite.cc,
libinterp/corefcn/utils.cc, libinterp/corefcn/variables.cc,
libinterp/corefcn/variables.h, libinterp/corefcn/xdiv.cc,
libinterp/corefcn/xdiv.h, libinterp/corefcn/xnorm.h, libinterp/corefcn/xpow.cc,
libinterp/corefcn/xpow.h, libinterp/corefcn/zfstream.cc,
libinterp/corefcn/zfstream.h, libinterp/dldfcn/__delaunayn__.cc,
libinterp/dldfcn/__dsearchn__.cc, libinterp/dldfcn/__eigs__.cc,
libinterp/dldfcn/__fltk_uigetfile__.cc, libinterp/dldfcn/__glpk__.cc,
libinterp/dldfcn/__init_fltk__.cc, libinterp/dldfcn/__init_gnuplot__.cc,
libinterp/dldfcn/__magick_read__.cc, libinterp/dldfcn/__voronoi__.cc,
libinterp/dldfcn/amd.cc, libinterp/dldfcn/ccolamd.cc, libinterp/dldfcn/chol.cc,
libinterp/dldfcn/colamd.cc, libinterp/dldfcn/convhulln.cc,
libinterp/dldfcn/dmperm.cc, libinterp/dldfcn/fftw.cc, libinterp/dldfcn/qr.cc,
libinterp/dldfcn/symbfact.cc, libinterp/dldfcn/symrcm.cc,
libinterp/dldfcn/tsearch.cc, libinterp/octave-value/ov-base-diag.cc,
libinterp/octave-value/ov-base-diag.h, libinterp/octave-value/ov-base-int.cc,
libinterp/octave-value/ov-base-int.h, libinterp/octave-value/ov-base-mat.h,
libinterp/octave-value/ov-base-scalar.cc,
libinterp/octave-value/ov-base-scalar.h,
libinterp/octave-value/ov-base-sparse.cc,
libinterp/octave-value/ov-base-sparse.h, libinterp/octave-value/ov-base.cc,
libinterp/octave-value/ov-base.h, libinterp/octave-value/ov-bool-mat.cc,
libinterp/octave-value/ov-bool-mat.h, libinterp/octave-value/ov-bool-sparse.cc,
libinterp/octave-value/ov-bool-sparse.h, libinterp/octave-value/ov-bool.cc,
libinterp/octave-value/ov-bool.h, libinterp/octave-value/ov-builtin.cc,
libinterp/octave-value/ov-builtin.h, libinterp/octave-value/ov-cell.cc,
libinterp/octave-value/ov-cell.h, libinterp/octave-value/ov-ch-mat.cc,
libinterp/octave-value/ov-ch-mat.h, libinterp/octave-value/ov-class.cc,
libinterp/octave-value/ov-class.h, libinterp/octave-value/ov-colon.h,
libinterp/octave-value/ov-complex.cc, libinterp/octave-value/ov-complex.h,
libinterp/octave-value/ov-cx-diag.cc, libinterp/octave-value/ov-cx-diag.h,
libinterp/octave-value/ov-cx-mat.cc, libinterp/octave-value/ov-cx-mat.h,
libinterp/octave-value/ov-cx-sparse.cc, libinterp/octave-value/ov-cx-sparse.h,
libinterp/octave-value/ov-dld-fcn.h, libinterp/octave-value/ov-fcn-handle.cc,
libinterp/octave-value/ov-fcn-handle.h,
libinterp/octave-value/ov-fcn-inline.cc,
libinterp/octave-value/ov-fcn-inline.h, libinterp/octave-value/ov-fcn.h,
libinterp/octave-value/ov-float.cc, libinterp/octave-value/ov-float.h,
libinterp/octave-value/ov-flt-complex.cc,
libinterp/octave-value/ov-flt-complex.h,
libinterp/octave-value/ov-flt-cx-diag.cc,
libinterp/octave-value/ov-flt-cx-diag.h,
libinterp/octave-value/ov-flt-cx-mat.cc,
libinterp/octave-value/ov-flt-cx-mat.h,
libinterp/octave-value/ov-flt-re-diag.cc,
libinterp/octave-value/ov-flt-re-diag.h,
libinterp/octave-value/ov-flt-re-mat.cc,
libinterp/octave-value/ov-flt-re-mat.h, libinterp/octave-value/ov-int16.cc,
libinterp/octave-value/ov-int32.cc, libinterp/octave-value/ov-int64.cc,
libinterp/octave-value/ov-int8.cc, libinterp/octave-value/ov-intx.h,
libinterp/octave-value/ov-java.cc, libinterp/octave-value/ov-lazy-idx.h,
libinterp/octave-value/ov-mex-fcn.cc, libinterp/octave-value/ov-mex-fcn.h,
libinterp/octave-value/ov-null-mat.cc, libinterp/octave-value/ov-null-mat.h,
libinterp/octave-value/ov-oncleanup.cc, libinterp/octave-value/ov-perm.cc,
libinterp/octave-value/ov-perm.h, libinterp/octave-value/ov-range.cc,
libinterp/octave-value/ov-range.h, libinterp/octave-value/ov-re-diag.cc,
libinterp/octave-value/ov-re-diag.h, libinterp/octave-value/ov-re-mat.cc,
libinterp/octave-value/ov-re-mat.h, libinterp/octave-value/ov-re-sparse.cc,
libinterp/octave-value/ov-re-sparse.h, libinterp/octave-value/ov-scalar.cc,
libinterp/octave-value/ov-scalar.h, libinterp/octave-value/ov-str-mat.cc,
libinterp/octave-value/ov-str-mat.h, libinterp/octave-value/ov-struct.cc,
libinterp/octave-value/ov-struct.h, libinterp/octave-value/ov-type-conv.h,
libinterp/octave-value/ov-typeinfo.cc, libinterp/octave-value/ov-typeinfo.h,
libinterp/octave-value/ov-uint16.cc, libinterp/octave-value/ov-uint32.cc,
libinterp/octave-value/ov-uint64.cc, libinterp/octave-value/ov-uint8.cc,
libinterp/octave-value/ov-usr-fcn.cc, libinterp/octave-value/ov-usr-fcn.h,
libinterp/octave-value/ov.cc, libinterp/octave-value/ov.h, libinterp/octave.cc,
libinterp/operators/op-b-bm.cc, libinterp/operators/op-b-sbm.cc,
libinterp/operators/op-bm-b.cc, libinterp/operators/op-bm-bm.cc,
libinterp/operators/op-cdm-cdm.cc, libinterp/operators/op-chm.cc,
libinterp/operators/op-class.cc, libinterp/operators/op-cm-cm.cc,
libinterp/operators/op-cm-cs.cc, libinterp/operators/op-cm-s.cc,
libinterp/operators/op-cm-scm.cc, libinterp/operators/op-cm-sm.cc,
libinterp/operators/op-cs-cm.cc, libinterp/operators/op-cs-cs.cc,
libinterp/operators/op-cs-scm.cc, libinterp/operators/op-cs-sm.cc,
libinterp/operators/op-dm-dm.cc, libinterp/operators/op-dm-scm.cc,
libinterp/operators/op-double-conv.cc, libinterp/operators/op-fcdm-fcdm.cc,
libinterp/operators/op-fcm-fcm.cc, libinterp/operators/op-fcm-fcs.cc,
libinterp/operators/op-fcm-fm.cc, libinterp/operators/op-fcm-fs.cc,
libinterp/operators/op-fcs-fcm.cc, libinterp/operators/op-fcs-fcs.cc,
libinterp/operators/op-fcs-fm.cc, libinterp/operators/op-fcs-fs.cc,
libinterp/operators/op-fdm-fdm.cc, libinterp/operators/op-float-conv.cc,
libinterp/operators/op-fm-fcm.cc, libinterp/operators/op-fm-fcs.cc,
libinterp/operators/op-fm-fm.cc, libinterp/operators/op-fm-fs.cc,
libinterp/operators/op-fs-fcm.cc, libinterp/operators/op-fs-fcs.cc,
libinterp/operators/op-fs-fm.cc, libinterp/operators/op-fs-fs.cc,
libinterp/operators/op-m-cm.cc, libinterp/operators/op-m-cs.cc,
libinterp/operators/op-m-m.cc, libinterp/operators/op-m-s.cc,
libinterp/operators/op-m-scm.cc, libinterp/operators/op-m-sm.cc,
libinterp/operators/op-pm-scm.cc, libinterp/operators/op-range.cc,
libinterp/operators/op-s-cm.cc, libinterp/operators/op-s-cs.cc,
libinterp/operators/op-s-scm.cc, libinterp/operators/op-sbm-b.cc,
libinterp/operators/op-sbm-bm.cc, libinterp/operators/op-sbm-sbm.cc,
libinterp/operators/op-scm-cm.cc, libinterp/operators/op-scm-cs.cc,
libinterp/operators/op-scm-m.cc, libinterp/operators/op-scm-s.cc,
libinterp/operators/op-scm-scm.cc, libinterp/operators/op-scm-sm.cc,
libinterp/operators/op-sm-cm.cc, libinterp/operators/op-sm-m.cc,
libinterp/operators/op-sm-s.cc, libinterp/operators/op-sm-scm.cc,
libinterp/operators/op-sm-sm.cc, libinterp/operators/op-str-m.cc,
libinterp/operators/op-str-s.cc, libinterp/operators/op-str-str.cc,
libinterp/operators/ops.h, libinterp/parse-tree/lex.h,
libinterp/parse-tree/parse.h, libinterp/parse-tree/pt-arg-list.cc,
libinterp/parse-tree/pt-arg-list.h, libinterp/parse-tree/pt-assign.cc,
libinterp/parse-tree/pt-assign.h, libinterp/parse-tree/pt-binop.cc,
libinterp/parse-tree/pt-binop.h, libinterp/parse-tree/pt-bp.h,
libinterp/parse-tree/pt-cbinop.cc, libinterp/parse-tree/pt-check.cc,
libinterp/parse-tree/pt-colon.cc, libinterp/parse-tree/pt-colon.h,
libinterp/parse-tree/pt-const.cc, libinterp/parse-tree/pt-decl.cc,
libinterp/parse-tree/pt-decl.h, libinterp/parse-tree/pt-eval.cc,
libinterp/parse-tree/pt-except.h, libinterp/parse-tree/pt-exp.h,
libinterp/parse-tree/pt-fcn-handle.cc, libinterp/parse-tree/pt-id.cc,
libinterp/parse-tree/pt-id.h, libinterp/parse-tree/pt-idx.cc,
libinterp/parse-tree/pt-idx.h, libinterp/parse-tree/pt-loop.h,
libinterp/parse-tree/pt-mat.cc, libinterp/parse-tree/pt-misc.cc,
libinterp/parse-tree/pt-misc.h, libinterp/parse-tree/pt-pr-code.cc,
libinterp/parse-tree/pt-select.h, libinterp/parse-tree/pt-stmt.h,
libinterp/parse-tree/token.h, libinterp/version.cc:
Use GNU style coding conventions for code in libinterp/
author | Rik <rik@octave.org> |
---|---|
date | Mon, 28 Oct 2013 19:51:46 -0700 |
parents | d63878346099 |
children | 6da521da1c70 |
rev | line source |
---|---|
7016 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
17429
diff
changeset
|
3 Copyright (C) 2006-2013 John W. Eaton |
7016 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 3 of the License, or (at your | |
10 option) any later version. | |
11 | |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
18 along with Octave; see the file COPYING. If not, see | |
19 <http://www.gnu.org/licenses/>. | |
20 | |
21 */ | |
22 | |
5900 | 23 #include <config.h> |
5864 | 24 |
25 #include <cfloat> | |
26 #include <csetjmp> | |
5900 | 27 #include <cstdarg> |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstdlib> |
5900 | 29 #include <cstring> |
30 #include <cctype> | |
31 | |
5864 | 32 #include <set> |
5900 | 33 |
34 #include "f77-fcn.h" | |
35 #include "lo-ieee.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7901
diff
changeset
|
36 #include "oct-locbuf.h" |
5900 | 37 |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15096
diff
changeset
|
38 #include "Cell.h" |
5900 | 39 // mxArray must be declared as a class before including mexproto.h. |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15096
diff
changeset
|
40 #include "mxarray.h" |
5900 | 41 #include "mexproto.h" |
42 #include "oct-map.h" | |
43 #include "oct-obj.h" | |
44 #include "ov.h" | |
6068 | 45 #include "ov-mex-fcn.h" |
5900 | 46 #include "ov-usr-fcn.h" |
5864 | 47 #include "pager.h" |
48 #include "parse.h" | |
49 #include "toplev.h" | |
5900 | 50 #include "unwind-prot.h" |
51 #include "utils.h" | |
5864 | 52 #include "variables.h" |
6595 | 53 #include "graphics.h" |
5900 | 54 |
55 // #define DEBUG 1 | |
56 | |
5905 | 57 static void |
58 xfree (void *ptr) | |
59 { | |
60 ::free (ptr); | |
61 } | |
62 | |
6806 | 63 static mwSize |
64 max_str_len (mwSize m, const char **str) | |
5900 | 65 { |
66 int max_len = 0; | |
67 | |
6806 | 68 for (mwSize i = 0; i < m; i++) |
5900 | 69 { |
6806 | 70 mwSize tmp = strlen (str[i]); |
5900 | 71 |
72 if (tmp > max_len) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
73 max_len = tmp; |
5900 | 74 } |
75 | |
76 return max_len; | |
77 } | |
78 | |
79 static int | |
80 valid_key (const char *key) | |
81 { | |
82 int retval = 0; | |
83 | |
84 int nel = strlen (key); | |
85 | |
86 if (nel > 0) | |
87 { | |
88 if (isalpha (key[0])) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
89 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
90 for (int i = 1; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
91 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
92 if (! (isalnum (key[i]) || key[i] == '_')) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
93 goto done; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
94 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
95 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
96 retval = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
97 } |
5900 | 98 } |
99 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
100 done: |
5900 | 101 |
102 return retval; | |
103 } | |
104 | |
105 // ------------------------------------------------------------------ | |
106 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
107 void |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
108 mxArray_base::error (const char *msg) const |
5900 | 109 { |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
110 // FIXME |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
111 ::error ("%s", msg); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
112 } |
5900 | 113 |
7357 | 114 static mwIndex |
115 calc_single_subscript_internal (mwSize ndims, const mwSize *dims, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
116 mwSize nsubs, const mwIndex *subs) |
7357 | 117 { |
118 mwIndex retval = 0; | |
119 | |
120 switch (nsubs) | |
121 { | |
122 case 0: | |
123 break; | |
124 | |
125 case 1: | |
126 retval = subs[0]; | |
127 break; | |
128 | |
129 default: | |
130 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
131 // Both nsubs and ndims should be at least 2 here. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
132 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
133 mwSize n = nsubs <= ndims ? nsubs : ndims; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
134 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
135 retval = subs[--n]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
136 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
137 while (--n >= 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
138 retval = dims[n] * retval + subs[n]; |
7357 | 139 } |
140 break; | |
141 } | |
142 | |
143 return retval; | |
144 } | |
145 | |
5900 | 146 // The object that handles values pass to MEX files from Octave. Some |
147 // methods in this class may set mutate_flag to TRUE to tell the | |
148 // mxArray class to convert to the Matlab-style representation and | |
149 // then invoke the method on that object instead (for example, getting | |
150 // a pointer to real or imaginary data from a complex object requires | |
151 // a mutation but getting a pointer to real data from a real object | |
152 // does not). Changing the representation causes a copy so we try to | |
153 // avoid it unless it is really necessary. Once the conversion | |
154 // happens, we delete this representation, so the conversion can only | |
155 // happen once per call to a MEX file. | |
156 | |
7179 | 157 static inline void *maybe_mark_foreign (void *ptr); |
158 | |
5900 | 159 class mxArray_octave_value : public mxArray_base |
160 { | |
161 public: | |
162 | |
163 mxArray_octave_value (const octave_value& ov) | |
164 : mxArray_base (), val (ov), mutate_flag (false), | |
165 id (mxUNKNOWN_CLASS), class_name (0), ndims (-1), dims (0) { } | |
166 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
167 mxArray_base *dup (void) const { return new mxArray_octave_value (*this); } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
168 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
169 mxArray *as_mxArray (void) const |
12331
f39436e14734
mex.cc (mxArray_octave_value::dup): if value can't be converted to mxArray object, create a clone of the mxArray_octave_value container
John W. Eaton <jwe@octave.org>
parents:
12123
diff
changeset
|
170 { |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
171 return val.as_mxArray (); |
12331
f39436e14734
mex.cc (mxArray_octave_value::dup): if value can't be converted to mxArray object, create a clone of the mxArray_octave_value container
John W. Eaton <jwe@octave.org>
parents:
12123
diff
changeset
|
172 } |
5900 | 173 |
174 ~mxArray_octave_value (void) | |
175 { | |
176 mxFree (class_name); | |
177 mxFree (dims); | |
178 } | |
179 | |
180 bool is_octave_value (void) const { return true; } | |
181 | |
182 int is_cell (void) const { return val.is_cell (); } | |
183 | |
184 int is_char (void) const { return val.is_string (); } | |
185 | |
186 int is_complex (void) const { return val.is_complex_type (); } | |
187 | |
188 int is_double (void) const { return val.is_double_type (); } | |
189 | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
190 int is_function_handle (void) const { return val.is_function_handle (); } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
191 |
5900 | 192 int is_int16 (void) const { return val.is_int16_type (); } |
193 | |
194 int is_int32 (void) const { return val.is_int32_type (); } | |
195 | |
196 int is_int64 (void) const { return val.is_int64_type (); } | |
197 | |
198 int is_int8 (void) const { return val.is_int8_type (); } | |
199 | |
200 int is_logical (void) const { return val.is_bool_type (); } | |
201 | |
202 int is_numeric (void) const { return val.is_numeric_type (); } | |
203 | |
204 int is_single (void) const { return val.is_single_type (); } | |
205 | |
206 int is_sparse (void) const { return val.is_sparse_type (); } | |
207 | |
208 int is_struct (void) const { return val.is_map (); } | |
209 | |
210 int is_uint16 (void) const { return val.is_uint16_type (); } | |
211 | |
6069 | 212 int is_uint32 (void) const { return val.is_uint32_type (); } |
213 | |
214 int is_uint64 (void) const { return val.is_uint64_type (); } | |
215 | |
216 int is_uint8 (void) const { return val.is_uint8_type (); } | |
5900 | 217 |
218 int is_range (void) const { return val.is_range (); } | |
219 | |
220 int is_real_type (void) const { return val.is_real_type (); } | |
221 | |
222 int is_logical_scalar_true (void) const | |
223 { | |
224 return (is_logical_scalar () && val.is_true ()); | |
225 } | |
226 | |
6686 | 227 mwSize get_m (void) const { return val.rows (); } |
228 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
229 mwSize get_n (void) const |
6187 | 230 { |
6686 | 231 mwSize n = 1; |
6187 | 232 |
233 // Force dims and ndims to be cached. | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14840
diff
changeset
|
234 get_dimensions (); |
6187 | 235 |
6686 | 236 for (mwIndex i = ndims - 1; i > 0; i--) |
6187 | 237 n *= dims[i]; |
238 | |
239 return n; | |
240 } | |
5900 | 241 |
6686 | 242 mwSize *get_dimensions (void) const |
5900 | 243 { |
244 if (! dims) | |
245 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
246 ndims = val.ndims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
247 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
248 dims = static_cast<mwSize *> (mxArray::malloc (ndims |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
249 * sizeof (mwSize))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
250 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
251 dim_vector dv = val.dims (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
252 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
253 for (mwIndex i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
254 dims[i] = dv(i); |
5900 | 255 } |
256 | |
257 return dims; | |
258 } | |
259 | |
6686 | 260 mwSize get_number_of_dimensions (void) const |
5900 | 261 { |
6332 | 262 // Force dims and ndims to be cached. |
263 get_dimensions (); | |
5900 | 264 |
265 return ndims; | |
266 } | |
267 | |
6686 | 268 void set_m (mwSize /*m*/) { request_mutation (); } |
269 | |
270 void set_n (mwSize /*n*/) { request_mutation (); } | |
271 | |
272 void set_dimensions (mwSize */*dims_arg*/, mwSize /*ndims_arg*/) | |
5900 | 273 { |
6400 | 274 request_mutation (); |
5900 | 275 } |
276 | |
6686 | 277 mwSize get_number_of_elements (void) const { return val.numel (); } |
5900 | 278 |
279 int is_empty (void) const { return val.is_empty (); } | |
280 | |
281 mxClassID get_class_id (void) const | |
282 { | |
283 id = mxUNKNOWN_CLASS; | |
284 | |
285 std::string cn = val.class_name (); | |
286 | |
287 if (cn == "cell") | |
288 id = mxCELL_CLASS; | |
289 else if (cn == "struct") | |
290 id = mxSTRUCT_CLASS; | |
291 else if (cn == "logical") | |
292 id = mxLOGICAL_CLASS; | |
293 else if (cn == "char") | |
294 id = mxCHAR_CLASS; | |
295 else if (cn == "double") | |
296 id = mxDOUBLE_CLASS; | |
297 else if (cn == "single") | |
298 id = mxSINGLE_CLASS; | |
299 else if (cn == "int8") | |
300 id = mxINT8_CLASS; | |
301 else if (cn == "uint8") | |
302 id = mxUINT8_CLASS; | |
303 else if (cn == "int16") | |
304 id = mxINT16_CLASS; | |
305 else if (cn == "uint16") | |
306 id = mxUINT16_CLASS; | |
307 else if (cn == "int32") | |
308 id = mxINT32_CLASS; | |
309 else if (cn == "uint32") | |
310 id = mxUINT32_CLASS; | |
311 else if (cn == "int64") | |
312 id = mxINT64_CLASS; | |
313 else if (cn == "uint64") | |
314 id = mxUINT64_CLASS; | |
6218 | 315 else if (cn == "function_handle") |
5900 | 316 id = mxFUNCTION_CLASS; |
317 | |
318 return id; | |
319 } | |
320 | |
321 const char *get_class_name (void) const | |
322 { | |
323 if (! class_name) | |
324 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
325 std::string s = val.class_name (); |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
326 class_name = mxArray::strsave (s.c_str ()); |
5900 | 327 } |
328 | |
329 return class_name; | |
330 } | |
331 | |
332 // Not allowed. | |
6400 | 333 void set_class_name (const char */*name_arg*/) { request_mutation (); } |
5900 | 334 |
6686 | 335 mxArray *get_cell (mwIndex /*idx*/) const |
5900 | 336 { |
337 request_mutation (); | |
338 return 0; | |
339 } | |
340 | |
341 // Not allowed. | |
6686 | 342 void set_cell (mwIndex /*idx*/, mxArray */*val*/) { request_mutation (); } |
5900 | 343 |
6332 | 344 double get_scalar (void) const { return val.scalar_value (true); } |
345 | |
5900 | 346 void *get_data (void) const |
347 { | |
9358
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
348 void *retval = val.mex_get_data (); |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
349 |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
350 if (retval) |
d4b1314a7c31
mex.cc (mxArray_octave_value::get_data): avoid enumerating types that can be handled as foreign
John W. Eaton <jwe@octave.org>
parents:
9144
diff
changeset
|
351 maybe_mark_foreign (retval); |
5900 | 352 else |
353 request_mutation (); | |
354 | |
355 return retval; | |
356 } | |
357 | |
358 void *get_imag_data (void) const | |
359 { | |
360 void *retval = 0; | |
361 | |
362 if (is_numeric () && is_real_type ()) | |
363 retval = 0; | |
364 else | |
365 request_mutation (); | |
366 | |
367 return retval; | |
368 } | |
369 | |
370 // Not allowed. | |
6400 | 371 void set_data (void */*pr*/) { request_mutation (); } |
5900 | 372 |
373 // Not allowed. | |
6400 | 374 void set_imag_data (void */*pi*/) { request_mutation (); } |
5900 | 375 |
6686 | 376 mwIndex *get_ir (void) const |
5900 | 377 { |
7179 | 378 return static_cast<mwIndex *> (maybe_mark_foreign (val.mex_get_ir ())); |
5900 | 379 } |
380 | |
6686 | 381 mwIndex *get_jc (void) const |
5900 | 382 { |
7179 | 383 return static_cast<mwIndex *> (maybe_mark_foreign (val.mex_get_jc ())); |
5900 | 384 } |
385 | |
6686 | 386 mwSize get_nzmax (void) const { return val.nzmax (); } |
5900 | 387 |
388 // Not allowed. | |
6686 | 389 void set_ir (mwIndex */*ir*/) { request_mutation (); } |
5900 | 390 |
391 // Not allowed. | |
6686 | 392 void set_jc (mwIndex */*jc*/) { request_mutation (); } |
5900 | 393 |
394 // Not allowed. | |
6686 | 395 void set_nzmax (mwSize /*nzmax*/) { request_mutation (); } |
5900 | 396 |
397 // Not allowed. | |
398 int add_field (const char */*key*/) | |
399 { | |
6400 | 400 request_mutation (); |
401 return 0; | |
5900 | 402 } |
403 | |
404 // Not allowed. | |
6400 | 405 void remove_field (int /*key_num*/) { request_mutation (); } |
5900 | 406 |
6686 | 407 mxArray *get_field_by_number (mwIndex /*index*/, int /*key_num*/) const |
5900 | 408 { |
409 request_mutation (); | |
410 return 0; | |
411 } | |
412 | |
413 // Not allowed. | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
414 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
415 mxArray */*val*/) |
5900 | 416 { |
6400 | 417 request_mutation (); |
5900 | 418 } |
419 | |
420 int get_number_of_fields (void) const { return val.nfields (); } | |
421 | |
422 const char *get_field_name_by_number (int /*key_num*/) const | |
423 { | |
424 request_mutation (); | |
425 return 0; | |
426 } | |
427 | |
428 int get_field_number (const char */*key*/) const | |
429 { | |
430 request_mutation (); | |
431 return 0; | |
432 } | |
433 | |
6686 | 434 int get_string (char *buf, mwSize buflen) const |
5900 | 435 { |
436 int retval = 1; | |
437 | |
6686 | 438 mwSize nel = get_number_of_elements (); |
5900 | 439 |
440 if (val.is_string () && nel < buflen) | |
441 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
442 charNDArray tmp = val.char_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
443 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
444 const char *p = tmp.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
445 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
446 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
447 buf[i] = p[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
448 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
449 buf[nel] = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
450 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
451 retval = 0; |
5900 | 452 } |
453 | |
454 return retval; | |
455 } | |
456 | |
457 char *array_to_string (void) const | |
458 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 // FIXME: this is suposed to handle multi-byte character strings. |
5900 | 460 |
461 char *buf = 0; | |
462 | |
463 if (val.is_string ()) | |
464 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
465 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
466 |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
467 buf = static_cast<char *> (mxArray::malloc (nel + 1)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
468 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
469 if (buf) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
470 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
471 charNDArray tmp = val.char_array_value (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
472 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
473 const char *p = tmp.data (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
474 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
475 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
476 buf[i] = p[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
477 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
478 buf[nel] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
479 } |
5900 | 480 } |
481 | |
482 return buf; | |
483 } | |
484 | |
6686 | 485 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const |
5900 | 486 { |
487 // Force ndims, dims to be cached. | |
488 get_dimensions (); | |
489 | |
7357 | 490 return calc_single_subscript_internal (ndims, dims, nsubs, subs); |
5900 | 491 } |
492 | |
6686 | 493 size_t get_element_size (void) const |
5900 | 494 { |
495 // Force id to be cached. | |
496 get_class_id (); | |
497 | |
498 switch (id) | |
499 { | |
500 case mxCELL_CLASS: return sizeof (mxArray *); | |
501 case mxSTRUCT_CLASS: return sizeof (mxArray *); | |
502 case mxLOGICAL_CLASS: return sizeof (mxLogical); | |
503 case mxCHAR_CLASS: return sizeof (mxChar); | |
504 case mxDOUBLE_CLASS: return sizeof (double); | |
505 case mxSINGLE_CLASS: return sizeof (float); | |
506 case mxINT8_CLASS: return 1; | |
507 case mxUINT8_CLASS: return 1; | |
508 case mxINT16_CLASS: return 2; | |
509 case mxUINT16_CLASS: return 2; | |
510 case mxINT32_CLASS: return 4; | |
511 case mxUINT32_CLASS: return 4; | |
512 case mxINT64_CLASS: return 8; | |
513 case mxUINT64_CLASS: return 8; | |
514 case mxFUNCTION_CLASS: return 0; | |
515 default: return 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
516 } |
5900 | 517 } |
518 | |
519 bool mutation_needed (void) const { return mutate_flag; } | |
520 | |
521 void request_mutation (void) const | |
522 { | |
523 if (mutate_flag) | |
524 panic_impossible (); | |
525 | |
526 mutate_flag = true; | |
527 } | |
528 | |
529 mxArray *mutate (void) const { return val.as_mxArray (); } | |
530 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
531 octave_value as_octave_value (void) const { return val; } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
532 |
5900 | 533 protected: |
534 | |
535 mxArray_octave_value (const mxArray_octave_value& arg) | |
536 : mxArray_base (arg), val (arg.val), mutate_flag (arg.mutate_flag), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
537 id (arg.id), class_name (mxArray::strsave (arg.class_name)), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
538 ndims (arg.ndims), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 dims (ndims > 0 ? static_cast<mwSize *> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
540 (mxArray::malloc (ndims * sizeof (mwSize))) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
541 : 0) |
5900 | 542 { |
543 if (dims) | |
544 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
545 for (mwIndex i = 0; i < ndims; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
546 dims[i] = arg.dims[i]; |
5900 | 547 } |
548 } | |
549 | |
550 private: | |
551 | |
552 octave_value val; | |
553 | |
554 mutable bool mutate_flag; | |
555 | |
556 // Caching these does not cost much or lead to much duplicated | |
557 // code. For other things, we just request mutation to a | |
558 // Matlab-style mxArray object. | |
559 | |
560 mutable mxClassID id; | |
561 mutable char *class_name; | |
6686 | 562 mutable mwSize ndims; |
563 mutable mwSize *dims; | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
564 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
565 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
566 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
567 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
568 mxArray_octave_value& operator = (const mxArray_octave_value&); |
5900 | 569 }; |
570 | |
571 // The base class for the Matlab-style representation, used to handle | |
572 // things that are common to all Matlab-style objects. | |
573 | |
574 class mxArray_matlab : public mxArray_base | |
575 { | |
576 protected: | |
577 | |
578 mxArray_matlab (mxClassID id_arg = mxUNKNOWN_CLASS) | |
579 : mxArray_base (), class_name (0), id (id_arg), ndims (0), dims (0) { } | |
580 | |
6686 | 581 mxArray_matlab (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg) |
5900 | 582 : mxArray_base (), class_name (0), id (id_arg), |
583 ndims (ndims_arg < 2 ? 2 : ndims_arg), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
584 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 585 { |
586 if (ndims_arg < 2) | |
587 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
588 dims[0] = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
589 dims[1] = 1; |
5900 | 590 } |
591 | |
6686 | 592 for (mwIndex i = 0; i < ndims_arg; i++) |
5900 | 593 dims[i] = dims_arg[i]; |
594 | |
6686 | 595 for (mwIndex i = ndims - 1; i > 1; i--) |
5900 | 596 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
597 if (dims[i] == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
598 ndims--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
599 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
600 break; |
5900 | 601 } |
602 } | |
603 | |
604 mxArray_matlab (mxClassID id_arg, const dim_vector& dv) | |
605 : mxArray_base (), class_name (0), id (id_arg), | |
606 ndims (dv.length ()), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
607 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 608 { |
6686 | 609 for (mwIndex i = 0; i < ndims; i++) |
5900 | 610 dims[i] = dv(i); |
611 | |
6686 | 612 for (mwIndex i = ndims - 1; i > 1; i--) |
5900 | 613 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
614 if (dims[i] == 1) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
615 ndims--; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
616 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
617 break; |
5900 | 618 } |
619 } | |
620 | |
6686 | 621 mxArray_matlab (mxClassID id_arg, mwSize m, mwSize n) |
5900 | 622 : mxArray_base (), class_name (0), id (id_arg), ndims (2), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
623 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 624 { |
625 dims[0] = m; | |
626 dims[1] = n; | |
627 } | |
628 | |
629 public: | |
630 | |
631 ~mxArray_matlab (void) | |
632 { | |
633 mxFree (class_name); | |
634 mxFree (dims); | |
635 } | |
636 | |
637 int is_cell (void) const { return id == mxCELL_CLASS; } | |
638 | |
639 int is_char (void) const { return id == mxCHAR_CLASS; } | |
640 | |
641 int is_complex (void) const { return 0; } | |
642 | |
643 int is_double (void) const { return id == mxDOUBLE_CLASS; } | |
644 | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
645 int is_function_handle (void) const { return id == mxFUNCTION_CLASS; } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
646 |
5900 | 647 int is_int16 (void) const { return id == mxINT16_CLASS; } |
648 | |
649 int is_int32 (void) const { return id == mxINT32_CLASS; } | |
650 | |
651 int is_int64 (void) const { return id == mxINT64_CLASS; } | |
652 | |
653 int is_int8 (void) const { return id == mxINT8_CLASS; } | |
654 | |
655 int is_logical (void) const { return id == mxLOGICAL_CLASS; } | |
656 | |
657 int is_numeric (void) const | |
658 { | |
659 return (id == mxDOUBLE_CLASS || id == mxSINGLE_CLASS | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
660 || id == mxINT8_CLASS || id == mxUINT8_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
661 || id == mxINT16_CLASS || id == mxUINT16_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
662 || id == mxINT32_CLASS || id == mxUINT32_CLASS |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
663 || id == mxINT64_CLASS || id == mxUINT64_CLASS); |
5900 | 664 } |
665 | |
666 int is_single (void) const { return id == mxSINGLE_CLASS; } | |
667 | |
668 int is_sparse (void) const { return 0; } | |
669 | |
670 int is_struct (void) const { return id == mxSTRUCT_CLASS; } | |
671 | |
672 int is_uint16 (void) const { return id == mxUINT16_CLASS; } | |
673 | |
674 int is_uint32 (void) const { return id == mxUINT32_CLASS; } | |
675 | |
676 int is_uint64 (void) const { return id == mxUINT64_CLASS; } | |
677 | |
678 int is_uint8 (void) const { return id == mxUINT8_CLASS; } | |
679 | |
680 int is_logical_scalar_true (void) const | |
681 { | |
682 return (is_logical_scalar () | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
683 && static_cast<mxLogical *> (get_data ())[0] != 0); |
5900 | 684 } |
685 | |
6686 | 686 mwSize get_m (void) const { return dims[0]; } |
687 | |
688 mwSize get_n (void) const | |
6187 | 689 { |
6686 | 690 mwSize n = 1; |
691 | |
692 for (mwSize i = ndims - 1 ; i > 0 ; i--) | |
6187 | 693 n *= dims[i]; |
694 | |
695 return n; | |
696 } | |
5900 | 697 |
6686 | 698 mwSize *get_dimensions (void) const { return dims; } |
699 | |
700 mwSize get_number_of_dimensions (void) const { return ndims; } | |
701 | |
702 void set_m (mwSize m) { dims[0] = m; } | |
703 | |
704 void set_n (mwSize n) { dims[1] = n; } | |
705 | |
706 void set_dimensions (mwSize *dims_arg, mwSize ndims_arg) | |
5900 | 707 { |
708 dims = dims_arg; | |
709 ndims = ndims_arg; | |
710 } | |
711 | |
6686 | 712 mwSize get_number_of_elements (void) const |
5900 | 713 { |
6686 | 714 mwSize retval = dims[0]; |
715 | |
716 for (mwIndex i = 1; i < ndims; i++) | |
5900 | 717 retval *= dims[i]; |
718 | |
719 return retval; | |
720 } | |
721 | |
722 int is_empty (void) const { return get_number_of_elements () == 0; } | |
723 | |
724 mxClassID get_class_id (void) const { return id; } | |
725 | |
726 const char *get_class_name (void) const | |
727 { | |
728 switch (id) | |
729 { | |
730 case mxCELL_CLASS: return "cell"; | |
731 case mxSTRUCT_CLASS: return "struct"; | |
732 case mxLOGICAL_CLASS: return "logical"; | |
733 case mxCHAR_CLASS: return "char"; | |
734 case mxDOUBLE_CLASS: return "double"; | |
735 case mxSINGLE_CLASS: return "single"; | |
736 case mxINT8_CLASS: return "int8"; | |
737 case mxUINT8_CLASS: return "uint8"; | |
738 case mxINT16_CLASS: return "int16"; | |
739 case mxUINT16_CLASS: return "uint16"; | |
740 case mxINT32_CLASS: return "int32"; | |
741 case mxUINT32_CLASS: return "uint32"; | |
742 case mxINT64_CLASS: return "int64"; | |
743 case mxUINT64_CLASS: return "uint64"; | |
6218 | 744 case mxFUNCTION_CLASS: return "function_handle"; |
5900 | 745 default: return "unknown"; |
746 } | |
747 } | |
748 | |
749 void set_class_name (const char *name_arg) | |
750 { | |
751 mxFree (class_name); | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
752 class_name = static_cast<char *> (mxArray::malloc (strlen (name_arg) + 1)); |
5900 | 753 strcpy (class_name, name_arg); |
754 } | |
755 | |
6686 | 756 mxArray *get_cell (mwIndex /*idx*/) const |
5900 | 757 { |
758 invalid_type_error (); | |
759 return 0; | |
760 } | |
761 | |
6686 | 762 void set_cell (mwIndex /*idx*/, mxArray */*val*/) |
5900 | 763 { |
764 invalid_type_error (); | |
765 } | |
766 | |
6332 | 767 double get_scalar (void) const |
768 { | |
769 invalid_type_error (); | |
770 return 0; | |
771 } | |
772 | |
5900 | 773 void *get_data (void) const |
774 { | |
775 invalid_type_error (); | |
776 return 0; | |
777 } | |
778 | |
779 void *get_imag_data (void) const | |
780 { | |
781 invalid_type_error (); | |
782 return 0; | |
783 } | |
784 | |
785 void set_data (void */*pr*/) | |
786 { | |
787 invalid_type_error (); | |
788 } | |
789 | |
790 void set_imag_data (void */*pi*/) | |
791 { | |
792 invalid_type_error (); | |
793 } | |
794 | |
6686 | 795 mwIndex *get_ir (void) const |
5900 | 796 { |
797 invalid_type_error (); | |
798 return 0; | |
799 } | |
800 | |
6686 | 801 mwIndex *get_jc (void) const |
5900 | 802 { |
803 invalid_type_error (); | |
804 return 0; | |
805 } | |
806 | |
6686 | 807 mwSize get_nzmax (void) const |
5900 | 808 { |
809 invalid_type_error (); | |
810 return 0; | |
811 } | |
812 | |
6686 | 813 void set_ir (mwIndex */*ir*/) |
5900 | 814 { |
815 invalid_type_error (); | |
816 } | |
817 | |
6686 | 818 void set_jc (mwIndex */*jc*/) |
5900 | 819 { |
820 invalid_type_error (); | |
821 } | |
822 | |
6686 | 823 void set_nzmax (mwSize /*nzmax*/) |
5900 | 824 { |
825 invalid_type_error (); | |
826 } | |
827 | |
828 int add_field (const char */*key*/) | |
829 { | |
830 invalid_type_error (); | |
831 return -1; | |
832 } | |
833 | |
834 void remove_field (int /*key_num*/) | |
835 { | |
836 invalid_type_error (); | |
837 } | |
838 | |
6686 | 839 mxArray *get_field_by_number (mwIndex /*index*/, int /*key_num*/) const |
5900 | 840 { |
841 invalid_type_error (); | |
842 return 0; | |
843 } | |
844 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
845 void set_field_by_number (mwIndex /*index*/, int /*key_num*/, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
846 mxArray */*val*/) |
5900 | 847 { |
848 invalid_type_error (); | |
849 } | |
850 | |
851 int get_number_of_fields (void) const | |
852 { | |
853 invalid_type_error (); | |
854 return 0; | |
855 } | |
856 | |
857 const char *get_field_name_by_number (int /*key_num*/) const | |
858 { | |
859 invalid_type_error (); | |
860 return 0; | |
861 } | |
862 | |
863 int get_field_number (const char */*key*/) const | |
864 { | |
865 return -1; | |
866 } | |
867 | |
6686 | 868 int get_string (char */*buf*/, mwSize /*buflen*/) const |
5900 | 869 { |
870 invalid_type_error (); | |
871 return 0; | |
872 } | |
873 | |
874 char *array_to_string (void) const | |
875 { | |
876 invalid_type_error (); | |
877 return 0; | |
878 } | |
879 | |
6686 | 880 mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const |
5900 | 881 { |
7357 | 882 return calc_single_subscript_internal (ndims, dims, nsubs, subs); |
5900 | 883 } |
884 | |
6686 | 885 size_t get_element_size (void) const |
5900 | 886 { |
887 switch (id) | |
888 { | |
889 case mxCELL_CLASS: return sizeof (mxArray *); | |
890 case mxSTRUCT_CLASS: return sizeof (mxArray *); | |
891 case mxLOGICAL_CLASS: return sizeof (mxLogical); | |
892 case mxCHAR_CLASS: return sizeof (mxChar); | |
893 case mxDOUBLE_CLASS: return sizeof (double); | |
894 case mxSINGLE_CLASS: return sizeof (float); | |
895 case mxINT8_CLASS: return 1; | |
896 case mxUINT8_CLASS: return 1; | |
897 case mxINT16_CLASS: return 2; | |
898 case mxUINT16_CLASS: return 2; | |
899 case mxINT32_CLASS: return 4; | |
900 case mxUINT32_CLASS: return 4; | |
901 case mxINT64_CLASS: return 8; | |
902 case mxUINT64_CLASS: return 8; | |
903 case mxFUNCTION_CLASS: return 0; | |
904 default: return 0; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
905 } |
5900 | 906 } |
907 | |
908 protected: | |
909 | |
910 mxArray_matlab (const mxArray_matlab& val) | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
911 : mxArray_base (val), class_name (mxArray::strsave (val.class_name)), |
5900 | 912 id (val.id), ndims (val.ndims), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
913 dims (static_cast<mwSize *> (mxArray::malloc (ndims * sizeof (mwSize)))) |
5900 | 914 { |
6686 | 915 for (mwIndex i = 0; i < ndims; i++) |
5900 | 916 dims[i] = val.dims[i]; |
917 } | |
918 | |
919 dim_vector | |
920 dims_to_dim_vector (void) const | |
921 { | |
6686 | 922 mwSize nd = get_number_of_dimensions (); |
923 | |
924 mwSize *d = get_dimensions (); | |
5900 | 925 |
926 dim_vector dv; | |
927 dv.resize (nd); | |
928 | |
6686 | 929 for (mwIndex i = 0; i < nd; i++) |
5900 | 930 dv(i) = d[i]; |
931 | |
932 return dv; | |
933 } | |
934 | |
935 private: | |
936 | |
937 char *class_name; | |
938 | |
939 mxClassID id; | |
940 | |
6686 | 941 mwSize ndims; |
942 mwSize *dims; | |
5900 | 943 |
944 void invalid_type_error (void) const | |
945 { | |
946 error ("invalid type for operation"); | |
947 } | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
948 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
949 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
950 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
951 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
952 mxArray_matlab& operator = (const mxArray_matlab&); |
5900 | 953 }; |
954 | |
955 // Matlab-style numeric, character, and logical data. | |
956 | |
957 class mxArray_number : public mxArray_matlab | |
958 { | |
959 public: | |
960 | |
6686 | 961 mxArray_number (mxClassID id_arg, mwSize ndims_arg, const mwSize *dims_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
962 mxComplexity flag = mxREAL) |
5900 | 963 : mxArray_matlab (id_arg, ndims_arg, dims_arg), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
964 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
965 pi (flag == mxCOMPLEX ? mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
966 get_element_size ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
967 : 0) { } |
5900 | 968 |
969 mxArray_number (mxClassID id_arg, const dim_vector& dv, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
970 mxComplexity flag = mxREAL) |
5900 | 971 : mxArray_matlab (id_arg, dv), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
972 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
973 pi (flag == mxCOMPLEX ? mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
974 get_element_size ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
975 : 0) { } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
976 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
977 mxArray_number (mxClassID id_arg, mwSize m, mwSize n, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
978 mxComplexity flag = mxREAL) |
5900 | 979 : mxArray_matlab (id_arg, m, n), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
980 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
981 pi (flag == mxCOMPLEX ? mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
982 get_element_size ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
983 : 0) { } |
5900 | 984 |
985 mxArray_number (mxClassID id_arg, double val) | |
986 : mxArray_matlab (id_arg, 1, 1), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
987 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
5900 | 988 pi (0) |
989 { | |
990 double *dpr = static_cast<double *> (pr); | |
991 dpr[0] = val; | |
992 } | |
993 | |
994 mxArray_number (mxClassID id_arg, mxLogical val) | |
995 : mxArray_matlab (id_arg, 1, 1), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
996 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
5900 | 997 pi (0) |
998 { | |
999 mxLogical *lpr = static_cast<mxLogical *> (pr); | |
1000 lpr[0] = val; | |
1001 } | |
1002 | |
1003 mxArray_number (const char *str) | |
10853
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1004 : mxArray_matlab (mxCHAR_CLASS, |
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1005 str ? (strlen (str) ? 1 : 0) : 0, |
c3813056f94f
mxArray_number (const char *): create empty string if given NULL arg
John W. Eaton <jwe@octave.org>
parents:
10463
diff
changeset
|
1006 str ? strlen (str) : 0), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1007 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1008 pi (0) |
5900 | 1009 { |
1010 mxChar *cpr = static_cast<mxChar *> (pr); | |
6686 | 1011 mwSize nel = get_number_of_elements (); |
1012 for (mwIndex i = 0; i < nel; i++) | |
5900 | 1013 cpr[i] = str[i]; |
1014 } | |
1015 | |
6686 | 1016 // FIXME?? |
6806 | 1017 mxArray_number (mwSize m, const char **str) |
5900 | 1018 : mxArray_matlab (mxCHAR_CLASS, m, max_str_len (m, str)), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1019 pr (mxArray::calloc (get_number_of_elements (), get_element_size ())), |
5900 | 1020 pi (0) |
1021 { | |
1022 mxChar *cpr = static_cast<mxChar *> (pr); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1023 |
6686 | 1024 mwSize *dv = get_dimensions (); |
1025 | |
1026 mwSize nc = dv[1]; | |
1027 | |
1028 for (mwIndex j = 0; j < m; j++) | |
5900 | 1029 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1030 const char *ptr = str[j]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1031 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1032 size_t tmp_len = strlen (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1033 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1034 for (size_t i = 0; i < tmp_len; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1035 cpr[m*i+j] = static_cast<mxChar> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1036 |
14632
954e1a180375
Silence warnings.
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
14138
diff
changeset
|
1037 for (size_t i = tmp_len; i < static_cast<size_t>(nc); i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1038 cpr[m*i+j] = static_cast<mxChar> (' '); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1039 } |
5900 | 1040 } |
1041 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1042 mxArray_base *dup (void) const { return new mxArray_number (*this); } |
5900 | 1043 |
1044 ~mxArray_number (void) | |
1045 { | |
1046 mxFree (pr); | |
1047 mxFree (pi); | |
1048 } | |
1049 | |
5907 | 1050 int is_complex (void) const { return pi != 0; } |
1051 | |
6332 | 1052 double get_scalar (void) const |
1053 { | |
1054 double retval = 0; | |
1055 | |
1056 switch (get_class_id ()) | |
1057 { | |
1058 case mxLOGICAL_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1059 retval = *(static_cast<bool *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1060 break; |
6332 | 1061 |
1062 case mxCHAR_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1063 retval = *(static_cast<mxChar *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1064 break; |
6332 | 1065 |
1066 case mxSINGLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1067 retval = *(static_cast<float *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1068 break; |
6332 | 1069 |
1070 case mxDOUBLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1071 retval = *(static_cast<double *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1072 break; |
6332 | 1073 |
1074 case mxINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1075 retval = *(static_cast<int8_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1076 break; |
6332 | 1077 |
1078 case mxUINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1079 retval = *(static_cast<uint8_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1080 break; |
6332 | 1081 |
1082 case mxINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1083 retval = *(static_cast<int16_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1084 break; |
6332 | 1085 |
1086 case mxUINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1087 retval = *(static_cast<uint16_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1088 break; |
6332 | 1089 |
1090 case mxINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1091 retval = *(static_cast<int32_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1092 break; |
6332 | 1093 |
1094 case mxUINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1095 retval = *(static_cast<uint32_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1096 break; |
6332 | 1097 |
1098 case mxINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1099 retval = *(static_cast<int64_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1100 break; |
6332 | 1101 |
1102 case mxUINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1103 retval = *(static_cast<uint64_t *> (pr)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1104 break; |
6332 | 1105 |
1106 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1107 panic_impossible (); |
6332 | 1108 } |
1109 | |
1110 return retval; | |
1111 } | |
1112 | |
5907 | 1113 void *get_data (void) const { return pr; } |
1114 | |
1115 void *get_imag_data (void) const { return pi; } | |
1116 | |
1117 void set_data (void *pr_arg) { pr = pr_arg; } | |
1118 | |
1119 void set_imag_data (void *pi_arg) { pi = pi_arg; } | |
1120 | |
6686 | 1121 int get_string (char *buf, mwSize buflen) const |
5907 | 1122 { |
13753
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1123 int retval = 0; |
5907 | 1124 |
6686 | 1125 mwSize nel = get_number_of_elements (); |
6493 | 1126 |
13753
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1127 if (! (nel < buflen)) |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1128 { |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1129 retval = 1; |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1130 if (buflen > 0) |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1131 nel = buflen-1; |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1132 } |
ab4238b0b09b
Change return value of mxGetString to match Matlab (Bug #34546)
Rik <octave@nomad.inbox5.com>
parents:
12472
diff
changeset
|
1133 |
6493 | 1134 if (nel < buflen) |
5907 | 1135 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1136 mxChar *ptr = static_cast<mxChar *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1137 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1138 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1139 buf[i] = static_cast<char> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1140 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1141 buf[nel] = 0; |
5907 | 1142 } |
1143 | |
1144 return retval; | |
1145 } | |
1146 | |
1147 char *array_to_string (void) const | |
1148 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1149 // FIXME: this is suposed to handle multi-byte character strings. |
5907 | 1150 |
6686 | 1151 mwSize nel = get_number_of_elements (); |
5907 | 1152 |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1153 char *buf = static_cast<char *> (mxArray::malloc (nel + 1)); |
5907 | 1154 |
1155 if (buf) | |
1156 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1157 mxChar *ptr = static_cast<mxChar *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1158 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1159 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1160 buf[i] = static_cast<char> (ptr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1161 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1162 buf[nel] = '\0'; |
5907 | 1163 } |
1164 | |
1165 return buf; | |
1166 } | |
1167 | |
5900 | 1168 octave_value as_octave_value (void) const |
1169 { | |
1170 octave_value retval; | |
1171 | |
1172 dim_vector dv = dims_to_dim_vector (); | |
1173 | |
1174 switch (get_class_id ()) | |
1175 { | |
1176 case mxLOGICAL_CLASS: | |
17429
84d195e050fd
mex.cc: Call ov_to_int with mxLogical argument for platform portability (bug #40027).
Jens Restemeier <jens.restemeier@gmail.com>
parents:
16892
diff
changeset
|
1177 retval = int_to_ov<mxLogical, boolNDArray, bool> (dv); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1178 break; |
5900 | 1179 |
1180 case mxCHAR_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1181 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1182 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1183 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1184 mxChar *ppr = static_cast<mxChar *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1185 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1186 charNDArray val (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1187 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1188 char *ptr = val.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1189 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1190 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1191 ptr[i] = static_cast<char> (ppr[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1192 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1193 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1194 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1195 break; |
5900 | 1196 |
1197 case mxSINGLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1198 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1199 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1200 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1201 float *ppr = static_cast<float *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1202 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1203 if (pi) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1204 { |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1205 FloatComplexNDArray val (dv); |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1206 |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1207 FloatComplex *ptr = val.fortran_vec (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1208 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1209 float *ppi = static_cast<float *> (pi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1210 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1211 for (mwIndex i = 0; i < nel; i++) |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1212 ptr[i] = FloatComplex (ppr[i], ppi[i]); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1213 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1214 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1215 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1216 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1217 { |
11132
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1218 FloatNDArray val (dv); |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1219 |
6ed521ed2d6a
Stop converting single valued output from mex files to doubles.
Gunnar Farneback <gunnar@lysator.liu.se>
parents:
11100
diff
changeset
|
1220 float *ptr = val.fortran_vec (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1221 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1222 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1223 ptr[i] = ppr[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1224 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1225 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1226 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1227 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1228 break; |
5900 | 1229 |
1230 case mxDOUBLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1231 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1232 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1233 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1234 double *ppr = static_cast<double *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1235 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1236 if (pi) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1237 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1238 ComplexNDArray val (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1239 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1240 Complex *ptr = val.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1241 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1242 double *ppi = static_cast<double *> (pi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1243 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1244 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1245 ptr[i] = Complex (ppr[i], ppi[i]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1246 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1247 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1248 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1249 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1250 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1251 NDArray val (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1252 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1253 double *ptr = val.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1254 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1255 for (mwIndex i = 0; i < nel; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1256 ptr[i] = ppr[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1257 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1258 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1259 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1260 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1261 break; |
5900 | 1262 |
1263 case mxINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1264 retval = int_to_ov<int8_t, int8NDArray, octave_int8> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1265 break; |
5900 | 1266 |
1267 case mxUINT8_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1268 retval = int_to_ov<uint8_t, uint8NDArray, octave_uint8> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1269 break; |
5900 | 1270 |
1271 case mxINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1272 retval = int_to_ov<int16_t, int16NDArray, octave_int16> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1273 break; |
5900 | 1274 |
1275 case mxUINT16_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1276 retval = int_to_ov<uint16_t, uint16NDArray, octave_uint16> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1277 break; |
5900 | 1278 |
1279 case mxINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1280 retval = int_to_ov<int32_t, int32NDArray, octave_int32> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1281 break; |
5900 | 1282 |
1283 case mxUINT32_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1284 retval = int_to_ov<uint32_t, uint32NDArray, octave_uint32> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1285 break; |
5900 | 1286 |
1287 case mxINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1288 retval = int_to_ov<int64_t, int64NDArray, octave_int64> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1289 break; |
5900 | 1290 |
1291 case mxUINT64_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1292 retval = int_to_ov<uint64_t, uint64NDArray, octave_uint64> (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1293 break; |
5900 | 1294 |
1295 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1296 panic_impossible (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1297 } |
5900 | 1298 |
1299 return retval; | |
1300 } | |
1301 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1302 protected: |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1303 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1304 template <typename ELT_T, typename ARRAY_T, typename ARRAY_ELT_T> |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1305 octave_value |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1306 int_to_ov (const dim_vector& dv) const |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1307 { |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1308 octave_value retval; |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1309 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1310 mwSize nel = get_number_of_elements (); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1311 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1312 ELT_T *ppr = static_cast<ELT_T *> (pr); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1313 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1314 if (pi) |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1315 error ("complex integer types are not supported"); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1316 else |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1317 { |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1318 ARRAY_T val (dv); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1319 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1320 ARRAY_ELT_T *ptr = val.fortran_vec (); |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1321 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1322 for (mwIndex i = 0; i < nel; i++) |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1323 ptr[i] = ppr[i]; |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1324 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1325 retval = val; |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1326 } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1327 |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1328 return retval; |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1329 } |
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1330 |
5900 | 1331 mxArray_number (const mxArray_number& val) |
1332 : mxArray_matlab (val), | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1333 pr (mxArray::malloc (get_number_of_elements () * get_element_size ())), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1334 pi (val.pi ? mxArray::malloc (get_number_of_elements () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1335 * get_element_size ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1336 : 0) |
5900 | 1337 { |
5907 | 1338 size_t nbytes = get_number_of_elements () * get_element_size (); |
1339 | |
1340 if (pr) | |
1341 memcpy (pr, val.pr, nbytes); | |
5900 | 1342 |
1343 if (pi) | |
5907 | 1344 memcpy (pi, val.pi, nbytes); |
5900 | 1345 } |
1346 | |
1347 private: | |
1348 | |
1349 void *pr; | |
1350 void *pi; | |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1351 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1352 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1353 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1354 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1355 mxArray_number& operator = (const mxArray_number&); |
5900 | 1356 }; |
1357 | |
1358 // Matlab-style sparse arrays. | |
1359 | |
5903 | 1360 class mxArray_sparse : public mxArray_matlab |
5900 | 1361 { |
1362 public: | |
1363 | |
14839
e2ac6e2c588a
use mwSize for size arguments to mxArray_sparse constructor (bug #36783)
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1364 mxArray_sparse (mxClassID id_arg, mwSize m, mwSize n, mwSize nzmax_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1365 mxComplexity flag = mxREAL) |
12123
9ea6f69259d7
more constructor initialization fixes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
12122
diff
changeset
|
1366 : mxArray_matlab (id_arg, m, n), nzmax (nzmax_arg), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1367 pr (mxArray::calloc (nzmax, get_element_size ())), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1368 pi (flag == mxCOMPLEX ? mxArray::calloc (nzmax, get_element_size ()) : 0), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1369 ir (static_cast<mwIndex *> (mxArray::calloc (nzmax, sizeof (mwIndex)))), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1370 jc (static_cast<mwIndex *> (mxArray::calloc (n + 1, sizeof (mwIndex)))) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1371 { } |
5900 | 1372 |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1373 mxArray_base *dup (void) const { return new mxArray_sparse (*this); } |
5900 | 1374 |
1375 ~mxArray_sparse (void) | |
1376 { | |
5903 | 1377 mxFree (pr); |
1378 mxFree (pi); | |
5900 | 1379 mxFree (ir); |
1380 mxFree (jc); | |
1381 } | |
1382 | |
5907 | 1383 int is_complex (void) const { return pi != 0; } |
1384 | |
1385 int is_sparse (void) const { return 1; } | |
1386 | |
1387 void *get_data (void) const { return pr; } | |
1388 | |
1389 void *get_imag_data (void) const { return pi; } | |
1390 | |
1391 void set_data (void *pr_arg) { pr = pr_arg; } | |
1392 | |
1393 void set_imag_data (void *pi_arg) { pi = pi_arg; } | |
1394 | |
6686 | 1395 mwIndex *get_ir (void) const { return ir; } |
1396 | |
1397 mwIndex *get_jc (void) const { return jc; } | |
1398 | |
1399 mwSize get_nzmax (void) const { return nzmax; } | |
1400 | |
1401 void set_ir (mwIndex *ir_arg) { ir = ir_arg; } | |
1402 | |
1403 void set_jc (mwIndex *jc_arg) { jc = jc_arg; } | |
1404 | |
1405 void set_nzmax (mwSize nzmax_arg) { nzmax = nzmax_arg; } | |
5907 | 1406 |
5900 | 1407 octave_value as_octave_value (void) const |
1408 { | |
5903 | 1409 octave_value retval; |
1410 | |
1411 dim_vector dv = dims_to_dim_vector (); | |
1412 | |
1413 switch (get_class_id ()) | |
1414 { | |
1415 case mxLOGICAL_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1416 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1417 bool *ppr = static_cast<bool *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1418 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1419 SparseBoolMatrix val (get_m (), get_n (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1420 static_cast<octave_idx_type> (nzmax)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1421 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1422 for (mwIndex i = 0; i < nzmax; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1423 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1424 val.xdata (i) = ppr[i]; |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1425 val.xridx (i) = ir[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1426 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1427 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1428 for (mwIndex i = 0; i < get_n () + 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1429 val.xcidx (i) = jc[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1430 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1431 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1432 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1433 break; |
5903 | 1434 |
1435 case mxSINGLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1436 error ("single precision sparse data type not supported"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1437 break; |
5903 | 1438 |
1439 case mxDOUBLE_CLASS: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1440 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1441 if (pi) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1442 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1443 double *ppr = static_cast<double *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1444 double *ppi = static_cast<double *> (pi); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1445 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1446 SparseComplexMatrix val (get_m (), get_n (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1447 static_cast<octave_idx_type> (nzmax)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1448 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1449 for (mwIndex i = 0; i < nzmax; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1450 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1451 val.xdata (i) = Complex (ppr[i], ppi[i]); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1452 val.xridx (i) = ir[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1453 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1454 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1455 for (mwIndex i = 0; i < get_n () + 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1456 val.xcidx (i) = jc[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1457 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1458 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1459 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1460 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1461 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1462 double *ppr = static_cast<double *> (pr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1463 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1464 SparseMatrix val (get_m (), get_n (), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1465 static_cast<octave_idx_type> (nzmax)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1466 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1467 for (mwIndex i = 0; i < nzmax; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1468 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1469 val.xdata (i) = ppr[i]; |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1470 val.xridx (i) = ir[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1471 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1472 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1473 for (mwIndex i = 0; i < get_n () + 1; i++) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
1474 val.xcidx (i) = jc[i]; |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1475 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1476 retval = val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1477 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1478 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1479 break; |
5903 | 1480 |
1481 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1482 panic_impossible (); |
5903 | 1483 } |
1484 | |
1485 return retval; | |
5900 | 1486 } |
1487 | |
1488 private: | |
1489 | |
6686 | 1490 mwSize nzmax; |
5900 | 1491 |
5903 | 1492 void *pr; |
1493 void *pi; | |
6686 | 1494 mwIndex *ir; |
1495 mwIndex *jc; | |
5900 | 1496 |
1497 mxArray_sparse (const mxArray_sparse& val) | |
5903 | 1498 : mxArray_matlab (val), nzmax (val.nzmax), |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1499 pr (mxArray::malloc (nzmax * get_element_size ())), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1500 pi (val.pi ? mxArray::malloc (nzmax * get_element_size ()) : 0), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1501 ir (static_cast<mwIndex *> (mxArray::malloc (nzmax * sizeof (mwIndex)))), |
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1502 jc (static_cast<mwIndex *> (mxArray::malloc (nzmax * sizeof (mwIndex)))) |
5900 | 1503 { |
5907 | 1504 size_t nbytes = nzmax * get_element_size (); |
1505 | |
1506 if (pr) | |
1507 memcpy (pr, val.pr, nbytes); | |
1508 | |
5903 | 1509 if (pi) |
5907 | 1510 memcpy (pi, val.pi, nbytes); |
1511 | |
1512 if (ir) | |
6686 | 1513 memcpy (ir, val.ir, nzmax * sizeof (mwIndex)); |
5907 | 1514 |
1515 if (jc) | |
6686 | 1516 memcpy (jc, val.jc, (val.get_n () + 1) * sizeof (mwIndex)); |
5900 | 1517 } |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1518 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1519 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1520 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1521 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1522 mxArray_sparse& operator = (const mxArray_sparse&); |
5900 | 1523 }; |
1524 | |
1525 // Matlab-style struct arrays. | |
1526 | |
1527 class mxArray_struct : public mxArray_matlab | |
1528 { | |
1529 public: | |
1530 | |
6686 | 1531 mxArray_struct (mwSize ndims_arg, const mwSize *dims_arg, int num_keys_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1532 const char **keys) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1533 : mxArray_matlab (mxSTRUCT_CLASS, ndims_arg, dims_arg), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1534 nfields (num_keys_arg), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1535 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1536 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1537 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1538 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1539 sizeof (mxArray *)))) |
5900 | 1540 { |
1541 init (keys); | |
1542 } | |
1543 | |
1544 mxArray_struct (const dim_vector& dv, int num_keys_arg, const char **keys) | |
1545 : mxArray_matlab (mxSTRUCT_CLASS, dv), nfields (num_keys_arg), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1546 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1547 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1548 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1549 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1550 sizeof (mxArray *)))) |
5900 | 1551 { |
1552 init (keys); | |
1553 } | |
1554 | |
6686 | 1555 mxArray_struct (mwSize m, mwSize n, int num_keys_arg, const char **keys) |
5900 | 1556 : mxArray_matlab (mxSTRUCT_CLASS, m, n), nfields (num_keys_arg), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1557 fields (static_cast<char **> (mxArray::calloc (nfields, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1558 sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1559 data (static_cast<mxArray **> (mxArray::calloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1560 get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1561 sizeof (mxArray *)))) |
5900 | 1562 { |
1563 init (keys); | |
1564 } | |
1565 | |
1566 void init (const char **keys) | |
1567 { | |
1568 for (int i = 0; i < nfields; i++) | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1569 fields[i] = mxArray::strsave (keys[i]); |
5900 | 1570 } |
1571 | |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1572 mxArray_base *dup (void) const { return new mxArray_struct (*this); } |
5900 | 1573 |
1574 ~mxArray_struct (void) | |
1575 { | |
1576 for (int i = 0; i < nfields; i++) | |
1577 mxFree (fields[i]); | |
1578 | |
1579 mxFree (fields); | |
1580 | |
6686 | 1581 mwSize ntot = nfields * get_number_of_elements (); |
1582 | |
1583 for (mwIndex i = 0; i < ntot; i++) | |
5905 | 1584 delete data[i]; |
5900 | 1585 |
1586 mxFree (data); | |
1587 } | |
1588 | |
1589 int add_field (const char *key) | |
1590 { | |
1591 int retval = -1; | |
1592 | |
1593 if (valid_key (key)) | |
1594 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1595 nfields++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1596 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1597 fields = static_cast<char **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1598 (mxRealloc (fields, nfields * sizeof (char *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1599 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1600 if (fields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1601 { |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1602 fields[nfields-1] = mxArray::strsave (key); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1603 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1604 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1605 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1606 mwSize ntot = nfields * nel; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1607 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1608 mxArray **new_data; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1609 new_data = static_cast<mxArray **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1610 (mxArray::malloc (ntot * sizeof (mxArray *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1611 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1612 if (new_data) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1613 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1614 mwIndex j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1615 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1616 mwIndex n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1617 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1618 for (mwIndex i = 0; i < ntot; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1619 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1620 if (++n == nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1621 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1622 new_data[j++] = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1623 n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1624 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1625 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1626 new_data[j++] = data[k++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1627 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1628 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1629 mxFree (data); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1630 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1631 data = new_data; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1632 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1633 retval = nfields - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1634 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1635 } |
5900 | 1636 } |
1637 | |
1638 return retval; | |
1639 } | |
1640 | |
1641 void remove_field (int key_num) | |
1642 { | |
1643 if (key_num >= 0 && key_num < nfields) | |
1644 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1645 mwSize nel = get_number_of_elements (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1646 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1647 mwSize ntot = nfields * nel; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1648 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1649 int new_nfields = nfields - 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1650 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1651 char **new_fields = static_cast<char **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1652 (mxArray::malloc (new_nfields * sizeof (char *))); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1653 |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1654 mxArray **new_data = static_cast<mxArray **> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1655 (mxArray::malloc (new_nfields * nel |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1656 * sizeof (mxArray *))); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1657 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1658 for (int i = 0; i < key_num; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1659 new_fields[i] = fields[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1660 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1661 for (int i = key_num + 1; i < nfields; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1662 new_fields[i-1] = fields[i]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1663 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1664 if (new_nfields > 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1665 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1666 mwIndex j = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1667 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1668 mwIndex n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1669 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1670 for (mwIndex i = 0; i < ntot; i++) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1671 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1672 if (n == key_num) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1673 k++; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1674 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1675 new_data[j++] = data[k++]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1676 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1677 if (++n == nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1678 n = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1679 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1680 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1681 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1682 nfields = new_nfields; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1683 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1684 mxFree (fields); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1685 mxFree (data); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1686 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1687 fields = new_fields; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1688 data = new_data; |
5900 | 1689 } |
1690 } | |
1691 | |
6686 | 1692 mxArray *get_field_by_number (mwIndex index, int key_num) const |
5900 | 1693 { |
6187 | 1694 return key_num >= 0 && key_num < nfields |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1695 ? data[nfields * index + key_num] : 0; |
5900 | 1696 } |
1697 | |
6686 | 1698 void set_field_by_number (mwIndex index, int key_num, mxArray *val); |
5900 | 1699 |
1700 int get_number_of_fields (void) const { return nfields; } | |
1701 | |
1702 const char *get_field_name_by_number (int key_num) const | |
1703 { | |
1704 return key_num >= 0 && key_num < nfields ? fields[key_num] : 0; | |
1705 } | |
1706 | |
1707 int get_field_number (const char *key) const | |
1708 { | |
1709 int retval = -1; | |
1710 | |
1711 for (int i = 0; i < nfields; i++) | |
1712 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1713 if (! strcmp (key, fields[i])) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1714 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1715 retval = i; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1716 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1717 } |
5900 | 1718 } |
1719 | |
1720 return retval; | |
1721 } | |
1722 | |
1723 void *get_data (void) const { return data; } | |
1724 | |
1725 void set_data (void *data_arg) { data = static_cast<mxArray **> (data_arg); } | |
1726 | |
5907 | 1727 octave_value as_octave_value (void) const |
1728 { | |
1729 dim_vector dv = dims_to_dim_vector (); | |
1730 | |
1731 string_vector keys (fields, nfields); | |
1732 | |
11073
a22f3a673f33
mex.cc (mxArray_struct::as_octave_value): Use octave_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
10853
diff
changeset
|
1733 octave_map m; |
5907 | 1734 |
6686 | 1735 mwSize ntot = nfields * get_number_of_elements (); |
5907 | 1736 |
1737 for (int i = 0; i < nfields; i++) | |
1738 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1739 Cell c (dv); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1740 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1741 octave_value *p = c.fortran_vec (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1742 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1743 mwIndex k = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1744 for (mwIndex j = i; j < ntot; j += nfields) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1745 p[k++] = mxArray::as_octave_value (data[j]); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1746 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1747 m.assign (keys[i], c); |
5907 | 1748 } |
1749 | |
1750 return m; | |
1751 } | |
1752 | |
5900 | 1753 private: |
1754 | |
1755 int nfields; | |
1756 | |
1757 char **fields; | |
1758 | |
1759 mxArray **data; | |
1760 | |
1761 mxArray_struct (const mxArray_struct& val) | |
1762 : mxArray_matlab (val), nfields (val.nfields), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1763 fields (static_cast<char **> (mxArray::malloc (nfields |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1764 * sizeof (char *)))), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1765 data (static_cast<mxArray **> (mxArray::malloc (nfields * |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1766 get_number_of_elements () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1767 * sizeof (mxArray *)))) |
5900 | 1768 { |
1769 for (int i = 0; i < nfields; i++) | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1770 fields[i] = mxArray::strsave (val.fields[i]); |
5900 | 1771 |
6686 | 1772 mwSize nel = get_number_of_elements (); |
1773 | |
1774 for (mwIndex i = 0; i < nel * nfields; i++) | |
6347 | 1775 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1776 mxArray *ptr = val.data[i]; |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11276
diff
changeset
|
1777 data[i] = ptr ? ptr->dup () : 0; |
6347 | 1778 } |
5900 | 1779 } |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1780 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1781 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1782 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1783 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1784 mxArray_struct& operator = (const mxArray_struct& val); |
5900 | 1785 }; |
1786 | |
1787 // Matlab-style cell arrays. | |
1788 | |
1789 class mxArray_cell : public mxArray_matlab | |
1790 { | |
1791 public: | |
1792 | |
6686 | 1793 mxArray_cell (mwSize ndims_arg, const mwSize *dims_arg) |
5900 | 1794 : mxArray_matlab (mxCELL_CLASS, ndims_arg, dims_arg), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1795 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1796 sizeof (mxArray *)))) { } |
5900 | 1797 |
1798 mxArray_cell (const dim_vector& dv) | |
1799 : mxArray_matlab (mxCELL_CLASS, dv), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1800 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1801 sizeof (mxArray *)))) { } |
5900 | 1802 |
6686 | 1803 mxArray_cell (mwSize m, mwSize n) |
5900 | 1804 : mxArray_matlab (mxCELL_CLASS, m, n), |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1805 data (static_cast<mxArray **> (mxArray::calloc (get_number_of_elements (), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1806 sizeof (mxArray *)))) { } |
5900 | 1807 |
15351
a291f850743c
modernize mxArray class hierarchy
John W. Eaton <jwe@octave.org>
parents:
15220
diff
changeset
|
1808 mxArray_base *dup (void) const { return new mxArray_cell (*this); } |
5900 | 1809 |
1810 ~mxArray_cell (void) | |
1811 { | |
6686 | 1812 mwSize nel = get_number_of_elements (); |
1813 | |
1814 for (mwIndex i = 0; i < nel; i++) | |
5905 | 1815 delete data[i]; |
5900 | 1816 |
1817 mxFree (data); | |
1818 } | |
1819 | |
6686 | 1820 mxArray *get_cell (mwIndex idx) const |
6187 | 1821 { |
1822 return idx >= 0 && idx < get_number_of_elements () ? data[idx] : 0; | |
1823 } | |
5907 | 1824 |
6686 | 1825 void set_cell (mwIndex idx, mxArray *val); |
5907 | 1826 |
1827 void *get_data (void) const { return data; } | |
1828 | |
1829 void set_data (void *data_arg) { data = static_cast<mxArray **> (data_arg); } | |
1830 | |
5900 | 1831 octave_value as_octave_value (void) const |
1832 { | |
1833 dim_vector dv = dims_to_dim_vector (); | |
1834 | |
1835 Cell c (dv); | |
1836 | |
6686 | 1837 mwSize nel = get_number_of_elements (); |
5900 | 1838 |
1839 octave_value *p = c.fortran_vec (); | |
1840 | |
6686 | 1841 for (mwIndex i = 0; i < nel; i++) |
5907 | 1842 p[i] = mxArray::as_octave_value (data[i]); |
5900 | 1843 |
1844 return c; | |
1845 } | |
1846 | |
1847 private: | |
1848 | |
1849 mxArray **data; | |
1850 | |
1851 mxArray_cell (const mxArray_cell& val) | |
1852 : mxArray_matlab (val), | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1853 data (static_cast<mxArray **> (mxArray::malloc (get_number_of_elements () |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1854 * sizeof (mxArray *)))) |
5900 | 1855 { |
6686 | 1856 mwSize nel = get_number_of_elements (); |
1857 | |
1858 for (mwIndex i = 0; i < nel; i++) | |
6347 | 1859 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1860 mxArray *ptr = val.data[i]; |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11276
diff
changeset
|
1861 data[i] = ptr ? ptr->dup () : 0; |
6347 | 1862 } |
5900 | 1863 } |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1864 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1865 // No assignment! FIXME: should this be implemented? Note that we |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1866 // do have a copy constructor. |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1867 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
1868 mxArray_cell& operator = (const mxArray_cell&); |
5900 | 1869 }; |
1870 | |
1871 // ------------------------------------------------------------------ | |
1872 | |
1873 mxArray::mxArray (const octave_value& ov) | |
6065 | 1874 : rep (new mxArray_octave_value (ov)), name (0) { } |
5900 | 1875 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1876 mxArray::mxArray (mxClassID id, mwSize ndims, const mwSize *dims, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1877 mxComplexity flag) |
6065 | 1878 : rep (new mxArray_number (id, ndims, dims, flag)), name (0) { } |
5900 | 1879 |
1880 mxArray::mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag) | |
6065 | 1881 : rep (new mxArray_number (id, dv, flag)), name (0) { } |
5900 | 1882 |
6686 | 1883 mxArray::mxArray (mxClassID id, mwSize m, mwSize n, mxComplexity flag) |
6065 | 1884 : rep (new mxArray_number (id, m, n, flag)), name (0) { } |
5900 | 1885 |
1886 mxArray::mxArray (mxClassID id, double val) | |
6065 | 1887 : rep (new mxArray_number (id, val)), name (0) { } |
5900 | 1888 |
1889 mxArray::mxArray (mxClassID id, mxLogical val) | |
6065 | 1890 : rep (new mxArray_number (id, val)), name (0) { } |
5900 | 1891 |
1892 mxArray::mxArray (const char *str) | |
6065 | 1893 : rep (new mxArray_number (str)), name (0) { } |
5900 | 1894 |
6686 | 1895 mxArray::mxArray (mwSize m, const char **str) |
6065 | 1896 : rep (new mxArray_number (m, str)), name (0) { } |
5900 | 1897 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1898 mxArray::mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1899 mxComplexity flag) |
6065 | 1900 : rep (new mxArray_sparse (id, m, n, nzmax, flag)), name (0) { } |
5900 | 1901 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1902 mxArray::mxArray (mwSize ndims, const mwSize *dims, int num_keys, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
1903 const char **keys) |
6065 | 1904 : rep (new mxArray_struct (ndims, dims, num_keys, keys)), name (0) { } |
5900 | 1905 |
1906 mxArray::mxArray (const dim_vector& dv, int num_keys, const char **keys) | |
6065 | 1907 : rep (new mxArray_struct (dv, num_keys, keys)), name (0) { } |
5900 | 1908 |
6686 | 1909 mxArray::mxArray (mwSize m, mwSize n, int num_keys, const char **keys) |
6065 | 1910 : rep (new mxArray_struct (m, n, num_keys, keys)), name (0) { } |
5900 | 1911 |
6686 | 1912 mxArray::mxArray (mwSize ndims, const mwSize *dims) |
6065 | 1913 : rep (new mxArray_cell (ndims, dims)), name (0) { } |
5900 | 1914 |
1915 mxArray::mxArray (const dim_vector& dv) | |
6065 | 1916 : rep (new mxArray_cell (dv)), name (0) { } |
5900 | 1917 |
6686 | 1918 mxArray::mxArray (mwSize m, mwSize n) |
6065 | 1919 : rep (new mxArray_cell (m, n)), name (0) { } |
5900 | 1920 |
1921 mxArray::~mxArray (void) | |
1922 { | |
1923 mxFree (name); | |
1924 | |
1925 delete rep; | |
1926 } | |
1927 | |
1928 void | |
1929 mxArray::set_name (const char *name_arg) | |
1930 { | |
1931 mxFree (name); | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
1932 name = mxArray::strsave (name_arg); |
5900 | 1933 } |
1934 | |
5907 | 1935 octave_value |
15353
5f3a69a309a7
fix decl of mexPutVariable
John W. Eaton <jwe@octave.org>
parents:
15351
diff
changeset
|
1936 mxArray::as_octave_value (const mxArray *ptr) |
5907 | 1937 { |
1938 return ptr ? ptr->as_octave_value () : octave_value (Matrix ()); | |
1939 } | |
1940 | |
1941 octave_value | |
1942 mxArray::as_octave_value (void) const | |
1943 { | |
1944 return rep->as_octave_value (); | |
1945 } | |
1946 | |
5900 | 1947 void |
1948 mxArray::maybe_mutate (void) const | |
1949 { | |
1950 if (rep->is_octave_value ()) | |
1951 { | |
1952 // The mutate function returns a pointer to a complete new | |
1953 // mxArray object (or 0, if no mutation happened). We just want | |
1954 // to replace the existing rep with the rep from the new object. | |
1955 | |
1956 mxArray *new_val = rep->mutate (); | |
1957 | |
1958 if (new_val) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1959 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1960 delete rep; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1961 rep = new_val->rep; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1962 new_val->rep = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1963 delete new_val; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1964 } |
5900 | 1965 } |
1966 } | |
1967 | |
1968 // ------------------------------------------------------------------ | |
1969 | |
6686 | 1970 // A class to manage calls to MEX functions. Mostly deals with memory |
5900 | 1971 // management. |
5864 | 1972 |
1973 class mex | |
1974 { | |
1975 public: | |
1976 | |
6068 | 1977 mex (octave_mex_function *f) |
1978 : curr_mex_fcn (f), memlist (), arraylist (), fname (0) { } | |
5864 | 1979 |
1980 ~mex (void) | |
1981 { | |
1982 if (! memlist.empty ()) | |
5905 | 1983 error ("mex: %s: cleanup failed", function_name ()); |
5900 | 1984 |
1985 mxFree (fname); | |
5864 | 1986 } |
1987 | |
5900 | 1988 const char *function_name (void) const |
1989 { | |
1990 if (! fname) | |
1991 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1992 octave_function *fcn = octave_call_stack::current (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1993 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1994 if (fcn) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1995 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1996 std::string nm = fcn->name (); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1997 fname = mxArray::strsave (nm.c_str ()); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1998 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
1999 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2000 fname = mxArray::strsave ("unknown"); |
5900 | 2001 } |
2002 | |
2003 return fname; | |
2004 } | |
2005 | |
2006 // Free all unmarked pointers obtained from malloc and calloc. | |
2007 static void cleanup (void *ptr) | |
2008 { | |
2009 mex *context = static_cast<mex *> (ptr); | |
2010 | |
5905 | 2011 // We can't use mex::free here because it modifies memlist. |
5900 | 2012 for (std::set<void *>::iterator p = context->memlist.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2013 p != context->memlist.end (); p++) |
6601 | 2014 xfree (*p); |
5905 | 2015 |
2016 context->memlist.clear (); | |
2017 | |
2018 // We can't use mex::free_value here because it modifies arraylist. | |
5900 | 2019 for (std::set<mxArray *>::iterator p = context->arraylist.begin (); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2020 p != context->arraylist.end (); p++) |
5905 | 2021 delete *p; |
2022 | |
2023 context->arraylist.clear (); | |
5900 | 2024 } |
5864 | 2025 |
6071 | 2026 // Allocate memory. |
5900 | 2027 void *malloc_unmarked (size_t n) |
2028 { | |
10411 | 2029 void *ptr = gnulib::malloc (n); |
5900 | 2030 |
2031 if (! ptr) | |
2032 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2033 // FIXME: could use "octave_new_handler();" instead |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2034 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2035 error ("%s: failed to allocate %d bytes of memory", |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2036 function_name (), n); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2037 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2038 abort (); |
5900 | 2039 } |
2040 | |
2041 global_mark (ptr); | |
2042 | |
2043 return ptr; | |
2044 } | |
2045 | |
6071 | 2046 // Allocate memory to be freed on exit. |
5900 | 2047 void *malloc (size_t n) |
2048 { | |
2049 void *ptr = malloc_unmarked (n); | |
2050 | |
2051 mark (ptr); | |
2052 | |
2053 return ptr; | |
2054 } | |
2055 | |
6071 | 2056 // Allocate memory and initialize to 0. |
5900 | 2057 void *calloc_unmarked (size_t n, size_t t) |
2058 { | |
2059 void *ptr = malloc_unmarked (n*t); | |
2060 | |
2061 memset (ptr, 0, n*t); | |
2062 | |
2063 return ptr; | |
2064 } | |
2065 | |
6071 | 2066 // Allocate memory to be freed on exit and initialize to 0. |
5900 | 2067 void *calloc (size_t n, size_t t) |
2068 { | |
2069 void *ptr = calloc_unmarked (n, t); | |
2070 | |
2071 mark (ptr); | |
2072 | |
2073 return ptr; | |
2074 } | |
2075 | |
10225
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2076 // Reallocate a pointer obtained from malloc or calloc. If the |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2077 // pointer is NULL, allocate using malloc. We don't need an |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2078 // "unmarked" version of this. |
5900 | 2079 void *realloc (void *ptr, size_t n) |
2080 { | |
10225
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2081 void *v; |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2082 |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2083 if (ptr) |
5900 | 2084 { |
10411 | 2085 v = gnulib::realloc (ptr, n); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2086 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2087 std::set<void *>::iterator p = memlist.find (ptr); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2088 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2089 if (v && p != memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2090 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2091 memlist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2092 memlist.insert (v); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2093 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2094 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2095 p = global_memlist.find (ptr); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2096 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2097 if (v && p != global_memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2098 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2099 global_memlist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2100 global_memlist.insert (v); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2101 } |
5900 | 2102 } |
10225
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2103 else |
477d05b0a739
mxRealloc: Allocate new memory on NULL argument
David Grundberg <davidg@cs.umu.se>
parents:
10127
diff
changeset
|
2104 v = malloc (n); |
5900 | 2105 |
2106 return v; | |
2107 } | |
2108 | |
2109 // Free a pointer obtained from malloc or calloc. | |
2110 void free (void *ptr) | |
2111 { | |
2112 if (ptr) | |
2113 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2114 unmark (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2115 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2116 std::set<void *>::iterator p = global_memlist.find (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2117 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2118 if (p != global_memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2119 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2120 global_memlist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2121 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2122 xfree (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2123 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2124 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2125 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2126 p = foreign_memlist.find (ptr); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2127 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2128 if (p != foreign_memlist.end ()) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2129 foreign_memlist.erase (p); |
11276
475e90eb4ff1
mex::free: don't warn about skipping memory not allocated by mx{M,C,Re}alloc
John W. Eaton <jwe@octave.org>
parents:
11132
diff
changeset
|
2130 #ifdef DEBUG |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2131 else |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2132 warning ("mxFree: skipping memory not allocated by mxMalloc, mxCalloc, or mxRealloc"); |
11276
475e90eb4ff1
mex::free: don't warn about skipping memory not allocated by mx{M,C,Re}alloc
John W. Eaton <jwe@octave.org>
parents:
11132
diff
changeset
|
2133 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2134 } |
5900 | 2135 } |
2136 } | |
2137 | |
7172 | 2138 // Mark a pointer to be freed on exit. |
2139 void mark (void *ptr) | |
2140 { | |
2141 #ifdef DEBUG | |
2142 if (memlist.find (ptr) != memlist.end ()) | |
2143 warning ("%s: double registration ignored", function_name ()); | |
2144 #endif | |
2145 | |
2146 memlist.insert (ptr); | |
2147 } | |
2148 | |
2149 // Unmark a pointer to be freed on exit, either because it was | |
2150 // made persistent, or because it was already freed. | |
2151 void unmark (void *ptr) | |
2152 { | |
2153 std::set<void *>::iterator p = memlist.find (ptr); | |
2154 | |
2155 if (p != memlist.end ()) | |
2156 memlist.erase (p); | |
2157 #ifdef DEBUG | |
2158 else | |
2159 warning ("%s: value not marked", function_name ()); | |
2160 #endif | |
2161 } | |
5900 | 2162 |
6065 | 2163 mxArray *mark_array (mxArray *ptr) |
2164 { | |
2165 arraylist.insert (ptr); | |
2166 return ptr; | |
2167 } | |
2168 | |
6071 | 2169 void unmark_array (mxArray *ptr) |
2170 { | |
2171 std::set<mxArray *>::iterator p = arraylist.find (ptr); | |
2172 | |
2173 if (p != arraylist.end ()) | |
2174 arraylist.erase (p); | |
2175 } | |
2176 | |
7179 | 2177 // Mark a pointer as one we allocated. |
2178 void mark_foreign (void *ptr) | |
2179 { | |
2180 #ifdef DEBUG | |
2181 if (foreign_memlist.find (ptr) != foreign_memlist.end ()) | |
2182 warning ("%s: double registration ignored", function_name ()); | |
2183 #endif | |
2184 | |
2185 foreign_memlist.insert (ptr); | |
2186 } | |
2187 | |
2188 // Unmark a pointer as one we allocated. | |
2189 void unmark_foreign (void *ptr) | |
2190 { | |
2191 std::set<void *>::iterator p = foreign_memlist.find (ptr); | |
2192 | |
2193 if (p != foreign_memlist.end ()) | |
2194 foreign_memlist.erase (p); | |
2195 #ifdef DEBUG | |
2196 else | |
2197 warning ("%s: value not marked", function_name ()); | |
2198 #endif | |
2199 | |
2200 } | |
2201 | |
5900 | 2202 // Make a new array value and initialize from an octave value; it will be |
2203 // freed on exit unless marked as persistent. | |
2204 mxArray *make_value (const octave_value& ov) | |
2205 { | |
6065 | 2206 return mark_array (new mxArray (ov)); |
5900 | 2207 } |
2208 | |
2209 // Free an array and its contents. | |
6065 | 2210 bool free_value (mxArray *ptr) |
5900 | 2211 { |
6065 | 2212 bool inlist = false; |
2213 | |
5905 | 2214 std::set<mxArray *>::iterator p = arraylist.find (ptr); |
2215 | |
2216 if (p != arraylist.end ()) | |
2217 { | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2218 inlist = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2219 arraylist.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2220 delete ptr; |
5905 | 2221 } |
2222 #ifdef DEBUG | |
2223 else | |
2224 warning ("mex::free_value: skipping memory not allocated by mex::make_value"); | |
2225 #endif | |
6065 | 2226 |
2227 return inlist; | |
5900 | 2228 } |
2229 | |
6068 | 2230 octave_mex_function *current_mex_function (void) const |
2231 { | |
2232 return curr_mex_fcn; | |
2233 } | |
2234 | |
5900 | 2235 // 1 if error should be returned to MEX file, 0 if abort. |
5864 | 2236 int trap_feval_error; |
2237 | |
5900 | 2238 // longjmp return point if mexErrMsgTxt or error. |
5864 | 2239 jmp_buf jump; |
2240 | |
5900 | 2241 // Trigger a long jump back to the mex calling function. |
5864 | 2242 void abort (void) { longjmp (jump, 1); } |
2243 | |
2244 private: | |
2245 | |
6068 | 2246 // Pointer to the mex function that corresponds to this mex context. |
2247 octave_mex_function *curr_mex_fcn; | |
2248 | |
5900 | 2249 // List of memory resources that need to be freed upon exit. |
2250 std::set<void *> memlist; | |
2251 | |
7179 | 2252 // List of mxArray objects that need to be freed upon exit. |
5900 | 2253 std::set<mxArray *> arraylist; |
2254 | |
7179 | 2255 // List of memory resources we know about, but that were allocated |
2256 // elsewhere. | |
2257 std::set<void *> foreign_memlist; | |
2258 | |
5900 | 2259 // The name of the currently executing function. |
2260 mutable char *fname; | |
2261 | |
2262 // List of memory resources we allocated. | |
2263 static std::set<void *> global_memlist; | |
2264 | |
2265 // Mark a pointer as one we allocated. | |
5905 | 2266 void global_mark (void *ptr) |
5900 | 2267 { |
2268 #ifdef DEBUG | |
5905 | 2269 if (global_memlist.find (ptr) != global_memlist.end ()) |
2270 warning ("%s: double registration ignored", function_name ()); | |
5864 | 2271 #endif |
5900 | 2272 |
5905 | 2273 global_memlist.insert (ptr); |
5864 | 2274 } |
2275 | |
5900 | 2276 // Unmark a pointer as one we allocated. |
5905 | 2277 void global_unmark (void *ptr) |
5864 | 2278 { |
5905 | 2279 std::set<void *>::iterator p = global_memlist.find (ptr); |
2280 | |
2281 if (p != global_memlist.end ()) | |
2282 global_memlist.erase (p); | |
5900 | 2283 #ifdef DEBUG |
5905 | 2284 else |
2285 warning ("%s: value not marked", function_name ()); | |
5900 | 2286 #endif |
2287 | |
5864 | 2288 } |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2289 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2290 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2291 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2292 mex (const mex&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2293 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
2294 mex& operator = (const mex&); |
5864 | 2295 }; |
2296 | |
5900 | 2297 // List of memory resources we allocated. |
2298 std::set<void *> mex::global_memlist; | |
2299 | |
2300 // Current context. | |
2301 mex *mex_context = 0; | |
2302 | |
2303 void * | |
2304 mxArray::malloc (size_t n) | |
2305 { | |
10411 | 2306 return mex_context ? mex_context->malloc_unmarked (n) : gnulib::malloc (n); |
5900 | 2307 } |
2308 | |
2309 void * | |
2310 mxArray::calloc (size_t n, size_t t) | |
2311 { | |
6065 | 2312 return mex_context ? mex_context->calloc_unmarked (n, t) : ::calloc (n, t); |
5900 | 2313 } |
2314 | |
7179 | 2315 static inline void * |
2316 maybe_mark_foreign (void *ptr) | |
2317 { | |
2318 if (mex_context) | |
2319 mex_context->mark_foreign (ptr); | |
2320 | |
2321 return ptr; | |
2322 } | |
2323 | |
6071 | 2324 static inline mxArray * |
2325 maybe_unmark_array (mxArray *ptr) | |
2326 { | |
2327 if (mex_context) | |
2328 mex_context->unmark_array (ptr); | |
2329 | |
2330 return ptr; | |
2331 } | |
2332 | |
7172 | 2333 static inline void * |
2334 maybe_unmark (void *ptr) | |
2335 { | |
2336 if (mex_context) | |
2337 mex_context->unmark (ptr); | |
2338 | |
2339 return ptr; | |
2340 } | |
2341 | |
6071 | 2342 void |
6686 | 2343 mxArray_struct::set_field_by_number (mwIndex index, int key_num, mxArray *val) |
6071 | 2344 { |
6187 | 2345 if (key_num >= 0 && key_num < nfields) |
2346 data[nfields * index + key_num] = maybe_unmark_array (val); | |
6071 | 2347 } |
2348 | |
2349 void | |
6686 | 2350 mxArray_cell::set_cell (mwIndex idx, mxArray *val) |
6071 | 2351 { |
6187 | 2352 if (idx >= 0 && idx < get_number_of_elements ()) |
2353 data[idx] = maybe_unmark_array (val); | |
6071 | 2354 } |
2355 | |
5900 | 2356 // ------------------------------------------------------------------ |
2357 | |
2358 // C interface to mxArray objects: | |
2359 | |
2360 // Floating point predicates. | |
2361 | |
2362 int | |
2363 mxIsFinite (const double v) | |
2364 { | |
2365 return lo_ieee_finite (v) != 0; | |
2366 } | |
2367 | |
2368 int | |
2369 mxIsInf (const double v) | |
2370 { | |
2371 return lo_ieee_isinf (v) != 0; | |
2372 } | |
2373 | |
2374 int | |
2375 mxIsNaN (const double v) | |
2376 { | |
2377 return lo_ieee_isnan (v) != 0; | |
2378 } | |
2379 | |
2380 double | |
2381 mxGetEps (void) | |
2382 { | |
15220
61822c866ba1
use std::numeric_limits<T>::epsilon in C++ code
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
2383 return std::numeric_limits<double>::epsilon (); |
5900 | 2384 } |
2385 | |
2386 double | |
2387 mxGetInf (void) | |
2388 { | |
2389 return lo_ieee_inf_value (); | |
2390 } | |
2391 | |
2392 double | |
2393 mxGetNaN (void) | |
2394 { | |
2395 return lo_ieee_nan_value (); | |
2396 } | |
2397 | |
2398 // Memory management. | |
2399 void * | |
2400 mxCalloc (size_t n, size_t size) | |
2401 { | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
2402 return mex_context ? mex_context->calloc (n, size) : ::calloc (n, size); |
5900 | 2403 } |
2404 | |
2405 void * | |
2406 mxMalloc (size_t n) | |
2407 { | |
10411 | 2408 return mex_context ? mex_context->malloc (n) : gnulib::malloc (n); |
5900 | 2409 } |
2410 | |
2411 void * | |
2412 mxRealloc (void *ptr, size_t size) | |
2413 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2414 return mex_context ? mex_context->realloc (ptr, size) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2415 : gnulib::realloc (ptr, size); |
5900 | 2416 } |
2417 | |
2418 void | |
2419 mxFree (void *ptr) | |
5864 | 2420 { |
5900 | 2421 if (mex_context) |
2422 mex_context->free (ptr); | |
5864 | 2423 else |
6071 | 2424 xfree (ptr); |
5900 | 2425 } |
6065 | 2426 |
2427 static inline mxArray * | |
2428 maybe_mark_array (mxArray *ptr) | |
2429 { | |
2430 return mex_context ? mex_context->mark_array (ptr) : ptr; | |
2431 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2432 |
5900 | 2433 // Constructors. |
2434 mxArray * | |
6686 | 2435 mxCreateCellArray (mwSize ndims, const mwSize *dims) |
5900 | 2436 { |
6065 | 2437 return maybe_mark_array (new mxArray (ndims, dims)); |
5900 | 2438 } |
2439 | |
2440 mxArray * | |
6686 | 2441 mxCreateCellMatrix (mwSize m, mwSize n) |
5900 | 2442 { |
6065 | 2443 return maybe_mark_array (new mxArray (m, n)); |
5900 | 2444 } |
2445 | |
2446 mxArray * | |
6686 | 2447 mxCreateCharArray (mwSize ndims, const mwSize *dims) |
5900 | 2448 { |
6065 | 2449 return maybe_mark_array (new mxArray (mxCHAR_CLASS, ndims, dims)); |
5864 | 2450 } |
2451 | |
5900 | 2452 mxArray * |
6686 | 2453 mxCreateCharMatrixFromStrings (mwSize m, const char **str) |
5900 | 2454 { |
6065 | 2455 return maybe_mark_array (new mxArray (m, str)); |
5900 | 2456 } |
2457 | |
2458 mxArray * | |
6686 | 2459 mxCreateDoubleMatrix (mwSize m, mwSize n, mxComplexity flag) |
5900 | 2460 { |
6065 | 2461 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, flag)); |
5900 | 2462 } |
2463 | |
2464 mxArray * | |
2465 mxCreateDoubleScalar (double val) | |
2466 { | |
6065 | 2467 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, val)); |
5900 | 2468 } |
2469 | |
2470 mxArray * | |
6686 | 2471 mxCreateLogicalArray (mwSize ndims, const mwSize *dims) |
5864 | 2472 { |
6065 | 2473 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, ndims, dims)); |
5900 | 2474 } |
2475 | |
2476 mxArray * | |
6686 | 2477 mxCreateLogicalMatrix (mwSize m, mwSize n) |
5900 | 2478 { |
6065 | 2479 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n)); |
5900 | 2480 } |
2481 | |
2482 mxArray * | |
7577
ba8fcc115fee
mex.cc: arg to mxCreateLogicalScalar is now mxLogical
John W. Eaton <jwe@octave.org>
parents:
7357
diff
changeset
|
2483 mxCreateLogicalScalar (mxLogical val) |
5900 | 2484 { |
6065 | 2485 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, val)); |
5900 | 2486 } |
2487 | |
2488 mxArray * | |
6686 | 2489 mxCreateNumericArray (mwSize ndims, const mwSize *dims, mxClassID class_id, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2490 mxComplexity flag) |
5900 | 2491 { |
6065 | 2492 return maybe_mark_array (new mxArray (class_id, ndims, dims, flag)); |
5864 | 2493 } |
2494 | |
5900 | 2495 mxArray * |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2496 mxCreateNumericMatrix (mwSize m, mwSize n, mxClassID class_id, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2497 mxComplexity flag) |
5900 | 2498 { |
6065 | 2499 return maybe_mark_array (new mxArray (class_id, m, n, flag)); |
5900 | 2500 } |
2501 | |
2502 mxArray * | |
6686 | 2503 mxCreateSparse (mwSize m, mwSize n, mwSize nzmax, mxComplexity flag) |
5900 | 2504 { |
6065 | 2505 return maybe_mark_array (new mxArray (mxDOUBLE_CLASS, m, n, nzmax, flag)); |
5900 | 2506 } |
2507 | |
2508 mxArray * | |
6686 | 2509 mxCreateSparseLogicalMatrix (mwSize m, mwSize n, mwSize nzmax) |
5900 | 2510 { |
6065 | 2511 return maybe_mark_array (new mxArray (mxLOGICAL_CLASS, m, n, nzmax)); |
5900 | 2512 } |
2513 | |
2514 mxArray * | |
2515 mxCreateString (const char *str) | |
2516 { | |
6065 | 2517 return maybe_mark_array (new mxArray (str)); |
5900 | 2518 } |
2519 | |
2520 mxArray * | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2521 mxCreateStructArray (mwSize ndims, const mwSize *dims, int num_keys, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2522 const char **keys) |
5900 | 2523 { |
6065 | 2524 return maybe_mark_array (new mxArray (ndims, dims, num_keys, keys)); |
5900 | 2525 } |
5864 | 2526 |
2527 mxArray * | |
6686 | 2528 mxCreateStructMatrix (mwSize m, mwSize n, int num_keys, const char **keys) |
5900 | 2529 { |
6065 | 2530 return maybe_mark_array (new mxArray (m, n, num_keys, keys)); |
5900 | 2531 } |
2532 | |
2533 // Copy constructor. | |
2534 mxArray * | |
2535 mxDuplicateArray (const mxArray *ptr) | |
2536 { | |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11276
diff
changeset
|
2537 return maybe_mark_array (ptr->dup ()); |
5900 | 2538 } |
2539 | |
2540 // Destructor. | |
2541 void | |
2542 mxDestroyArray (mxArray *ptr) | |
2543 { | |
6065 | 2544 if (! (mex_context && mex_context->free_value (ptr))) |
2545 delete ptr; | |
5900 | 2546 } |
2547 | |
2548 // Type Predicates. | |
2549 int | |
2550 mxIsCell (const mxArray *ptr) | |
2551 { | |
2552 return ptr->is_cell (); | |
2553 } | |
2554 | |
2555 int | |
2556 mxIsChar (const mxArray *ptr) | |
2557 { | |
2558 return ptr->is_char (); | |
2559 } | |
2560 | |
2561 int | |
2562 mxIsClass (const mxArray *ptr, const char *name) | |
2563 { | |
2564 return ptr->is_class (name); | |
2565 } | |
2566 | |
2567 int | |
2568 mxIsComplex (const mxArray *ptr) | |
2569 { | |
2570 return ptr->is_complex (); | |
2571 } | |
2572 | |
2573 int | |
2574 mxIsDouble (const mxArray *ptr) | |
2575 { | |
2576 return ptr->is_double (); | |
2577 } | |
2578 | |
2579 int | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2580 mxIsFunctionHandle (const mxArray *ptr) |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2581 { |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2582 return ptr->is_function_handle (); |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2583 } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2584 |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
11073
diff
changeset
|
2585 int |
5900 | 2586 mxIsInt16 (const mxArray *ptr) |
2587 { | |
2588 return ptr->is_int16 (); | |
2589 } | |
2590 | |
2591 int | |
2592 mxIsInt32 (const mxArray *ptr) | |
2593 { | |
2594 return ptr->is_int32 (); | |
2595 } | |
2596 | |
2597 int | |
2598 mxIsInt64 (const mxArray *ptr) | |
2599 { | |
2600 return ptr->is_int64 (); | |
2601 } | |
2602 | |
2603 int | |
2604 mxIsInt8 (const mxArray *ptr) | |
2605 { | |
2606 return ptr->is_int8 (); | |
2607 } | |
2608 | |
2609 int | |
2610 mxIsLogical (const mxArray *ptr) | |
2611 { | |
2612 return ptr->is_logical (); | |
2613 } | |
2614 | |
2615 int | |
2616 mxIsNumeric (const mxArray *ptr) | |
2617 { | |
2618 return ptr->is_numeric (); | |
2619 } | |
2620 | |
2621 int | |
2622 mxIsSingle (const mxArray *ptr) | |
2623 { | |
2624 return ptr->is_single (); | |
2625 } | |
2626 | |
2627 int | |
2628 mxIsSparse (const mxArray *ptr) | |
2629 { | |
2630 return ptr->is_sparse (); | |
2631 } | |
2632 | |
2633 int | |
2634 mxIsStruct (const mxArray *ptr) | |
2635 { | |
2636 return ptr->is_struct (); | |
2637 } | |
2638 | |
2639 int | |
2640 mxIsUint16 (const mxArray *ptr) | |
2641 { | |
2642 return ptr->is_uint16 (); | |
2643 } | |
2644 | |
2645 int | |
2646 mxIsUint32 (const mxArray *ptr) | |
2647 { | |
2648 return ptr->is_uint32 (); | |
2649 } | |
2650 | |
2651 int | |
2652 mxIsUint64 (const mxArray *ptr) | |
2653 { | |
2654 return ptr->is_uint64 (); | |
2655 } | |
2656 | |
2657 int | |
2658 mxIsUint8 (const mxArray *ptr) | |
2659 { | |
2660 return ptr->is_uint8 (); | |
2661 } | |
2662 | |
2663 // Odd type+size predicate. | |
2664 int | |
2665 mxIsLogicalScalar (const mxArray *ptr) | |
2666 { | |
2667 return ptr->is_logical_scalar (); | |
2668 } | |
2669 | |
2670 // Odd type+size+value predicate. | |
2671 int | |
2672 mxIsLogicalScalarTrue (const mxArray *ptr) | |
2673 { | |
2674 return ptr->is_logical_scalar_true (); | |
2675 } | |
2676 | |
2677 // Size predicate. | |
2678 int | |
2679 mxIsEmpty (const mxArray *ptr) | |
2680 { | |
2681 return ptr->is_empty (); | |
2682 } | |
2683 | |
2684 // Just plain odd thing to ask of a value. | |
2685 int | |
2686 mxIsFromGlobalWS (const mxArray */*ptr*/) | |
2687 { | |
2688 // FIXME | |
2689 abort (); | |
2690 return 0; | |
2691 } | |
2692 | |
2693 // Dimension extractors. | |
6686 | 2694 size_t |
5900 | 2695 mxGetM (const mxArray *ptr) |
2696 { | |
2697 return ptr->get_m (); | |
2698 } | |
2699 | |
6686 | 2700 size_t |
5900 | 2701 mxGetN (const mxArray *ptr) |
2702 { | |
2703 return ptr->get_n (); | |
2704 } | |
2705 | |
6686 | 2706 mwSize * |
5900 | 2707 mxGetDimensions (const mxArray *ptr) |
5864 | 2708 { |
5900 | 2709 return ptr->get_dimensions (); |
2710 } | |
2711 | |
6686 | 2712 mwSize |
5900 | 2713 mxGetNumberOfDimensions (const mxArray *ptr) |
2714 { | |
2715 return ptr->get_number_of_dimensions (); | |
2716 } | |
2717 | |
6686 | 2718 size_t |
5900 | 2719 mxGetNumberOfElements (const mxArray *ptr) |
2720 { | |
2721 return ptr->get_number_of_elements (); | |
2722 } | |
2723 | |
2724 // Dimension setters. | |
2725 void | |
6686 | 2726 mxSetM (mxArray *ptr, mwSize m) |
5900 | 2727 { |
2728 ptr->set_m (m); | |
2729 } | |
2730 | |
2731 void | |
6686 | 2732 mxSetN (mxArray *ptr, mwSize n) |
5900 | 2733 { |
2734 ptr->set_n (n); | |
2735 } | |
2736 | |
2737 void | |
10126
8687ce1c56da
Change signature of mxSetDimensions.
David Grundberg <davidg@cs.umu.se>
parents:
10066
diff
changeset
|
2738 mxSetDimensions (mxArray *ptr, const mwSize *dims, mwSize ndims) |
5900 | 2739 { |
10126
8687ce1c56da
Change signature of mxSetDimensions.
David Grundberg <davidg@cs.umu.se>
parents:
10066
diff
changeset
|
2740 ptr->set_dimensions (static_cast<mwSize *> ( |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2741 maybe_unmark (const_cast<mwSize *> (dims))), |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2742 ndims); |
5900 | 2743 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2744 |
5900 | 2745 // Data extractors. |
2746 double * | |
2747 mxGetPr (const mxArray *ptr) | |
2748 { | |
2749 return static_cast<double *> (ptr->get_data ()); | |
2750 } | |
2751 | |
2752 double * | |
2753 mxGetPi (const mxArray *ptr) | |
2754 { | |
2755 return static_cast<double *> (ptr->get_imag_data ()); | |
2756 } | |
2757 | |
2758 double | |
2759 mxGetScalar (const mxArray *ptr) | |
2760 { | |
6332 | 2761 return ptr->get_scalar (); |
5900 | 2762 } |
2763 | |
2764 mxChar * | |
2765 mxGetChars (const mxArray *ptr) | |
2766 { | |
2767 return static_cast<mxChar *> (ptr->get_data ()); | |
2768 } | |
2769 | |
2770 mxLogical * | |
2771 mxGetLogicals (const mxArray *ptr) | |
2772 { | |
2773 return static_cast<mxLogical *> (ptr->get_data ()); | |
2774 } | |
2775 | |
2776 void * | |
2777 mxGetData (const mxArray *ptr) | |
2778 { | |
2779 return ptr->get_data (); | |
2780 } | |
2781 | |
2782 void * | |
2783 mxGetImagData (const mxArray *ptr) | |
2784 { | |
2785 return ptr->get_imag_data (); | |
2786 } | |
2787 | |
2788 // Data setters. | |
2789 void | |
2790 mxSetPr (mxArray *ptr, double *pr) | |
2791 { | |
7172 | 2792 ptr->set_data (maybe_unmark (pr)); |
5900 | 2793 } |
2794 | |
2795 void | |
2796 mxSetPi (mxArray *ptr, double *pi) | |
2797 { | |
7172 | 2798 ptr->set_imag_data (maybe_unmark (pi)); |
5864 | 2799 } |
2800 | |
5900 | 2801 void |
2802 mxSetData (mxArray *ptr, void *pr) | |
2803 { | |
7172 | 2804 ptr->set_data (maybe_unmark (pr)); |
5900 | 2805 } |
2806 | |
2807 void | |
2808 mxSetImagData (mxArray *ptr, void *pi) | |
2809 { | |
7172 | 2810 ptr->set_imag_data (maybe_unmark (pi)); |
5900 | 2811 } |
2812 | |
2813 // Classes. | |
2814 mxClassID | |
2815 mxGetClassID (const mxArray *ptr) | |
2816 { | |
2817 return ptr->get_class_id (); | |
2818 } | |
2819 | |
2820 const char * | |
2821 mxGetClassName (const mxArray *ptr) | |
2822 { | |
2823 return ptr->get_class_name (); | |
2824 } | |
2825 | |
2826 void | |
2827 mxSetClassName (mxArray *ptr, const char *name) | |
2828 { | |
2829 ptr->set_class_name (name); | |
2830 } | |
2831 | |
2832 // Cell support. | |
2833 mxArray * | |
6686 | 2834 mxGetCell (const mxArray *ptr, mwIndex idx) |
5900 | 2835 { |
2836 return ptr->get_cell (idx); | |
2837 } | |
2838 | |
2839 void | |
6686 | 2840 mxSetCell (mxArray *ptr, mwIndex idx, mxArray *val) |
5900 | 2841 { |
2842 ptr->set_cell (idx, val); | |
2843 } | |
2844 | |
2845 // Sparse support. | |
6686 | 2846 mwIndex * |
5900 | 2847 mxGetIr (const mxArray *ptr) |
2848 { | |
2849 return ptr->get_ir (); | |
2850 } | |
2851 | |
6686 | 2852 mwIndex * |
5900 | 2853 mxGetJc (const mxArray *ptr) |
2854 { | |
2855 return ptr->get_jc (); | |
2856 } | |
2857 | |
6686 | 2858 mwSize |
5900 | 2859 mxGetNzmax (const mxArray *ptr) |
2860 { | |
2861 return ptr->get_nzmax (); | |
2862 } | |
2863 | |
2864 void | |
6686 | 2865 mxSetIr (mxArray *ptr, mwIndex *ir) |
5900 | 2866 { |
7172 | 2867 ptr->set_ir (static_cast <mwIndex *> (maybe_unmark (ir))); |
5900 | 2868 } |
2869 | |
2870 void | |
6686 | 2871 mxSetJc (mxArray *ptr, mwIndex *jc) |
5900 | 2872 { |
7172 | 2873 ptr->set_jc (static_cast<mwIndex *> (maybe_unmark (jc))); |
5900 | 2874 } |
2875 | |
2876 void | |
6686 | 2877 mxSetNzmax (mxArray *ptr, mwSize nzmax) |
5900 | 2878 { |
2879 ptr->set_nzmax (nzmax); | |
2880 } | |
2881 | |
2882 // Structure support. | |
2883 int | |
2884 mxAddField (mxArray *ptr, const char *key) | |
2885 { | |
2886 return ptr->add_field (key); | |
2887 } | |
2888 | |
2889 void | |
2890 mxRemoveField (mxArray *ptr, int key_num) | |
2891 { | |
2892 ptr->remove_field (key_num); | |
2893 } | |
5864 | 2894 |
2895 mxArray * | |
6686 | 2896 mxGetField (const mxArray *ptr, mwIndex index, const char *key) |
5900 | 2897 { |
2898 int key_num = mxGetFieldNumber (ptr, key); | |
2899 return mxGetFieldByNumber (ptr, index, key_num); | |
2900 } | |
2901 | |
2902 mxArray * | |
6686 | 2903 mxGetFieldByNumber (const mxArray *ptr, mwIndex index, int key_num) |
5864 | 2904 { |
5900 | 2905 return ptr->get_field_by_number (index, key_num); |
5864 | 2906 } |
2907 | |
5900 | 2908 void |
6686 | 2909 mxSetField (mxArray *ptr, mwIndex index, const char *key, mxArray *val) |
5900 | 2910 { |
2911 int key_num = mxGetFieldNumber (ptr, key); | |
2912 mxSetFieldByNumber (ptr, index, key_num, val); | |
2913 } | |
5864 | 2914 |
2915 void | |
6686 | 2916 mxSetFieldByNumber (mxArray *ptr, mwIndex index, int key_num, mxArray *val) |
5864 | 2917 { |
5900 | 2918 ptr->set_field_by_number (index, key_num, val); |
2919 } | |
2920 | |
2921 int | |
2922 mxGetNumberOfFields (const mxArray *ptr) | |
2923 { | |
2924 return ptr->get_number_of_fields (); | |
5864 | 2925 } |
2926 | |
5900 | 2927 const char * |
2928 mxGetFieldNameByNumber (const mxArray *ptr, int key_num) | |
5864 | 2929 { |
5900 | 2930 return ptr->get_field_name_by_number (key_num); |
2931 } | |
2932 | |
2933 int | |
2934 mxGetFieldNumber (const mxArray *ptr, const char *key) | |
2935 { | |
2936 return ptr->get_field_number (key); | |
5864 | 2937 } |
2938 | |
5900 | 2939 int |
6686 | 2940 mxGetString (const mxArray *ptr, char *buf, mwSize buflen) |
5900 | 2941 { |
2942 return ptr->get_string (buf, buflen); | |
2943 } | |
2944 | |
2945 char * | |
2946 mxArrayToString (const mxArray *ptr) | |
5864 | 2947 { |
5900 | 2948 return ptr->array_to_string (); |
2949 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
2950 |
6686 | 2951 mwIndex |
2952 mxCalcSingleSubscript (const mxArray *ptr, mwSize nsubs, mwIndex *subs) | |
5900 | 2953 { |
2954 return ptr->calc_single_subscript (nsubs, subs); | |
5864 | 2955 } |
5900 | 2956 |
6686 | 2957 size_t |
5900 | 2958 mxGetElementSize (const mxArray *ptr) |
2959 { | |
2960 return ptr->get_element_size (); | |
2961 } | |
2962 | |
2963 // ------------------------------------------------------------------ | |
5864 | 2964 |
2965 typedef void (*cmex_fptr) (int nlhs, mxArray **plhs, int nrhs, mxArray **prhs); | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2966 typedef F77_RET_T (*fmex_fptr) (int& nlhs, mxArray **plhs, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
2967 int& nrhs, mxArray **prhs); |
5864 | 2968 |
2969 octave_value_list | |
6068 | 2970 call_mex (bool have_fmex, void *f, const octave_value_list& args, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
2971 int nargout_arg, octave_mex_function *curr_mex_fcn) |
5864 | 2972 { |
5900 | 2973 // Use at least 1 for nargout since even for zero specified args, |
2974 // still want to be able to return an ans. | |
5864 | 2975 |
8806 | 2976 volatile int nargout = nargout_arg; |
2977 | |
5864 | 2978 int nargin = args.length (); |
5900 | 2979 OCTAVE_LOCAL_BUFFER (mxArray *, argin, nargin); |
5864 | 2980 for (int i = 0; i < nargin; i++) |
2981 argin[i] = 0; | |
2982 | |
2983 int nout = nargout == 0 ? 1 : nargout; | |
5900 | 2984 OCTAVE_LOCAL_BUFFER (mxArray *, argout, nout); |
5864 | 2985 for (int i = 0; i < nout; i++) |
2986 argout[i] = 0; | |
2987 | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2988 unwind_protect_safe frame; |
5905 | 2989 |
2990 // Save old mex pointer. | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
2991 frame.protect_var (mex_context); |
5905 | 2992 |
6068 | 2993 mex context (curr_mex_fcn); |
5900 | 2994 |
16227 | 2995 frame.add_fcn (mex::cleanup, static_cast<void *> (&context)); |
5864 | 2996 |
2997 for (int i = 0; i < nargin; i++) | |
2998 argin[i] = context.make_value (args(i)); | |
2999 | |
3000 if (setjmp (context.jump) == 0) | |
3001 { | |
5900 | 3002 mex_context = &context; |
5864 | 3003 |
6068 | 3004 if (have_fmex) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3005 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3006 fmex_fptr fcn = FCN_PTR_CAST (fmex_fptr, f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3007 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3008 int tmp_nargout = nargout; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3009 int tmp_nargin = nargin; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3010 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3011 fcn (tmp_nargout, argout, tmp_nargin, argin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3012 } |
5864 | 3013 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3014 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3015 cmex_fptr fcn = FCN_PTR_CAST (cmex_fptr, f); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3016 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3017 fcn (nargout, argout, nargin, argin); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3018 } |
5864 | 3019 } |
3020 | |
3021 // Convert returned array entries back into octave values. | |
3022 | |
3023 octave_value_list retval; | |
3024 | |
3025 if (! error_state) | |
3026 { | |
3027 if (nargout == 0 && argout[0]) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3028 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3029 // We have something for ans. |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3030 nargout = 1; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3031 } |
5900 | 3032 |
3033 retval.resize (nargout); | |
3034 | |
3035 for (int i = 0; i < nargout; i++) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3036 retval(i) = mxArray::as_octave_value (argout[i]); |
5864 | 3037 } |
3038 | |
3039 // Clean up mex resources. | |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
3040 frame.run (); |
5864 | 3041 |
3042 return retval; | |
3043 } | |
3044 | |
3045 // C interface to mex functions: | |
3046 | |
3047 const char * | |
3048 mexFunctionName (void) | |
3049 { | |
5900 | 3050 return mex_context ? mex_context->function_name () : "unknown"; |
3051 } | |
3052 | |
3053 int | |
15354
93dff6435fe1
tag calls to mxArray::malloc, mxArray::calloc, and mxArray::strsave with class name
John W. Eaton <jwe@octave.org>
parents:
15353
diff
changeset
|
3054 mexCallMATLAB (int nargout, mxArray *argout[], int nargin, |
15373
b5d0a47c171c
* mex.cc (mexCallMATLAB): Remove stray const added in 93dff6435fe1 (bug #37342).
John W. Eaton <jwe@octave.org>
parents:
15354
diff
changeset
|
3055 mxArray *argin[], const char *fname) |
5900 | 3056 { |
3057 octave_value_list args; | |
3058 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3059 // FIXME: do we need unwind protect to clean up args? Off hand, I |
5900 | 3060 // would say that this problem is endemic to Octave and we will |
3061 // continue to have memory leaks after Ctrl-C until proper exception | |
3062 // handling is implemented. longjmp() only clears the stack, so any | |
3063 // class which allocates data on the heap is going to leak. | |
3064 | |
3065 args.resize (nargin); | |
3066 | |
3067 for (int i = 0; i < nargin; i++) | |
5907 | 3068 args(i) = mxArray::as_octave_value (argin[i]); |
5900 | 3069 |
3070 octave_value_list retval = feval (fname, args, nargout); | |
3071 | |
3072 if (error_state && mex_context->trap_feval_error == 0) | |
5864 | 3073 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3074 // FIXME: is this the correct way to clean up? abort() is |
5900 | 3075 // going to trigger a long jump, so the normal class destructors |
3076 // will not be called. Hopefully this will reduce things to a | |
3077 // tiny leak. Maybe create a new octave memory tracer type | |
3078 // which prints a friendly message every time it is | |
3079 // created/copied/deleted to check this. | |
3080 | |
3081 args.resize (0); | |
3082 retval.resize (0); | |
3083 mex_context->abort (); | |
3084 } | |
3085 | |
3086 int num_to_copy = retval.length (); | |
3087 | |
3088 if (nargout < retval.length ()) | |
3089 num_to_copy = nargout; | |
3090 | |
3091 for (int i = 0; i < num_to_copy; i++) | |
3092 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3093 // FIXME: it would be nice to avoid copying the value here, |
5900 | 3094 // but there is no way to steal memory from a matrix, never mind |
3095 // that matrix memory is allocated by new[] and mxArray memory | |
3096 // is allocated by malloc(). | |
3097 argout[i] = mex_context->make_value (retval (i)); | |
3098 } | |
3099 | |
3100 while (num_to_copy < nargout) | |
3101 argout[num_to_copy++] = 0; | |
3102 | |
3103 if (error_state) | |
3104 { | |
3105 error_state = 0; | |
3106 return 1; | |
5864 | 3107 } |
3108 else | |
5900 | 3109 return 0; |
3110 } | |
3111 | |
3112 void | |
3113 mexSetTrapFlag (int flag) | |
3114 { | |
3115 if (mex_context) | |
3116 mex_context->trap_feval_error = flag; | |
3117 } | |
3118 | |
3119 int | |
3120 mexEvalString (const char *s) | |
3121 { | |
3122 int retval = 0; | |
3123 | |
3124 int parse_status; | |
3125 | |
3126 octave_value_list ret; | |
3127 | |
3128 ret = eval_string (s, false, parse_status, 0); | |
3129 | |
3130 if (parse_status || error_state) | |
3131 { | |
3132 error_state = 0; | |
3133 | |
3134 retval = 1; | |
3135 } | |
5864 | 3136 |
3137 return retval; | |
3138 } | |
3139 | |
3140 void | |
3141 mexErrMsgTxt (const char *s) | |
3142 { | |
3143 if (s && strlen (s) > 0) | |
5879 | 3144 error ("%s: %s", mexFunctionName (), s); |
5864 | 3145 else |
16851
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3146 { |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3147 // For compatibility with Matlab, print an empty message. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3148 // Octave's error routine requires a non-null input so use a SPACE. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3149 error (" "); |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3150 } |
5864 | 3151 |
5900 | 3152 mex_context->abort (); |
5864 | 3153 } |
3154 | |
5879 | 3155 void |
6338 | 3156 mexErrMsgIdAndTxt (const char *id, const char *fmt, ...) |
5879 | 3157 { |
6338 | 3158 if (fmt && strlen (fmt) > 0) |
3159 { | |
3160 const char *fname = mexFunctionName (); | |
3161 size_t len = strlen (fname) + 2 + strlen (fmt) + 1; | |
3162 OCTAVE_LOCAL_BUFFER (char, tmpfmt, len); | |
3163 sprintf (tmpfmt, "%s: %s", fname, fmt); | |
3164 va_list args; | |
3165 va_start (args, fmt); | |
3166 verror_with_id (id, tmpfmt, args); | |
3167 va_end (args); | |
3168 } | |
5879 | 3169 else |
16851
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3170 { |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3171 // For compatibility with Matlab, print an empty message. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3172 // Octave's error routine requires a non-null input so use a SPACE. |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3173 error (" "); |
209f0db3c32b
mexErrMsgTxt should abort when called with an empty string (bug #39343).
Rik <rik@octave.org>
parents:
16708
diff
changeset
|
3174 } |
5879 | 3175 |
5900 | 3176 mex_context->abort (); |
5879 | 3177 } |
3178 | |
3179 void | |
3180 mexWarnMsgTxt (const char *s) | |
3181 { | |
3182 warning ("%s", s); | |
3183 } | |
3184 | |
3185 void | |
6338 | 3186 mexWarnMsgIdAndTxt (const char *id, const char *fmt, ...) |
5879 | 3187 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3188 // FIXME: is this right? What does Matlab do if fmt is NULL or |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3189 // an empty string? |
6338 | 3190 |
3191 if (fmt && strlen (fmt) > 0) | |
3192 { | |
3193 const char *fname = mexFunctionName (); | |
3194 size_t len = strlen (fname) + 2 + strlen (fmt) + 1; | |
3195 OCTAVE_LOCAL_BUFFER (char, tmpfmt, len); | |
3196 sprintf (tmpfmt, "%s: %s", fname, fmt); | |
3197 va_list args; | |
3198 va_start (args, fmt); | |
3199 vwarning_with_id (id, tmpfmt, args); | |
3200 va_end (args); | |
3201 } | |
5879 | 3202 } |
5864 | 3203 |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3204 int |
5864 | 3205 mexPrintf (const char *fmt, ...) |
3206 { | |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3207 int retval; |
5864 | 3208 va_list args; |
3209 va_start (args, fmt); | |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3210 retval = octave_vformat (octave_stdout, fmt, args); |
5864 | 3211 va_end (args); |
10127
f21fdff5c906
Change signature of mexPrintf.
David Grundberg <davidg@cs.umu.se>
parents:
10126
diff
changeset
|
3212 return retval; |
5864 | 3213 } |
3214 | |
3215 mxArray * | |
5879 | 3216 mexGetVariable (const char *space, const char *name) |
5864 | 3217 { |
3218 mxArray *retval = 0; | |
3219 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3220 octave_value val; |
5864 | 3221 |
3222 if (! strcmp (space, "global")) | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3223 val = get_global_value (name); |
5864 | 3224 else |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3225 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3226 // FIXME: should this be in variables.cc? |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3227 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
3228 unwind_protect frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3229 |
7901 | 3230 bool caller = ! strcmp (space, "caller"); |
3231 bool base = ! strcmp (space, "base"); | |
3232 | |
3233 if (caller || base) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3234 { |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3235 // MEX files don't create a separate frame in the call stack, |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3236 // so we are already in the "caller" frame. |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3237 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3238 if (base) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3239 { |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3240 octave_call_stack::goto_base_frame (); |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3241 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3242 if (error_state) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3243 return retval; |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3244 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3245 frame.add_fcn (octave_call_stack::pop); |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3246 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3247 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3248 val = symbol_table::varval (name); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3249 } |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3250 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3251 mexErrMsgTxt ("mexGetVariable: symbol table does not exist"); |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7577
diff
changeset
|
3252 } |
7336 | 3253 |
3254 if (val.is_defined ()) | |
5864 | 3255 { |
7336 | 3256 retval = mex_context->make_value (val); |
3257 | |
3258 retval->set_name (name); | |
5864 | 3259 } |
3260 | |
3261 return retval; | |
3262 } | |
3263 | |
5879 | 3264 const mxArray * |
3265 mexGetVariablePtr (const char *space, const char *name) | |
5864 | 3266 { |
5879 | 3267 return mexGetVariable (space, name); |
5864 | 3268 } |
3269 | |
5900 | 3270 int |
15353
5f3a69a309a7
fix decl of mexPutVariable
John W. Eaton <jwe@octave.org>
parents:
15351
diff
changeset
|
3271 mexPutVariable (const char *space, const char *name, const mxArray *ptr) |
5864 | 3272 { |
5900 | 3273 if (! ptr) |
3274 return 1; | |
3275 | |
3276 if (! name) | |
3277 return 1; | |
3278 | |
3279 if (name[0] == '\0') | |
3280 name = ptr->get_name (); | |
3281 | |
3282 if (! name || name[0] == '\0') | |
3283 return 1; | |
3284 | |
3285 if (! strcmp (space, "global")) | |
5907 | 3286 set_global_value (name, mxArray::as_octave_value (ptr)); |
5900 | 3287 else |
3288 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
3289 // FIXME: should this be in variables.cc? |
7336 | 3290 |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9689
diff
changeset
|
3291 unwind_protect frame; |
9144
c6463412aebb
eliminate symbol_table::scope_stack; fix scoping issue with evalin
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
3292 |
7901 | 3293 bool caller = ! strcmp (space, "caller"); |
3294 bool base = ! strcmp (space, "base"); | |
3295 | |
3296 if (caller || base) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3297 { |
16708
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3298 // MEX files don't create a separate frame in the call stack, |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3299 // so we are already in the "caller" frame. |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3300 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3301 if (base) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3302 { |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3303 octave_call_stack::goto_base_frame (); |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3304 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3305 if (error_state) |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3306 return 1; |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3307 |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3308 frame.add_fcn (octave_call_stack::pop); |
08f0f274de36
use correct "caller" workspace for mexputvariable and mexgetvariable
John W. Eaton <jwe@octave.org>
parents:
16442
diff
changeset
|
3309 } |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3310 |
16442
302157614308
deprecate symbol_table::varref functions
John W. Eaton <jwe@octave.org>
parents:
16227
diff
changeset
|
3311 symbol_table::assign (name, mxArray::as_octave_value (ptr)); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3312 } |
5900 | 3313 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3314 mexErrMsgTxt ("mexPutVariable: symbol table does not exist"); |
5900 | 3315 } |
3316 | |
3317 return 0; | |
5864 | 3318 } |
3319 | |
3320 void | |
5900 | 3321 mexMakeArrayPersistent (mxArray *ptr) |
5864 | 3322 { |
7172 | 3323 maybe_unmark_array (ptr); |
5864 | 3324 } |
5879 | 3325 |
5864 | 3326 void |
5900 | 3327 mexMakeMemoryPersistent (void *ptr) |
5864 | 3328 { |
7172 | 3329 maybe_unmark (ptr); |
5864 | 3330 } |
3331 | |
5900 | 3332 int |
6068 | 3333 mexAtExit (void (*f) (void)) |
5864 | 3334 { |
6068 | 3335 if (mex_context) |
3336 { | |
3337 octave_mex_function *curr_mex_fcn = mex_context->current_mex_function (); | |
3338 | |
3339 assert (curr_mex_fcn); | |
3340 | |
3341 curr_mex_fcn->atexit (f); | |
3342 } | |
3343 | |
5900 | 3344 return 0; |
5864 | 3345 } |
3346 | |
5900 | 3347 const mxArray * |
6595 | 3348 mexGet (double handle, const char *property) |
5864 | 3349 { |
6595 | 3350 mxArray *m = 0; |
3351 octave_value ret = get_property_from_handle (handle, property, "mexGet"); | |
3352 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14840
diff
changeset
|
3353 if (!error_state && ret.is_defined ()) |
6595 | 3354 m = ret.as_mxArray (); |
3355 return m; | |
5864 | 3356 } |
3357 | |
5900 | 3358 int |
3359 mexIsGlobal (const mxArray *ptr) | |
5864 | 3360 { |
5900 | 3361 return mxIsFromGlobalWS (ptr); |
5864 | 3362 } |
3363 | |
5900 | 3364 int |
3365 mexIsLocked (void) | |
5864 | 3366 { |
5900 | 3367 int retval = 0; |
3368 | |
3369 if (mex_context) | |
3370 { | |
3371 const char *fname = mexFunctionName (); | |
3372 | |
3373 retval = mislocked (fname); | |
3374 } | |
3375 | |
3376 return retval; | |
5864 | 3377 } |
3378 | |
5900 | 3379 std::map<std::string,int> mex_lock_count; |
3380 | |
3381 void | |
3382 mexLock (void) | |
5864 | 3383 { |
5900 | 3384 if (mex_context) |
5864 | 3385 { |
5900 | 3386 const char *fname = mexFunctionName (); |
3387 | |
3388 if (mex_lock_count.find (fname) == mex_lock_count.end ()) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3389 mex_lock_count[fname] = 1; |
5900 | 3390 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3391 mex_lock_count[fname]++; |
5900 | 3392 |
7336 | 3393 mlock (); |
5864 | 3394 } |
3395 } | |
3396 | |
5900 | 3397 int |
6595 | 3398 mexSet (double handle, const char *property, mxArray *val) |
5900 | 3399 { |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3400 bool ret = |
6595 | 3401 set_property_in_handle (handle, property, mxArray::as_octave_value (val), |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3402 "mexSet"); |
6595 | 3403 return (ret ? 0 : 1); |
5900 | 3404 } |
3405 | |
3406 void | |
3407 mexUnlock (void) | |
5864 | 3408 { |
5900 | 3409 if (mex_context) |
5864 | 3410 { |
5900 | 3411 const char *fname = mexFunctionName (); |
3412 | |
5905 | 3413 std::map<std::string,int>::iterator p = mex_lock_count.find (fname); |
3414 | |
6062 | 3415 if (p != mex_lock_count.end ()) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3416 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3417 int count = --mex_lock_count[fname]; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3418 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3419 if (count == 0) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3420 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3421 munlock (fname); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3422 |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3423 mex_lock_count.erase (p); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3424 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10225
diff
changeset
|
3425 } |
5864 | 3426 } |
3427 } |