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