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