Mercurial > hg > octave-nkf
annotate src/mxarray.h.in @ 14182:f8d99761244c stable
test: Expand %!testif functionality to multiple conditions
* test.m: Add testing for multiple conditions in %!testif statement.
* svds.m, eigs.cc: Test for ARPACK and other libraries before running
some tests.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 09 Jan 2012 13:32:44 -0800 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
6686 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2001-2012 Paul Kienzle |
6686 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
6686 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
6686 | 20 |
21 */ | |
22 | |
23 /* | |
24 | |
25 Part of this code was originally distributed as part of Octave Forge under | |
26 the following terms: | |
27 | |
28 Author: Paul Kienzle | |
29 I grant this code to the public domain. | |
30 2001-03-22 | |
31 | |
32 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
33 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
34 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
35 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
36 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
38 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
39 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
40 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
41 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
42 SUCH DAMAGE. | |
43 | |
44 */ | |
45 | |
46 #if ! defined (MXARRAY_H) | |
47 #define MXARRAY_H | |
48 | |
49 typedef enum | |
50 { | |
51 mxREAL = 0, | |
52 mxCOMPLEX = 1 | |
53 } | |
54 mxComplexity; | |
55 | |
56 typedef enum | |
57 { | |
58 mxUNKNOWN_CLASS = 0, | |
59 mxCELL_CLASS, | |
60 mxSTRUCT_CLASS, | |
61 mxLOGICAL_CLASS, | |
62 mxCHAR_CLASS, | |
63 mxUNUSED_CLASS, | |
64 mxDOUBLE_CLASS, | |
65 mxSINGLE_CLASS, | |
66 mxINT8_CLASS, | |
67 mxUINT8_CLASS, | |
68 mxINT16_CLASS, | |
69 mxUINT16_CLASS, | |
70 mxINT32_CLASS, | |
71 mxUINT32_CLASS, | |
72 mxINT64_CLASS, | |
73 mxUINT64_CLASS, | |
7056 | 74 mxFUNCTION_CLASS |
6686 | 75 } |
76 mxClassID; | |
77 | |
7574
9669b69e34ef
define mxLogical as unsigned char instead of int
John W. Eaton <jwe@octave.org>
parents:
7417
diff
changeset
|
78 typedef unsigned char mxLogical; |
6686 | 79 |
80 /* typedef Uint16 mxChar; */ | |
81 typedef char mxChar; | |
82 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
83 /* |
6686 | 84 * FIXME? Mathworks says these should be size_t on 64-bit system and when |
85 * mex is used with the -largearraydims flag, but why do that? Its better | |
86 * to conform to the same indexing as the rest of Octave | |
87 */ | |
9906 | 88 typedef %OCTAVE_IDX_TYPE% mwSize; |
89 typedef %OCTAVE_IDX_TYPE% mwIndex; | |
6686 | 90 |
91 #if ! defined (MXARRAY_TYPEDEFS_ONLY) | |
92 | |
7417 | 93 #include <cstring> |
94 | |
6686 | 95 class octave_value; |
96 | |
97 #define DO_MUTABLE_METHOD(RET_T, METHOD_CALL) \ | |
98 RET_T retval = rep->METHOD_CALL; \ | |
99 \ | |
100 if (rep->mutation_needed ()) \ | |
101 { \ | |
102 maybe_mutate (); \ | |
103 retval = rep->METHOD_CALL; \ | |
104 } \ | |
105 \ | |
106 return retval | |
107 | |
108 #define DO_VOID_MUTABLE_METHOD(METHOD_CALL) \ | |
109 rep->METHOD_CALL; \ | |
110 \ | |
111 if (rep->mutation_needed ()) \ | |
112 { \ | |
113 maybe_mutate (); \ | |
114 rep->METHOD_CALL; \ | |
115 } | |
116 | |
117 // This just provides a way to avoid infinite recursion when building | |
118 // mxArray objects. | |
119 | |
120 struct | |
121 xmxArray | |
122 { | |
123 xmxArray (void) { } | |
124 }; | |
125 | |
126 // The main interface class. The representation can be based on an | |
127 // octave_value object or a separate object that tries to reproduce | |
128 // the semantics of mxArray objects in Matlab more directly. | |
129 | |
130 class mxArray | |
131 { | |
132 public: | |
133 | |
134 mxArray (const octave_value& ov); | |
135 | |
136 mxArray (mxClassID id, mwSize ndims, const mwSize *dims, | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9906
diff
changeset
|
137 mxComplexity flag = mxREAL); |
6686 | 138 |
139 mxArray (mxClassID id, const dim_vector& dv, mxComplexity flag = mxREAL); | |
140 | |
141 mxArray (mxClassID id, mwSize m, mwSize n, mxComplexity flag = mxREAL); | |
142 | |
143 mxArray (mxClassID id, double val); | |
144 | |
145 mxArray (mxClassID id, mxLogical val); | |
146 | |
147 mxArray (const char *str); | |
148 | |
6806 | 149 mxArray (mwSize m, const char **str); |
6686 | 150 |
6806 | 151 mxArray (mxClassID id, mwSize m, mwSize n, mwSize nzmax, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9906
diff
changeset
|
152 mxComplexity flag = mxREAL); |
6686 | 153 |
154 mxArray (mwSize ndims, const mwSize *dims, int num_keys, const char **keys); | |
155 | |
156 mxArray (const dim_vector& dv, int num_keys, const char **keys); | |
157 | |
158 mxArray (mwSize m, mwSize n, int num_keys, const char **keys); | |
159 | |
160 mxArray (mwSize ndims, const mwSize *dims); | |
161 | |
162 mxArray (const dim_vector& dv); | |
163 | |
164 mxArray (mwSize m, mwSize n); | |
165 | |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11100
diff
changeset
|
166 virtual mxArray *dup (void) const |
6686 | 167 { |
11277
7d5351fc575a
mex.cc: convert mxArray_octave_value to matlab style representation when duplicating
John W. Eaton <jwe@octave.org>
parents:
11100
diff
changeset
|
168 mxArray *new_rep = rep->dup (); |
6686 | 169 |
170 return new mxArray (new_rep, name); | |
171 } | |
172 | |
173 virtual ~mxArray (void); | |
174 | |
175 virtual bool is_octave_value (void) const { return rep->is_octave_value (); } | |
176 | |
177 virtual int is_cell (void) const { return rep->is_cell (); } | |
178 | |
179 virtual int is_char (void) const { return rep->is_char (); } | |
180 | |
181 virtual int is_class (const char *name_arg) const { return rep->is_class (name_arg); } | |
182 | |
183 virtual int is_complex (void) const { return rep->is_complex (); } | |
184 | |
185 virtual int is_double (void) const { return rep->is_double (); } | |
186 | |
11100
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
187 virtual int is_function_handle (void) const { return rep->is_function_handle (); } |
cdf940db26a0
provide mxIsFunctionHandle MEX interface function
John W. Eaton <jwe@octave.org>
parents:
10317
diff
changeset
|
188 |
6686 | 189 virtual int is_int16 (void) const { return rep->is_int16 (); } |
190 | |
191 virtual int is_int32 (void) const { return rep->is_int32 (); } | |
192 | |
193 virtual int is_int64 (void) const { return rep->is_int64 (); } | |
194 | |
195 virtual int is_int8 (void) const { return rep->is_int8 (); } | |
196 | |
197 virtual int is_logical (void) const { return rep->is_logical (); } | |
198 | |
199 virtual int is_numeric (void) const { return rep->is_numeric (); } | |
200 | |
201 virtual int is_single (void) const { return rep->is_single (); } | |
202 | |
203 virtual int is_sparse (void) const { return rep->is_sparse (); } | |
204 | |
205 virtual int is_struct (void) const { return rep->is_struct (); } | |
206 | |
207 virtual int is_uint16 (void) const { return rep->is_uint16 (); } | |
208 | |
209 virtual int is_uint32 (void) const { return rep->is_uint32 (); } | |
210 | |
211 virtual int is_uint64 (void) const { return rep->is_uint64 (); } | |
212 | |
213 virtual int is_uint8 (void) const { return rep->is_uint8 (); } | |
214 | |
215 virtual int is_logical_scalar (void) const { return rep->is_logical_scalar (); } | |
216 | |
217 virtual int is_logical_scalar_true (void) const { return rep->is_logical_scalar_true (); } | |
218 | |
219 virtual mwSize get_m (void) const { return rep->get_m (); } | |
220 | |
221 virtual mwSize get_n (void) const { return rep->get_n (); } | |
222 | |
223 virtual mwSize *get_dimensions (void) const { return rep->get_dimensions (); } | |
224 | |
225 virtual mwSize get_number_of_dimensions (void) const { return rep->get_number_of_dimensions (); } | |
226 | |
227 virtual void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); } | |
228 | |
229 virtual void set_n (mwSize n) { DO_VOID_MUTABLE_METHOD (set_n (n)); } | |
230 | |
231 virtual void set_dimensions (mwSize *dims_arg, mwSize ndims_arg) { DO_VOID_MUTABLE_METHOD (set_dimensions (dims_arg, ndims_arg)); } | |
232 | |
233 virtual mwSize get_number_of_elements (void) const { return rep->get_number_of_elements (); } | |
234 | |
235 virtual int is_empty (void) const { return get_number_of_elements () == 0; } | |
236 | |
237 const char *get_name (void) const { return name; } | |
238 | |
239 void set_name (const char *name_arg); | |
240 | |
241 virtual mxClassID get_class_id (void) const { return rep->get_class_id (); } | |
242 | |
243 virtual const char *get_class_name (void) const { return rep->get_class_name (); } | |
244 | |
245 virtual void set_class_name (const char *name_arg) { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); } | |
246 | |
247 virtual mxArray *get_cell (mwIndex idx) const { DO_MUTABLE_METHOD (mxArray *, get_cell (idx)); } | |
248 | |
249 virtual void set_cell (mwIndex idx, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); } | |
250 | |
251 virtual double get_scalar (void) const { return rep->get_scalar (); } | |
252 | |
253 virtual void *get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); } | |
254 | |
255 virtual void *get_imag_data (void) const { DO_MUTABLE_METHOD (void *, get_imag_data ()); } | |
256 | |
257 virtual void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); } | |
258 | |
259 virtual void set_imag_data (void *pi) { DO_VOID_MUTABLE_METHOD (set_imag_data (pi)); } | |
260 | |
261 virtual mwIndex *get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); } | |
262 | |
263 virtual mwIndex *get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); } | |
264 | |
265 virtual mwSize get_nzmax (void) const { return rep->get_nzmax (); } | |
266 | |
267 virtual void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); } | |
268 | |
269 virtual void set_jc (mwIndex *jc) { DO_VOID_MUTABLE_METHOD (set_jc (jc)); } | |
270 | |
271 virtual void set_nzmax (mwSize nzmax) { DO_VOID_MUTABLE_METHOD (set_nzmax (nzmax)); } | |
272 | |
273 virtual int add_field (const char *key) { DO_MUTABLE_METHOD (int, add_field (key)); } | |
274 | |
275 virtual void remove_field (int key_num) { DO_VOID_MUTABLE_METHOD (remove_field (key_num)); } | |
276 | |
277 virtual mxArray *get_field_by_number (mwIndex index, int key_num) const { DO_MUTABLE_METHOD (mxArray *, get_field_by_number (index, key_num)); } | |
278 | |
279 virtual void set_field_by_number (mwIndex index, int key_num, mxArray *val) { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); } | |
280 | |
281 virtual int get_number_of_fields (void) const { return rep->get_number_of_fields (); } | |
282 | |
283 virtual const char *get_field_name_by_number (int key_num) const { DO_MUTABLE_METHOD (const char*, get_field_name_by_number (key_num)); } | |
284 | |
285 virtual int get_field_number (const char *key) const { DO_MUTABLE_METHOD (int, get_field_number (key)); } | |
286 | |
6806 | 287 virtual int get_string (char *buf, mwSize buflen) const { return rep->get_string (buf, buflen); } |
6686 | 288 |
289 virtual char *array_to_string (void) const { return rep->array_to_string (); } | |
290 | |
291 virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const { return rep->calc_single_subscript (nsubs, subs); } | |
292 | |
293 virtual size_t get_element_size (void) const { return rep->get_element_size (); } | |
294 | |
295 virtual bool mutation_needed (void) const { return rep->mutation_needed (); } | |
296 | |
297 virtual mxArray *mutate (void) const { return rep->mutate (); } | |
298 | |
299 static void *malloc (size_t n); | |
300 | |
301 static void *calloc (size_t n, size_t t); | |
302 | |
303 static char *strsave (const char *str) | |
304 { | |
305 char *retval = 0; | |
306 | |
307 if (str) | |
308 { | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9906
diff
changeset
|
309 mwSize sz = sizeof (mxChar) * (strlen (str) + 1); |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9906
diff
changeset
|
310 retval = static_cast<char *> (mxArray::malloc (sz)); |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
9906
diff
changeset
|
311 strcpy (retval, str); |
6686 | 312 } |
313 | |
314 return retval; | |
315 } | |
316 | |
317 static octave_value as_octave_value (mxArray *ptr); | |
318 | |
319 protected: | |
320 | |
321 virtual octave_value as_octave_value (void) const; | |
322 | |
323 mxArray (const xmxArray&) : rep (0), name (0) { } | |
324 | |
325 private: | |
326 | |
327 mutable mxArray *rep; | |
328 | |
329 char *name; | |
330 | |
331 mxArray (mxArray *r, const char *n) | |
332 : rep (r), name (strsave (n)) { } | |
333 | |
334 void maybe_mutate (void) const; | |
335 | |
336 // No copying! | |
337 | |
338 mxArray (const mxArray&); | |
339 | |
340 mxArray& operator = (const mxArray&); | |
341 }; | |
342 | |
343 #undef DO_MUTABLE_METHOD | |
344 #undef DO_VOID_MUTABLE_METHOD | |
345 | |
346 #endif | |
347 #endif |