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