GNU Octave  8.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
mxarray.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2001-2023 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 /*
27 
28 Part of this code was originally distributed as part of Octave Forge under
29 the following terms:
30 
31 Author: Paul Kienzle
32 I grant this code to the public domain.
33 2001-03-22
34 
35 THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
36 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
38 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
39 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
40 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
41 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
44 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 SUCH DAMAGE.
46 
47 */
48 
49 #if ! defined (octave_mxarray_h)
50 #define octave_mxarray_h 1
51 
52 #include "octave-config.h"
53 
54 #include "mxtypes.h"
55 
56 #if ! defined (MXARRAY_TYPEDEFS_ONLY)
57 
58 #include <cstring>
59 #include "error.h"
60 
61 class octave_value;
62 class dim_vector;
63 
64 #define DO_MUTABLE_METHOD(RET_T, METHOD_CALL) \
65  RET_T retval = m_rep->METHOD_CALL; \
66  \
67  if (m_rep->mutation_needed ()) \
68  { \
69  maybe_mutate (); \
70  retval = m_rep->METHOD_CALL; \
71  } \
72  \
73  return retval
74 
75 #define DO_VOID_MUTABLE_METHOD(METHOD_CALL) \
76  m_rep->METHOD_CALL; \
77  \
78  if (m_rep->mutation_needed ()) \
79  { \
80  maybe_mutate (); \
81  m_rep->METHOD_CALL; \
82  }
83 
84 class OCTINTERP_API mxArray;
85 
86 // A class to provide the default implementation of some of the
87 // virtual functions declared in the mxArray class.
88 
89 class OCTINTERP_API mxArray_base
90 {
91 protected:
92 
93  OCTINTERP_API mxArray_base (bool interleaved);
94 
95 public:
96 
97  virtual mxArray_base * dup (void) const = 0;
98 
99  virtual mxArray * as_mxArray (void) const { return nullptr; }
100 
101  virtual ~mxArray_base (void) = default;
102 
103  virtual bool is_octave_value (void) const { return false; }
104 
105  virtual int iscell (void) const = 0;
106 
107  virtual int is_char (void) const = 0;
108 
109  virtual int is_class (const char *name_arg) const
110  {
111  int retval = 0;
112 
113  const char *cname = get_class_name ();
114 
115  if (cname && name_arg)
116  retval = ! strcmp (cname, name_arg);
117 
118  return retval;
119  }
120 
121  virtual int is_complex (void) const = 0;
122 
123  virtual int is_double (void) const = 0;
124 
125  virtual int is_function_handle (void) const = 0;
126 
127  virtual int is_int16 (void) const = 0;
128 
129  virtual int is_int32 (void) const = 0;
130 
131  virtual int is_int64 (void) const = 0;
132 
133  virtual int is_int8 (void) const = 0;
134 
135  virtual int is_logical (void) const = 0;
136 
137  virtual int is_numeric (void) const = 0;
138 
139  virtual int is_single (void) const = 0;
140 
141  virtual int is_sparse (void) const = 0;
142 
143  virtual int is_struct (void) const = 0;
144 
145  virtual int is_uint16 (void) const = 0;
146 
147  virtual int is_uint32 (void) const = 0;
148 
149  virtual int is_uint64 (void) const = 0;
150 
151  virtual int is_uint8 (void) const = 0;
152 
153  virtual int is_logical_scalar (void) const
154  {
155  return is_logical () && get_number_of_elements () == 1;
156  }
157 
158  virtual int is_logical_scalar_true (void) const = 0;
159 
160  virtual mwSize get_m (void) const = 0;
161 
162  virtual mwSize get_n (void) const = 0;
163 
164  virtual mwSize * get_dimensions (void) const = 0;
165 
166  virtual mwSize get_number_of_dimensions (void) const = 0;
167 
168  virtual void set_m (mwSize m) = 0;
169 
170  virtual void set_n (mwSize n) = 0;
171 
172  virtual int set_dimensions (mwSize *dims_arg, mwSize ndims_arg) = 0;
173 
174  virtual mwSize get_number_of_elements (void) const = 0;
175 
176  virtual int isempty (void) const = 0;
177 
178  virtual bool is_scalar (void) const = 0;
179 
180  virtual mxClassID get_class_id (void) const = 0;
181 
182  virtual const char * get_class_name (void) const = 0;
183 
184  virtual void set_class_name (const char *name_arg) = 0;
185 
186  // The following functions aren't pure virtual because they are only
187  // valid for one type. Making them pure virtual would mean that they
188  // have to be implemented for all derived types, and all of those
189  // would need to throw errors instead of just doing it once here.
190 
191  virtual mxArray *
192  get_property (mwIndex /*idx*/, const char * /*pname*/) const
193  {
194  return nullptr;
195  }
196 
197  virtual void set_property (mwIndex /*idx*/, const char * /*pname*/,
198  const mxArray * /*pval*/)
199  {
200  err_invalid_type ("set_property");
201  }
202 
203  virtual mxArray * get_cell (mwIndex /*idx*/) const
204  {
205  err_invalid_type ("get_cell");
206  }
207 
208  virtual void set_cell (mwIndex idx, mxArray *val) = 0;
209 
210  virtual double get_scalar (void) const = 0;
211 
212  virtual void * get_data (void) const = 0;
213 
214  virtual mxDouble * get_doubles (void) const = 0;
215  virtual mxSingle * get_singles (void) const = 0;
216  virtual mxInt8 * get_int8s (void) const = 0;
217  virtual mxInt16 * get_int16s (void) const = 0;
218  virtual mxInt32 * get_int32s (void) const = 0;
219  virtual mxInt64 * get_int64s (void) const = 0;
220  virtual mxUint8 * get_uint8s (void) const = 0;
221  virtual mxUint16 * get_uint16s (void) const = 0;
222  virtual mxUint32 * get_uint32s (void) const = 0;
223  virtual mxUint64 * get_uint64s (void) const = 0;
224 
225  virtual mxComplexDouble * get_complex_doubles (void) const = 0;
226  virtual mxComplexSingle * get_complex_singles (void) const = 0;
227 #if 0
228  /* We don't have these yet. */
229  virtual mxComplexInt8 * get_complex_int8s (void) const = 0;
230  virtual mxComplexInt16 * get_complex_int16s (void) const = 0;
231  virtual mxComplexInt32 * get_complex_int32s (void) const = 0;
232  virtual mxComplexInt64 * get_complex_int64s (void) const = 0;
233  virtual mxComplexUint8 * get_complex_uint8s (void) const = 0;
234  virtual mxComplexUint16 * get_complex_uint16s (void) const = 0;
235  virtual mxComplexUint32 * get_complex_uint32s (void) const = 0;
236  virtual mxComplexUint64 * get_complex_uint64s (void) const = 0;
237 #endif
238 
239  virtual void * get_imag_data (void) const = 0;
240 
241  virtual void set_data (void *pr) = 0;
242 
243  virtual int set_doubles (mxDouble *data) = 0;
244  virtual int set_singles (mxSingle *data) = 0;
245  virtual int set_int8s (mxInt8 *data) = 0;
246  virtual int set_int16s (mxInt16 *data) = 0;
247  virtual int set_int32s (mxInt32 *data) = 0;
248  virtual int set_int64s (mxInt64 *data) = 0;
249  virtual int set_uint8s (mxUint8 *data) = 0;
250  virtual int set_uint16s (mxUint16 *data) = 0;
251  virtual int set_uint32s (mxUint32 *data) = 0;
252  virtual int set_uint64s (mxUint64 *data) = 0;
253 
254  virtual int set_complex_doubles (mxComplexDouble *data) = 0;
255  virtual int set_complex_singles (mxComplexSingle *data) = 0;
256 #if 0
257  /* We don't have these yet. */
258  virtual int set_complex_int8s (mxComplexInt8 *data) = 0;
259  virtual int set_complex_int16s (mxComplexInt16 *data) = 0;
260  virtual int set_complex_int32s (mxComplexInt32 *data) = 0;
261  virtual int set_complex_int64s (mxComplexInt64 *data) = 0;
262  virtual int set_complex_uint8s (mxComplexUint8 *data) = 0;
263  virtual int set_complex_uint16s (mxComplexUint16 *data) = 0;
264  virtual int set_complex_uint32s (mxComplexUint32 *data) = 0;
265  virtual int set_complex_uint64s (mxComplexUint64 *data) = 0;
266 #endif
267 
268  virtual void set_imag_data (void *pi) = 0;
269 
270  virtual mwIndex * get_ir (void) const = 0;
271 
272  virtual mwIndex * get_jc (void) const = 0;
273 
274  virtual mwSize get_nzmax (void) const = 0;
275 
276  virtual void set_ir (mwIndex *ir) = 0;
277 
278  virtual void set_jc (mwIndex *jc) = 0;
279 
280  virtual void set_nzmax (mwSize nzmax) = 0;
281 
282  virtual int add_field (const char *key) = 0;
283 
284  virtual void remove_field (int key_num) = 0;
285 
286  virtual mxArray * get_field_by_number (mwIndex index, int key_num) const = 0;
287 
288  virtual void
289  set_field_by_number (mwIndex index, int key_num, mxArray *val) = 0;
290 
291  virtual int get_number_of_fields (void) const = 0;
292 
293  virtual const char * get_field_name_by_number (int key_num) const = 0;
294 
295  virtual int get_field_number (const char *key) const = 0;
296 
297  virtual int get_string (char *buf, mwSize buflen) const = 0;
298 
299  virtual char * array_to_string (void) const = 0;
300 
301  virtual mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const = 0;
302 
303  virtual std::size_t get_element_size (void) const = 0;
304 
305  virtual bool mutation_needed (void) const { return false; }
306 
307  virtual mxArray * mutate (void) const { return nullptr; }
308 
309  virtual octave_value as_octave_value (void) const = 0;
310 
311 protected:
312 
313  mxArray_base (const mxArray_base&) = default;
314 
315  std::size_t get_numeric_element_size (std::size_t size) const
316  {
317  return (m_interleaved
318  ? is_complex () ? 2 * size : size
319  : size);
320  }
321 
322  OCTAVE_NORETURN void err_invalid_type (const char *op) const
323  {
324  error ("%s: invalid type for mxArray::%s", get_class_name (), op);
325  }
326 
327  //--------
328 
329  // If TRUE, we are using interleaved storage for complex numeric arrays.
331 
332 };
333 
334 // The main interface class. The representation can be based on an
335 // octave_value object or a separate object that tries to reproduce
336 // the semantics of mxArray objects in Matlab more directly.
337 
338 class mxArray
339 {
340 public:
341 
342  OCTINTERP_API mxArray (bool interleaved, const octave_value& ov);
343 
344  OCTINTERP_API mxArray (bool interleaved, mxClassID id, mwSize ndims,
345  const mwSize *dims, mxComplexity flag = mxREAL,
346  bool init = true);
347 
348  OCTINTERP_API mxArray (bool interleaved, mxClassID id, const dim_vector& dv,
349  mxComplexity flag = mxREAL);
350 
351  OCTINTERP_API mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n,
352  mxComplexity flag = mxREAL, bool init = true);
353 
354  OCTINTERP_API mxArray (bool interleaved, mxClassID id, double val);
355 
356  OCTINTERP_API mxArray (bool interleaved, mxClassID id, mxLogical val);
357 
358  OCTINTERP_API mxArray (bool interleaved, const char *str);
359 
360  OCTINTERP_API mxArray (bool interleaved, mwSize m, const char **str);
361 
362  OCTINTERP_API mxArray (bool interleaved, mxClassID id, mwSize m, mwSize n,
363  mwSize nzmax, mxComplexity flag = mxREAL);
364 
365  OCTINTERP_API mxArray (bool interleaved, mwSize ndims, const mwSize *dims,
366  int num_keys, const char **keys);
367 
368  OCTINTERP_API mxArray (bool interleaved, const dim_vector& dv, int num_keys,
369  const char **keys);
370 
371  OCTINTERP_API mxArray (bool interleaved, mwSize m, mwSize n, int num_keys,
372  const char **keys);
373 
374  OCTINTERP_API mxArray (bool interleaved, mwSize ndims, const mwSize *dims);
375 
376  OCTINTERP_API mxArray (bool interleaved, const dim_vector& dv);
377 
378  OCTINTERP_API mxArray (bool interleaved, mwSize m, mwSize n);
379 
380  mxArray * dup (void) const
381  {
382  mxArray *retval = m_rep->as_mxArray ();
383 
384  if (retval)
385  retval->set_name (m_name);
386  else
387  {
388  mxArray_base *new_rep = m_rep->dup ();
389 
390  retval = new mxArray (new_rep, m_name);
391  }
392 
393  return retval;
394  }
395 
396  // No copying!
397 
398  mxArray (const mxArray&) = delete;
399 
400  mxArray& operator = (const mxArray&) = delete;
401 
402  OCTINTERP_API ~mxArray (void);
403 
404  bool is_octave_value (void) const { return m_rep->is_octave_value (); }
405 
406  int iscell (void) const { return m_rep->iscell (); }
407 
408  int is_char (void) const { return m_rep->is_char (); }
409 
410  int is_class (const char *name_arg) const { return m_rep->is_class (name_arg); }
411 
412  int is_complex (void) const { return m_rep->is_complex (); }
413 
414  int is_double (void) const { return m_rep->is_double (); }
415 
416  int is_function_handle (void) const { return m_rep->is_function_handle (); }
417 
418  int is_int16 (void) const { return m_rep->is_int16 (); }
419 
420  int is_int32 (void) const { return m_rep->is_int32 (); }
421 
422  int is_int64 (void) const { return m_rep->is_int64 (); }
423 
424  int is_int8 (void) const { return m_rep->is_int8 (); }
425 
426  int is_logical (void) const { return m_rep->is_logical (); }
427 
428  int is_numeric (void) const { return m_rep->is_numeric (); }
429 
430  int is_single (void) const { return m_rep->is_single (); }
431 
432  int is_sparse (void) const { return m_rep->is_sparse (); }
433 
434  int is_struct (void) const { return m_rep->is_struct (); }
435 
436  int is_uint16 (void) const { return m_rep->is_uint16 (); }
437 
438  int is_uint32 (void) const { return m_rep->is_uint32 (); }
439 
440  int is_uint64 (void) const { return m_rep->is_uint64 (); }
441 
442  int is_uint8 (void) const { return m_rep->is_uint8 (); }
443 
444  int is_logical_scalar (void) const { return m_rep->is_logical_scalar (); }
445 
446  int is_logical_scalar_true (void) const
447  { return m_rep->is_logical_scalar_true (); }
448 
449  mwSize get_m (void) const { return m_rep->get_m (); }
450 
451  mwSize get_n (void) const { return m_rep->get_n (); }
452 
453  mwSize * get_dimensions (void) const { return m_rep->get_dimensions (); }
454 
455  mwSize get_number_of_dimensions (void) const
456  { return m_rep->get_number_of_dimensions (); }
457 
458  void set_m (mwSize m) { DO_VOID_MUTABLE_METHOD (set_m (m)); }
459 
460  void set_n (mwSize n) { DO_VOID_MUTABLE_METHOD (set_n (n)); }
461 
462  int set_dimensions (mwSize *dims_arg, mwSize ndims_arg)
463  { DO_MUTABLE_METHOD (int, set_dimensions (dims_arg, ndims_arg)); }
464 
465  mwSize get_number_of_elements (void) const
466  { return m_rep->get_number_of_elements (); }
467 
468  int isempty (void) const { return get_number_of_elements () == 0; }
469 
470  bool is_scalar (void) const { return m_rep->is_scalar (); }
471 
472  const char * get_name (void) const { return m_name; }
473 
474  OCTINTERP_API void set_name (const char *name);
475 
476  mxClassID get_class_id (void) const { return m_rep->get_class_id (); }
477 
478  const char * get_class_name (void) const { return m_rep->get_class_name (); }
479 
480  mxArray * get_property (mwIndex idx, const char *pname) const
481  { return m_rep->get_property (idx, pname); }
482 
483  void set_property (mwIndex idx, const char *pname, const mxArray *pval)
484  { m_rep->set_property (idx, pname, pval); }
485 
486  void set_class_name (const char *name_arg)
487  { DO_VOID_MUTABLE_METHOD (set_class_name (name_arg)); }
488 
489  mxArray * get_cell (mwIndex idx) const
490  { DO_MUTABLE_METHOD (mxArray *, get_cell (idx)); }
491 
492  void set_cell (mwIndex idx, mxArray *val)
493  { DO_VOID_MUTABLE_METHOD (set_cell (idx, val)); }
494 
495  double get_scalar (void) const { return m_rep->get_scalar (); }
496 
497  void * get_data (void) const { DO_MUTABLE_METHOD (void *, get_data ()); }
498 
499  mxDouble * get_doubles (void) const
500  { DO_MUTABLE_METHOD (mxDouble *, get_doubles ()); }
501 
502  mxSingle * get_singles (void) const
503  { DO_MUTABLE_METHOD (mxSingle *, get_singles ()); }
504 
505  mxInt8 * get_int8s (void) const
506  { DO_MUTABLE_METHOD (mxInt8 *, get_int8s ()); }
507 
508  mxInt16 * get_int16s (void) const
509  { DO_MUTABLE_METHOD (mxInt16 *, get_int16s ()); }
510 
511  mxInt32 * get_int32s (void) const
512  { DO_MUTABLE_METHOD (mxInt32 *, get_int32s ()); }
513 
514  mxInt64 * get_int64s (void) const
515  { DO_MUTABLE_METHOD (mxInt64 *, get_int64s ()); }
516 
517  mxUint8 * get_uint8s (void) const
518  { DO_MUTABLE_METHOD (mxUint8 *, get_uint8s ()); }
519 
520  mxUint16 * get_uint16s (void) const
521  { DO_MUTABLE_METHOD (mxUint16 *, get_uint16s ()); }
522 
523  mxUint32 * get_uint32s (void) const
524  { DO_MUTABLE_METHOD (mxUint32 *, get_uint32s ()); }
525 
526  mxUint64 * get_uint64s (void) const
527  { DO_MUTABLE_METHOD (mxUint64 *, get_uint64s ()); }
528 
529  mxComplexDouble * get_complex_doubles (void) const
530  { DO_MUTABLE_METHOD (mxComplexDouble *, get_complex_doubles ()); }
531 
532  mxComplexSingle * get_complex_singles (void) const
533  { DO_MUTABLE_METHOD (mxComplexSingle *, get_complex_singles ()); }
534 
535 #if 0
536  /* We don't have these yet. */
537  mxComplexInt8 * get_complex_int8s (void) const
538  { DO_MUTABLE_METHOD (mxComplexInt8 *, get_complex_int8s ()); }
539 
540  mxComplexInt16 * get_complex_int16s (void) const
541  { DO_MUTABLE_METHOD (mxComplexInt16 *, get_complex_int16s ()); }
542 
543  mxComplexInt32 * get_complex_int32s (void) const
544  { DO_MUTABLE_METHOD (mxComplexInt32 *, get_complex_int32s ()); }
545 
546  mxComplexInt64 * get_complex_int64s (void) const
547  { DO_MUTABLE_METHOD (mxComplexInt64 *, get_complex_int64s ()); }
548 
549  mxComplexUint8 * get_complex_uint8s (void) const
550  { DO_MUTABLE_METHOD (mxComplexUint8 *, get_complex_uint8s ()); }
551 
552  mxComplexUint16 * get_complex_uint16s (void) const
553  { DO_MUTABLE_METHOD (mxComplexUint16 *, get_complex_uint16s ()); }
554 
555  mxComplexUint32 * get_complex_uint32s (void) const
556  { DO_MUTABLE_METHOD (mxComplexUint32 *, get_complex_uint32s ()); }
557 
558  mxComplexUint64 * get_complex_uint64s (void) const
559  { DO_MUTABLE_METHOD (mxComplexUint64 *, get_complex_uint64s ()); }
560 #endif
561 
562  void * get_imag_data (void) const
563  { DO_MUTABLE_METHOD (void *, get_imag_data ()); }
564 
565  void set_data (void *pr) { DO_VOID_MUTABLE_METHOD (set_data (pr)); }
566 
567  int set_doubles (mxDouble *data)
568  { DO_MUTABLE_METHOD (int, set_doubles (data)); }
569 
570  int set_singles (mxSingle *data)
571  { DO_MUTABLE_METHOD (int, set_singles (data)); }
572 
573  int set_int8s (mxInt8 *data)
574  { DO_MUTABLE_METHOD (int, set_int8s (data)); }
575 
576  int set_int16s (mxInt16 *data)
577  { DO_MUTABLE_METHOD (int, set_int16s (data)); }
578 
579  int set_int32s (mxInt32 *data)
580  { DO_MUTABLE_METHOD (int, set_int32s (data)); }
581 
582  int set_int64s (mxInt64 *data)
583  { DO_MUTABLE_METHOD (int, set_int64s (data)); }
584 
585  int set_uint8s (mxUint8 *data)
586  { DO_MUTABLE_METHOD (int, set_uint8s (data)); }
587 
588  int set_uint16s (mxUint16 *data)
589  { DO_MUTABLE_METHOD (int, set_uint16s (data)); }
590 
591  int set_uint32s (mxUint32 *data)
592  { DO_MUTABLE_METHOD (int, set_uint32s (data)); }
593 
594  int set_uint64s (mxUint64 *data)
595  { DO_MUTABLE_METHOD (int, set_uint64s (data)); }
596 
597  int set_complex_doubles (mxComplexDouble *data)
598  { DO_MUTABLE_METHOD (int, set_complex_doubles (data)); }
599 
600  int set_complex_singles (mxComplexSingle *data)
601  { DO_MUTABLE_METHOD (int, set_complex_singles (data)); }
602 
603 #if 0
604  /* We don't have these yet. */
605  int set_complex_int8s (mxComplexInt8 *data)
606  { DO_MUTABLE_METHOD (int, set_complex_int8s (data)); }
607 
608  int set_complex_int16s (mxComplexInt16 *data)
609  { DO_MUTABLE_METHOD (int, set_complex_int16s (data)); }
610 
611  int set_complex_int32s (mxComplexInt32 *data)
612  { DO_MUTABLE_METHOD (int, set_complex_int32s (data)); }
613 
614  int set_complex_int64s (mxComplexInt64 *data)
615  { DO_MUTABLE_METHOD (int, set_complex_int64s (data)); }
616 
617  int set_complex_uint8s (mxComplexUint8 *data)
618  { DO_MUTABLE_METHOD (int, set_complex_uint8s (data)); }
619 
620  int set_complex_uint16s (mxComplexUint16 *data)
621  { DO_MUTABLE_METHOD (int, set_complex_uint16s (data)); }
622 
623  int set_complex_uint32s (mxComplexUint32 *data)
624  { DO_MUTABLE_METHOD (int, set_complex_uint32s (data)); }
625 
626  int set_complex_uint64s (mxComplexUint64 *data)
627  { DO_MUTABLE_METHOD (int, set_complex_uint64s (data)); }
628 #endif
629 
631 
632  mwIndex * get_ir (void) const { DO_MUTABLE_METHOD (mwIndex *, get_ir ()); }
633 
634  mwIndex * get_jc (void) const { DO_MUTABLE_METHOD (mwIndex *, get_jc ()); }
635 
636  mwSize get_nzmax (void) const { return m_rep->get_nzmax (); }
637 
638  void set_ir (mwIndex *ir) { DO_VOID_MUTABLE_METHOD (set_ir (ir)); }
639 
640  void set_jc (mwIndex *jc) { DO_VOID_MUTABLE_METHOD (set_jc (jc)); }
641 
642  void set_nzmax (mwSize nzmax) { DO_VOID_MUTABLE_METHOD (set_nzmax (nzmax)); }
643 
644  int add_field (const char *key) { DO_MUTABLE_METHOD (int, add_field (key)); }
645 
646  void remove_field (int key_num)
647  { DO_VOID_MUTABLE_METHOD (remove_field (key_num)); }
648 
649  mxArray * get_field_by_number (mwIndex index, int key_num) const
650  { DO_MUTABLE_METHOD (mxArray *, get_field_by_number (index, key_num)); }
651 
652  void set_field_by_number (mwIndex index, int key_num, mxArray *val)
653  { DO_VOID_MUTABLE_METHOD (set_field_by_number (index, key_num, val)); }
654 
655  int get_number_of_fields (void) const
656  { return m_rep->get_number_of_fields (); }
657 
658  const char * get_field_name_by_number (int key_num) const
659  { DO_MUTABLE_METHOD (const char *, get_field_name_by_number (key_num)); }
660 
661  int get_field_number (const char *key) const
662  { DO_MUTABLE_METHOD (int, get_field_number (key)); }
663 
664  int get_string (char *buf, mwSize buflen) const
665  { return m_rep->get_string (buf, buflen); }
666 
667  char * array_to_string (void) const { return m_rep->array_to_string (); }
668 
669  mwIndex calc_single_subscript (mwSize nsubs, mwIndex *subs) const
670  { return m_rep->calc_single_subscript (nsubs, subs); }
671 
672  std::size_t get_element_size (void) const
673  { return m_rep->get_element_size (); }
674 
675  bool mutation_needed (void) const { return m_rep->mutation_needed (); }
676 
677  mxArray * mutate (void) const { return m_rep->mutate (); }
678 
679  static OCTINTERP_API void * malloc (std::size_t n);
680 
681  static OCTINTERP_API void * calloc (std::size_t n, std::size_t t);
682 
683  static OCTINTERP_API void * alloc (bool init, std::size_t n, std::size_t t);
684 
685  static char * strsave (const char *str)
686  {
687  char *retval = nullptr;
688 
689  if (str)
690  {
691  mwSize sz = sizeof (mxChar) * (strlen (str) + 1);
692 
693  retval = static_cast<char *> (mxArray::malloc (sz));
694 
695  if (retval)
696  strcpy (retval, str);
697  }
698 
699  return retval;
700  }
701 
702  static OCTINTERP_API octave_value
703  as_octave_value (const mxArray *ptr, bool null_is_empty = true);
704 
705  OCTINTERP_API octave_value as_octave_value (void) const;
706 
707 private:
708 
709  mxArray (mxArray_base *r, const char *n)
710  : m_rep (r), m_name (mxArray::strsave (n)) { }
711 
712  static OCTINTERP_API mxArray_base *
713  create_rep (bool interleaved, const octave_value& ov);
714 
715  static OCTINTERP_API mxArray_base *
716  create_rep (bool interleaved, mxClassID id, mwSize ndims,
717  const mwSize *dims, mxComplexity flag, bool init);
718 
719  static OCTINTERP_API mxArray_base *
720  create_rep (bool interleaved, mxClassID id, const dim_vector& dv,
721  mxComplexity flag);
722 
723  static OCTINTERP_API mxArray_base *
724  create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n,
725  mxComplexity flag, bool init);
726 
727  static OCTINTERP_API mxArray_base *
728  create_rep (bool interleaved, mxClassID id, double val);
729 
730  static OCTINTERP_API mxArray_base *
731  create_rep (bool interleaved, mxClassID id, mxLogical val);
732 
733  static OCTINTERP_API mxArray_base *
734  create_rep (bool interleaved, const char *str);
735 
736  static OCTINTERP_API mxArray_base *
737  create_rep (bool interleaved, mwSize m, const char **str);
738 
739  static OCTINTERP_API mxArray_base *
740  create_rep (bool interleaved, mxClassID id, mwSize m, mwSize n,
741  mwSize nzmax, mxComplexity flag);
742 
743  OCTINTERP_API void maybe_mutate (void) const;
744 
745  //--------
746 
747  mutable mxArray_base *m_rep;
748 
749  char *m_name;
750 
751 };
752 
753 #undef DO_MUTABLE_METHOD
754 #undef DO_VOID_MUTABLE_METHOD
755 
756 #endif
757 #endif
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
virtual int set_int8s(mxInt8 *data)=0
virtual int set_complex_singles(mxComplexSingle *data)=0
OCTAVE_NORETURN void err_invalid_type(const char *op) const
Definition: mxarray.h:322
virtual int is_logical(void) const =0
virtual mxInt16 * get_int16s(void) const =0
virtual void set_n(mwSize n)=0
virtual void set_cell(mwIndex idx, mxArray *val)=0
virtual int is_int32(void) const =0
virtual int add_field(const char *key)=0
virtual mxUint8 * get_uint8s(void) const =0
virtual mxUint64 * get_uint64s(void) const =0
virtual void set_nzmax(mwSize nzmax)=0
virtual int set_uint16s(mxUint16 *data)=0
virtual int is_logical_scalar_true(void) const =0
virtual mxInt32 * get_int32s(void) const =0
virtual int is_uint16(void) const =0
virtual int set_uint64s(mxUint64 *data)=0
virtual int get_string(char *buf, mwSize buflen) const =0
virtual int is_double(void) const =0
virtual mxComplexSingle * get_complex_singles(void) const =0
virtual mwIndex calc_single_subscript(mwSize nsubs, mwIndex *subs) const =0
virtual mxArray * get_cell(mwIndex) const
Definition: mxarray.h:203
virtual int set_doubles(mxDouble *data)=0
virtual mxArray * as_mxArray(void) const
Definition: mxarray.h:99
virtual int set_int64s(mxInt64 *data)=0
virtual mxArray * mutate(void) const
Definition: mxarray.h:307
virtual int is_numeric(void) const =0
virtual int is_function_handle(void) const =0
virtual mwSize * get_dimensions(void) const =0
virtual void * get_imag_data(void) const =0
virtual void set_imag_data(void *pi)=0
virtual mxArray * get_field_by_number(mwIndex index, int key_num) const =0
virtual int set_int16s(mxInt16 *data)=0
virtual int set_singles(mxSingle *data)=0
virtual void set_m(mwSize m)=0
virtual void set_data(void *pr)=0
bool m_interleaved
Definition: mxarray.h:330
virtual mwSize get_number_of_elements(void) const =0
virtual int is_logical_scalar(void) const
Definition: mxarray.h:153
virtual int is_struct(void) const =0
virtual bool is_scalar(void) const =0
virtual int is_class(const char *name_arg) const
Definition: mxarray.h:109
virtual int is_single(void) const =0
virtual mxInt8 * get_int8s(void) const =0
virtual const char * get_class_name(void) const =0
std::size_t get_numeric_element_size(std::size_t size) const
Definition: mxarray.h:315
virtual int get_number_of_fields(void) const =0
virtual int is_sparse(void) const =0
virtual mwSize get_nzmax(void) const =0
virtual int is_int16(void) const =0
virtual void set_property(mwIndex, const char *, const mxArray *)
Definition: mxarray.h:197
virtual int set_complex_doubles(mxComplexDouble *data)=0
virtual int is_char(void) const =0
virtual char * array_to_string(void) const =0
virtual mxInt64 * get_int64s(void) const =0
virtual mxSingle * get_singles(void) const =0
virtual ~mxArray_base(void)=default
virtual bool mutation_needed(void) const
Definition: mxarray.h:305
virtual void * get_data(void) const =0
virtual mwSize get_m(void) const =0
virtual int is_uint32(void) const =0
virtual void set_jc(mwIndex *jc)=0
virtual mwIndex * get_ir(void) const =0
virtual bool is_octave_value(void) const
Definition: mxarray.h:103
virtual int is_uint64(void) const =0
virtual int is_int64(void) const =0
virtual int set_uint32s(mxUint32 *data)=0
virtual mwSize get_number_of_dimensions(void) const =0
virtual int is_int8(void) const =0
virtual int set_uint8s(mxUint8 *data)=0
virtual int is_complex(void) const =0
virtual int set_dimensions(mwSize *dims_arg, mwSize ndims_arg)=0
virtual mxComplexDouble * get_complex_doubles(void) const =0
virtual void set_class_name(const char *name_arg)=0
virtual mxDouble * get_doubles(void) const =0
virtual mwIndex * get_jc(void) const =0
mxArray_base(const mxArray_base &)=default
virtual double get_scalar(void) const =0
virtual mwSize get_n(void) const =0
virtual int is_uint8(void) const =0
virtual int isempty(void) const =0
virtual mxArray_base * dup(void) const =0
virtual void set_ir(mwIndex *ir)=0
virtual void remove_field(int key_num)=0
virtual std::size_t get_element_size(void) const =0
virtual mxArray * get_property(mwIndex, const char *) const
Definition: mxarray.h:192
virtual const char * get_field_name_by_number(int key_num) const =0
virtual mxUint32 * get_uint32s(void) const =0
virtual void set_field_by_number(mwIndex index, int key_num, mxArray *val)=0
virtual octave_value as_octave_value(void) const =0
virtual int get_field_number(const char *key) const =0
virtual mxUint16 * get_uint16s(void) const =0
virtual int set_int32s(mxInt32 *data)=0
virtual int iscell(void) const =0
virtual mxClassID get_class_id(void) const =0
mxArray & operator=(const mxArray &)=delete
mxInt64 * get_int64s(void) const
Definition: mxarray.h:514
int set_uint8s(mxUint8 *data)
Definition: mxarray.h:585
mxClassID get_class_id(void) const
Definition: mxarray.h:476
int is_int64(void) const
Definition: mxarray.h:422
int is_single(void) const
Definition: mxarray.h:430
int set_complex_singles(mxComplexSingle *data)
Definition: mxarray.h:600
OCTINTERP_API void maybe_mutate(void) const
Definition: mex.cc:3386
int set_uint32s(mxUint32 *data)
Definition: mxarray.h:591
void * get_imag_data(void) const
Definition: mxarray.h:562
OCTINTERP_API void set_name(const char *name)
Definition: mex.cc:3281
const char * get_class_name(void) const
Definition: mxarray.h:478
mxInt8 * get_int8s(void) const
Definition: mxarray.h:505
void set_n(mwSize n)
Definition: mxarray.h:460
char * m_name
Definition: mxarray.h:749
bool mutation_needed(void) const
Definition: mxarray.h:675
int is_logical_scalar_true(void) const
Definition: mxarray.h:446
int is_uint32(void) const
Definition: mxarray.h:438
int is_char(void) const
Definition: mxarray.h:408
bool is_octave_value(void) const
Definition: mxarray.h:404
OCTINTERP_API ~mxArray(void)
Definition: mex.cc:3273
void set_property(mwIndex idx, const char *pname, const mxArray *pval)
Definition: mxarray.h:483
int set_singles(mxSingle *data)
Definition: mxarray.h:570
int set_uint16s(mxUint16 *data)
Definition: mxarray.h:588
void set_m(mwSize m)
Definition: mxarray.h:458
static OCTINTERP_API void * alloc(bool init, std::size_t n, std::size_t t)
Definition: mex.cc:3747
mxArray * get_property(mwIndex idx, const char *pname) const
Definition: mxarray.h:480
int set_uint64s(mxUint64 *data)
Definition: mxarray.h:594
mxArray * dup(void) const
Definition: mxarray.h:380
void * get_data(void) const
Definition: mxarray.h:497
mwIndex * get_jc(void) const
Definition: mxarray.h:634
mwIndex calc_single_subscript(mwSize nsubs, mwIndex *subs) const
Definition: mxarray.h:669
int is_function_handle(void) const
Definition: mxarray.h:416
int set_dimensions(mwSize *dims_arg, mwSize ndims_arg)
Definition: mxarray.h:462
static char * strsave(const char *str)
Definition: mxarray.h:685
int isempty(void) const
Definition: mxarray.h:468
mwSize get_m(void) const
Definition: mxarray.h:449
void set_data(void *pr)
Definition: mxarray.h:565
int is_uint64(void) const
Definition: mxarray.h:440
int is_struct(void) const
Definition: mxarray.h:434
static OCTINTERP_API void * calloc(std::size_t n, std::size_t t)
Definition: mex.cc:3741
OCTINTERP_API mxArray(bool interleaved, const octave_value &ov)
Definition: mex.cc:3201
int set_complex_doubles(mxComplexDouble *data)
Definition: mxarray.h:597
int get_field_number(const char *key) const
Definition: mxarray.h:661
std::size_t get_element_size(void) const
Definition: mxarray.h:672
mxArray(mxArray_base *r, const char *n)
Definition: mxarray.h:709
mxInt32 * get_int32s(void) const
Definition: mxarray.h:511
int iscell(void) const
Definition: mxarray.h:406
mxArray * mutate(void) const
Definition: mxarray.h:677
mxArray * get_field_by_number(mwIndex index, int key_num) const
Definition: mxarray.h:649
int add_field(const char *key)
Definition: mxarray.h:644
int is_int8(void) const
Definition: mxarray.h:424
int get_number_of_fields(void) const
Definition: mxarray.h:655
int is_sparse(void) const
Definition: mxarray.h:432
mxDouble * get_doubles(void) const
Definition: mxarray.h:499
mxComplexDouble * get_complex_doubles(void) const
Definition: mxarray.h:529
mxUint16 * get_uint16s(void) const
Definition: mxarray.h:520
mxUint8 * get_uint8s(void) const
Definition: mxarray.h:517
int is_double(void) const
Definition: mxarray.h:414
mwSize get_nzmax(void) const
Definition: mxarray.h:636
mxArray_base * m_rep
Definition: mxarray.h:747
int is_uint8(void) const
Definition: mxarray.h:442
mwIndex * get_ir(void) const
Definition: mxarray.h:632
int set_int32s(mxInt32 *data)
Definition: mxarray.h:579
bool is_scalar(void) const
Definition: mxarray.h:470
int set_int64s(mxInt64 *data)
Definition: mxarray.h:582
int set_doubles(mxDouble *data)
Definition: mxarray.h:567
void set_nzmax(mwSize nzmax)
Definition: mxarray.h:642
int is_logical(void) const
Definition: mxarray.h:426
int is_int16(void) const
Definition: mxarray.h:418
double get_scalar(void) const
Definition: mxarray.h:495
void set_jc(mwIndex *jc)
Definition: mxarray.h:640
mwSize get_number_of_dimensions(void) const
Definition: mxarray.h:455
int set_int16s(mxInt16 *data)
Definition: mxarray.h:576
mxArray(const mxArray &)=delete
const char * get_name(void) const
Definition: mxarray.h:472
int is_numeric(void) const
Definition: mxarray.h:428
mwSize get_number_of_elements(void) const
Definition: mxarray.h:465
const char * get_field_name_by_number(int key_num) const
Definition: mxarray.h:658
int get_string(char *buf, mwSize buflen) const
Definition: mxarray.h:664
mxUint64 * get_uint64s(void) const
Definition: mxarray.h:526
int is_class(const char *name_arg) const
Definition: mxarray.h:410
int set_int8s(mxInt8 *data)
Definition: mxarray.h:573
mwSize get_n(void) const
Definition: mxarray.h:451
void set_class_name(const char *name_arg)
Definition: mxarray.h:486
int is_complex(void) const
Definition: mxarray.h:412
mxUint32 * get_uint32s(void) const
Definition: mxarray.h:523
int is_uint16(void) const
Definition: mxarray.h:436
void set_field_by_number(mwIndex index, int key_num, mxArray *val)
Definition: mxarray.h:652
void set_cell(mwIndex idx, mxArray *val)
Definition: mxarray.h:492
mxArray * get_cell(mwIndex idx) const
Definition: mxarray.h:489
static OCTINTERP_API mxArray_base * create_rep(bool interleaved, const octave_value &ov)
Definition: mex.cc:3304
void set_ir(mwIndex *ir)
Definition: mxarray.h:638
char * array_to_string(void) const
Definition: mxarray.h:667
int is_logical_scalar(void) const
Definition: mxarray.h:444
static OCTINTERP_API void * malloc(std::size_t n)
Definition: mex.cc:3735
OCTINTERP_API octave_value as_octave_value(void) const
Definition: mex.cc:3298
mwSize * get_dimensions(void) const
Definition: mxarray.h:453
void set_imag_data(void *pi)
Definition: mxarray.h:630
mxSingle * get_singles(void) const
Definition: mxarray.h:502
mxInt16 * get_int16s(void) const
Definition: mxarray.h:508
void remove_field(int key_num)
Definition: mxarray.h:646
int is_int32(void) const
Definition: mxarray.h:420
mxComplexSingle * get_complex_singles(void) const
Definition: mxarray.h:532
void error(const char *fmt,...)
Definition: error.cc:979
static const double pi
Definition: lo-specfun.cc:1944
T octave_idx_type m
Definition: mx-inlines.cc:773
octave_idx_type n
Definition: mx-inlines.cc:753
T * r
Definition: mx-inlines.cc:773
#define DO_VOID_MUTABLE_METHOD(METHOD_CALL)
Definition: mxarray.h:75
#define DO_MUTABLE_METHOD(RET_T, METHOD_CALL)
Definition: mxarray.h:64
T::size_type strlen(const typename T::value_type *str)
Definition: oct-string.cc:85
OCTAVE_API bool strcmp(const T &str_a, const T &str_b)
Octave string utility functions.