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