GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2013 John W. Eaton
4 Copyright (C) 2009-2010 VZLU Prague
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_ov_h)
25 #define octave_ov_h 1
26 
27 #include <cstdlib>
28 
29 #include <iosfwd>
30 #include <string>
31 #include <list>
32 
33 #include "Range.h"
34 #include "data-conv.h"
35 #include "idx-vector.h"
36 #include "mach-info.h"
37 #include "mx-base.h"
38 #include "oct-alloc.h"
39 #include "oct-time.h"
40 #include "str-vec.h"
41 
42 #include "oct-hdf5.h"
43 #include "oct-sort.h"
44 
45 class Cell;
46 class mxArray;
47 class octave_map;
48 class octave_scalar_map;
49 class Octave_map;
50 class octave_stream;
51 class octave_function;
53 class octave_fcn_handle;
54 class octave_fcn_inline;
55 class octave_value_list;
56 class octave_lvalue;
57 
58 #include "ov-base.h"
59 
60 // Constants.
61 
62 class octave_value;
63 
64 class
67 {
68 public:
69 
70  enum unary_op
71  {
72  op_not, // not
73  op_uplus, // uplus
74  op_uminus, // uminus
75  op_transpose, // transpose
76  op_hermitian, // ctranspose
81  };
82 
83  enum binary_op
84  {
85  op_add, // plus
86  op_sub, // minus
87  op_mul, // mtimes
88  op_div, // mrdivide
89  op_pow, // mpower
90  op_ldiv, // mldivide
93  op_lt, // lt
94  op_le, // le
95  op_eq, // eq
96  op_ge, // ge
97  op_gt, // gt
98  op_ne, // ne
99  op_el_mul, // times
100  op_el_div, // rdivide
101  op_el_pow, // power
102  op_el_ldiv, // ldivide
103  op_el_and, // and
104  op_el_or, // or
108  };
109 
111  {
112  // ** compound operations **
125  };
126 
128  {
146  };
147 
149 
151 
152  static std::string unary_op_as_string (unary_op);
153  static std::string unary_op_fcn_name (unary_op);
154 
155  static std::string binary_op_as_string (binary_op);
156  static std::string binary_op_fcn_name (binary_op);
157 
158  static std::string binary_op_fcn_name (compound_binary_op);
159 
160  static std::string assign_op_as_string (assign_op);
161 
162  static octave_value empty_conv (const std::string& type,
163  const octave_value& rhs = octave_value ());
164 
166 
168  {
169  static octave_base_value nil_rep;
170  rep = &nil_rep;
171  rep->count++;
172  }
173 
174  octave_value (short int i);
175  octave_value (unsigned short int i);
176  octave_value (int i);
177  octave_value (unsigned int i);
178  octave_value (long int i);
179  octave_value (unsigned long int i);
180 
181  // FIXME: these are kluges. They turn into doubles
182  // internally, which will break for very large values. We just use
183  // them to store things like 64-bit ino_t, etc, and hope that those
184  // values are never actually larger than can be represented exactly
185  // in a double.
186 
187 #if defined (HAVE_LONG_LONG_INT)
188  octave_value (long long int i);
189 #endif
190 #if defined (HAVE_UNSIGNED_LONG_LONG_INT)
191  octave_value (unsigned long long int i);
192 #endif
193 
195  octave_value (double d);
196  octave_value (float d);
197  octave_value (const Array<octave_value>& a, bool is_cs_list = false);
198  octave_value (const Cell& c, bool is_cs_list = false);
199  octave_value (const Matrix& m, const MatrixType& t = MatrixType ());
200  octave_value (const FloatMatrix& m, const MatrixType& t = MatrixType ());
201  octave_value (const NDArray& nda);
202  octave_value (const FloatNDArray& nda);
203  octave_value (const Array<double>& m);
204  octave_value (const Array<float>& m);
205  octave_value (const DiagMatrix& d);
210  octave_value (const FloatDiagMatrix& d);
211  octave_value (const RowVector& v);
212  octave_value (const FloatRowVector& v);
213  octave_value (const ColumnVector& v);
214  octave_value (const FloatColumnVector& v);
215  octave_value (const Complex& C);
216  octave_value (const FloatComplex& C);
217  octave_value (const ComplexMatrix& m, const MatrixType& t = MatrixType ());
219  const MatrixType& t = MatrixType ());
220  octave_value (const ComplexNDArray& cnda);
221  octave_value (const FloatComplexNDArray& cnda);
222  octave_value (const Array<Complex>& m);
226  octave_value (const ComplexRowVector& v);
230  octave_value (const PermMatrix& p);
231  octave_value (bool b);
232  octave_value (const boolMatrix& bm, const MatrixType& t = MatrixType ());
233  octave_value (const boolNDArray& bnda);
234  octave_value (const Array<bool>& bnda);
235  octave_value (char c, char type = '\'');
236  octave_value (const char *s, char type = '\'');
237  octave_value (const std::string& s, char type = '\'');
238  octave_value (const string_vector& s, char type = '\'');
239  octave_value (const charMatrix& chm, char type = '\'');
240  octave_value (const charNDArray& chnda, char type = '\'');
241  octave_value (const Array<char>& chnda, char type = '\'');
242  octave_value (const charMatrix& chm, bool is_string,
243  char type = '\'') GCC_ATTR_DEPRECATED;
244  octave_value (const charNDArray& chnda, bool is_string,
245  char type = '\'') GCC_ATTR_DEPRECATED;
246  octave_value (const Array<char>& chnda, bool is_string,
247  char type = '\'') GCC_ATTR_DEPRECATED;
248  octave_value (const SparseMatrix& m, const MatrixType& t = MatrixType ());
249  octave_value (const Sparse<double>& m, const MatrixType& t = MatrixType ());
251  const MatrixType& t = MatrixType ());
252  octave_value (const Sparse<Complex>& m, const MatrixType& t = MatrixType ());
253  octave_value (const SparseBoolMatrix& bm,
254  const MatrixType& t = MatrixType ());
255  octave_value (const Sparse<bool>& m, const MatrixType& t = MatrixType ());
256  octave_value (const octave_int8& i);
257  octave_value (const octave_int16& i);
258  octave_value (const octave_int32& i);
259  octave_value (const octave_int64& i);
260  octave_value (const octave_uint8& i);
261  octave_value (const octave_uint16& i);
262  octave_value (const octave_uint32& i);
263  octave_value (const octave_uint64& i);
264  octave_value (const int8NDArray& inda);
265  octave_value (const Array<octave_int8>& inda);
266  octave_value (const int16NDArray& inda);
267  octave_value (const Array<octave_int16>& inda);
268  octave_value (const int32NDArray& inda);
269  octave_value (const Array<octave_int32>& inda);
270  octave_value (const int64NDArray& inda);
271  octave_value (const Array<octave_int64>& inda);
272  octave_value (const uint8NDArray& inda);
273  octave_value (const Array<octave_uint8>& inda);
274  octave_value (const uint16NDArray& inda);
275  octave_value (const Array<octave_uint16>& inda);
276  octave_value (const uint32NDArray& inda);
277  octave_value (const Array<octave_uint32>& inda);
278  octave_value (const uint64NDArray& inda);
279  octave_value (const Array<octave_uint64>& inda);
280  octave_value (const Array<octave_idx_type>& inda,
281  bool zero_based = false, bool cache_index = false);
282  octave_value (const Array<std::string>& cellstr);
283  octave_value (const idx_vector& idx, bool lazy = true);
284  octave_value (double base, double limit, double inc);
285  octave_value (const Range& r);
286  octave_value (const octave_map& m);
287  octave_value (const octave_scalar_map& m);
288  octave_value (const Octave_map& m);
289  octave_value (const Octave_map& m, const std::string& id,
290  const std::list<std::string>& plist);
291  octave_value (const octave_value_list& m, bool = false);
293 
294  octave_value (octave_base_value *new_rep, bool borrow = false);
295  octave_value (octave_base_value *new_rep, int xcount) GCC_ATTR_DEPRECATED;
296 
297  // Copy constructor.
298 
300  {
301  rep = a.rep;
302  rep->count++;
303  }
304 
305  // This should only be called for derived types.
306 
307  octave_base_value *clone (void) const;
308 
310  { return rep->empty_clone (); }
311 
312  // Delete the representation of this constant if the count drops to
313  // zero.
314 
316  {
317  if (--rep->count == 0)
318  delete rep;
319  }
320 
321  void make_unique (void)
322  {
323  if (rep->count > 1)
324  {
326 
327  if (--rep->count == 0)
328  delete rep;
329 
330  rep = r;
331  }
332  }
333 
334  // This uniquifies the value if it is referenced by more than a certain
335  // number of shallow copies. This is useful for optimizations where we
336  // know a certain copy, typically within a cell array, to be obsolete.
337  void make_unique (int obsolete_copies)
338  {
339  if (rep->count > obsolete_copies + 1)
340  {
342 
343  if (--rep->count == 0)
344  delete rep;
345 
346  rep = r;
347  }
348  }
349 
350  // Simple assignment.
351 
353  {
354  if (rep != a.rep)
355  {
356  if (--rep->count == 0)
357  delete rep;
358 
359  rep = a.rep;
360  rep->count++;
361  }
362 
363  return *this;
364  }
365 
366  octave_idx_type get_count (void) const { return rep->count; }
367 
369  { return rep->numeric_conversion_function (); }
370 
372  { return rep->numeric_demotion_function (); }
373 
374  void maybe_mutate (void);
375 
376  octave_value squeeze (void) const
377  { return rep->squeeze (); }
378 
379  // The result of full().
381  { return rep->full_value (); }
382 
384  { return rep->try_narrowing_conversion (); }
385 
386  // Close to dims (), but can be overloaded for classes.
387  Matrix size (void)
388  { return rep->size (); }
389 
391  { return rep->numel (idx); }
392 
393  octave_value single_subsref (const std::string& type,
394  const octave_value_list& idx);
395 
396  octave_value subsref (const std::string& type,
397  const std::list<octave_value_list>& idx)
398  { return rep->subsref (type, idx); }
399 
400  octave_value subsref (const std::string& type,
401  const std::list<octave_value_list>& idx,
402  bool auto_add)
403  { return rep->subsref (type, idx, auto_add); }
404 
405  octave_value_list subsref (const std::string& type,
406  const std::list<octave_value_list>& idx,
407  int nargout);
408 
409  octave_value_list subsref (const std::string& type,
410  const std::list<octave_value_list>& idx,
411  int nargout,
412  const std::list<octave_lvalue> *lvalue_list);
413 
414  octave_value next_subsref (const std::string& type, const
415  std::list<octave_value_list>& idx,
416  size_t skip = 1);
417 
418  octave_value_list next_subsref (int nargout,
419  const std::string& type, const
420  std::list<octave_value_list>& idx,
421  size_t skip = 1);
422 
423  octave_value_list next_subsref (int nargout,
424  const std::string& type, const
425  std::list<octave_value_list>& idx,
426  const std::list<octave_lvalue> *lvalue_list,
427  size_t skip = 1);
428 
429  octave_value next_subsref (bool auto_add, const std::string& type, const
430  std::list<octave_value_list>& idx,
431  size_t skip = 1);
432 
434  bool resize_ok = false)
435  { return rep->do_index_op (idx, resize_ok); }
436 
438  do_multi_index_op (int nargout, const octave_value_list& idx);
439 
441  do_multi_index_op (int nargout, const octave_value_list& idx,
442  const std::list<octave_lvalue> *lvalue_list);
443 
444  octave_value subsasgn (const std::string& type,
445  const std::list<octave_value_list>& idx,
446  const octave_value& rhs);
447 
448  octave_value undef_subsasgn (const std::string& type,
449  const std::list<octave_value_list>& idx,
450  const octave_value& rhs);
451 
452  octave_value& assign (assign_op op, const std::string& type,
453  const std::list<octave_value_list>& idx,
454  const octave_value& rhs);
455 
456  octave_value& assign (assign_op, const octave_value& rhs);
457 
459  { return rep->index_vector (); }
460 
461  // Size.
462 
463  dim_vector dims (void) const
464  { return rep->dims (); }
465 
466  octave_idx_type rows (void) const { return rep->rows (); }
467 
468  octave_idx_type columns (void) const { return rep->columns (); }
469 
470  octave_idx_type length (void) const;
471 
472  int ndims (void) const { return rep->ndims (); }
473 
474  bool all_zero_dims (void) const { return dims ().all_zero (); }
475 
476  octave_idx_type numel (void) const
477  { return rep->numel (); }
478 
480  { return rep->capacity (); }
481 
482  size_t byte_size (void) const
483  { return rep->byte_size (); }
484 
485  octave_idx_type nnz (void) const { return rep->nnz (); }
486 
487  octave_idx_type nzmax (void) const { return rep->nzmax (); }
488 
489  octave_idx_type nfields (void) const { return rep->nfields (); }
490 
491  octave_value reshape (const dim_vector& dv) const
492  { return rep->reshape (dv); }
493 
494  octave_value permute (const Array<int>& vec, bool inv = false) const
495  { return rep->permute (vec, inv); }
496 
497  octave_value ipermute (const Array<int>& vec) const
498  { return rep->permute (vec, true); }
499 
500  octave_value resize (const dim_vector& dv, bool fill = false) const
501  { return rep->resize (dv, fill);}
502 
503  MatrixType matrix_type (void) const
504  { return rep->matrix_type (); }
505 
506  MatrixType matrix_type (const MatrixType& typ) const
507  { return rep->matrix_type (typ); }
508 
509  // Does this constant have a type? Both of these are provided since
510  // it is sometimes more natural to write is_undefined() instead of
511  // ! is_defined().
512 
513  bool is_defined (void) const
514  { return rep->is_defined (); }
515 
516  bool is_undefined (void) const
517  { return ! is_defined (); }
518 
519  bool is_empty (void) const
520  { return rep->is_empty (); }
521 
522  bool is_cell (void) const
523  { return rep->is_cell (); }
524 
525  bool is_cellstr (void) const
526  { return rep->is_cellstr (); }
527 
528  bool is_real_scalar (void) const
529  { return rep->is_real_scalar (); }
530 
531  bool is_real_matrix (void) const
532  { return rep->is_real_matrix (); }
533 
534  bool is_complex_scalar (void) const
535  { return rep->is_complex_scalar (); }
536 
537  bool is_complex_matrix (void) const
538  { return rep->is_complex_matrix (); }
539 
540  bool is_bool_scalar (void) const
541  { return rep->is_bool_scalar (); }
542 
543  bool is_bool_matrix (void) const
544  { return rep->is_bool_matrix (); }
545 
546  bool is_char_matrix (void) const
547  { return rep->is_char_matrix (); }
548 
549  bool is_diag_matrix (void) const
550  { return rep->is_diag_matrix (); }
551 
552  bool is_perm_matrix (void) const
553  { return rep->is_perm_matrix (); }
554 
555  bool is_string (void) const
556  { return rep->is_string (); }
557 
558  bool is_sq_string (void) const
559  { return rep->is_sq_string (); }
560 
561  bool is_dq_string (void) const
562  { return rep->is_string () && ! rep->is_sq_string (); }
563 
564  bool is_range (void) const
565  { return rep->is_range (); }
566 
567  bool is_map (void) const
568  { return rep->is_map (); }
569 
570  bool is_object (void) const
571  { return rep->is_object (); }
572 
573  bool is_java (void) const
574  { return rep->is_java (); }
575 
576  bool is_cs_list (void) const
577  { return rep->is_cs_list (); }
578 
579  bool is_magic_colon (void) const
580  { return rep->is_magic_colon (); }
581 
582  bool is_null_value (void) const
583  { return rep->is_null_value (); }
584 
585  // Are any or all of the elements in this constant nonzero?
586 
587  octave_value all (int dim = 0) const
588  { return rep->all (dim); }
589 
590  octave_value any (int dim = 0) const
591  { return rep->any (dim); }
592 
594  { return rep->builtin_type (); }
595 
596  // Floating point types.
597 
598  bool is_double_type (void) const
599  { return rep->is_double_type (); }
600 
601  bool is_single_type (void) const
602  { return rep->is_single_type (); }
603 
604  bool is_float_type (void) const
605  { return rep->is_float_type (); }
606 
607  // Integer types.
608 
609  bool is_int8_type (void) const
610  { return rep->is_int8_type (); }
611 
612  bool is_int16_type (void) const
613  { return rep->is_int16_type (); }
614 
615  bool is_int32_type (void) const
616  { return rep->is_int32_type (); }
617 
618  bool is_int64_type (void) const
619  { return rep->is_int64_type (); }
620 
621  bool is_uint8_type (void) const
622  { return rep->is_uint8_type (); }
623 
624  bool is_uint16_type (void) const
625  { return rep->is_uint16_type (); }
626 
627  bool is_uint32_type (void) const
628  { return rep->is_uint32_type (); }
629 
630  bool is_uint64_type (void) const
631  { return rep->is_uint64_type (); }
632 
633  // Other type stuff.
634 
635  bool is_bool_type (void) const
636  { return rep->is_bool_type (); }
637 
638  bool is_integer_type (void) const
639  { return rep->is_integer_type (); }
640 
641  bool is_real_type (void) const
642  { return rep->is_real_type (); }
643 
644  bool is_complex_type (void) const
645  { return rep->is_complex_type (); }
646 
647  bool is_scalar_type (void) const
648  { return rep->is_scalar_type (); }
649 
650  bool is_matrix_type (void) const
651  { return rep->is_matrix_type (); }
652 
653  bool is_numeric_type (void) const
654  { return rep->is_numeric_type (); }
655 
656  bool is_sparse_type (void) const
657  { return rep->is_sparse_type (); }
658 
659  // Does this constant correspond to a truth value?
660 
661  bool is_true (void) const
662  { return rep->is_true (); }
663 
664  // Do two constants match (in a switch statement)?
665 
666  bool is_equal (const octave_value&) const;
667 
668  // Are the dimensions of this constant zero by zero?
669 
670  bool is_zero_by_zero (void) const
671  { return (rows () == 0 && columns () == 0); }
672 
673  bool is_constant (void) const
674  { return rep->is_constant (); }
675 
676  bool is_function_handle (void) const
677  { return rep->is_function_handle (); }
678 
679  bool is_anonymous_function (void) const
680  { return rep->is_anonymous_function (); }
681 
682  bool is_inline_function (void) const
683  { return rep->is_inline_function (); }
684 
685  bool is_function (void) const
686  { return rep->is_function (); }
687 
688  bool is_user_script (void) const
689  { return rep->is_user_script (); }
690 
691  bool is_user_function (void) const
692  { return rep->is_user_function (); }
693 
694  bool is_user_code (void) const
695  { return rep->is_user_code (); }
696 
697  bool is_builtin_function (void) const
698  { return rep->is_builtin_function (); }
699 
700  bool is_dld_function (void) const
701  { return rep->is_dld_function (); }
702 
703  bool is_mex_function (void) const
704  { return rep->is_mex_function (); }
705 
707 
708  // Values.
709 
710  octave_value eval (void) { return *this; }
711 
712  short int
713  short_value (bool req_int = false, bool frc_str_conv = false) const
714  { return rep->short_value (req_int, frc_str_conv); }
715 
716  unsigned short int
717  ushort_value (bool req_int = false, bool frc_str_conv = false) const
718  { return rep->ushort_value (req_int, frc_str_conv); }
719 
720  int int_value (bool req_int = false, bool frc_str_conv = false) const
721  { return rep->int_value (req_int, frc_str_conv); }
722 
723  unsigned int
724  uint_value (bool req_int = false, bool frc_str_conv = false) const
725  { return rep->uint_value (req_int, frc_str_conv); }
726 
727  int nint_value (bool frc_str_conv = false) const
728  { return rep->nint_value (frc_str_conv); }
729 
730  long int
731  long_value (bool req_int = false, bool frc_str_conv = false) const
732  { return rep->long_value (req_int, frc_str_conv); }
733 
734  unsigned long int
735  ulong_value (bool req_int = false, bool frc_str_conv = false) const
736  { return rep->ulong_value (req_int, frc_str_conv); }
737 
738  int64_t
739  int64_value (bool req_int = false, bool frc_str_conv = false) const
740  { return rep->int64_value (req_int, frc_str_conv); }
741 
742  uint64_t
743  uint64_value (bool req_int = false, bool frc_str_conv = false) const
744  { return rep->uint64_value (req_int, frc_str_conv); }
745 
747  idx_type_value (bool req_int = false, bool frc_str_conv = false) const;
748 
749  double double_value (bool frc_str_conv = false) const
750  { return rep->double_value (frc_str_conv); }
751 
752  float float_value (bool frc_str_conv = false) const
753  { return rep->float_value (frc_str_conv); }
754 
755  double scalar_value (bool frc_str_conv = false) const
756  { return rep->scalar_value (frc_str_conv); }
757 
758  float float_scalar_value (bool frc_str_conv = false) const
759  { return rep->float_scalar_value (frc_str_conv); }
760 
761  Cell cell_value (void) const;
762 
763  Matrix matrix_value (bool frc_str_conv = false) const
764  { return rep->matrix_value (frc_str_conv); }
765 
766  FloatMatrix float_matrix_value (bool frc_str_conv = false) const
767  { return rep->float_matrix_value (frc_str_conv); }
768 
769  NDArray array_value (bool frc_str_conv = false) const
770  { return rep->array_value (frc_str_conv); }
771 
772  FloatNDArray float_array_value (bool frc_str_conv = false) const
773  { return rep->float_array_value (frc_str_conv); }
774 
775  Complex complex_value (bool frc_str_conv = false) const
776  { return rep->complex_value (frc_str_conv); }
777 
778  FloatComplex float_complex_value (bool frc_str_conv = false) const
779  { return rep->float_complex_value (frc_str_conv); }
780 
781  ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const
782  { return rep->complex_matrix_value (frc_str_conv); }
783 
785  float_complex_matrix_value (bool frc_str_conv = false) const
786  { return rep->float_complex_matrix_value (frc_str_conv); }
787 
788  ComplexNDArray complex_array_value (bool frc_str_conv = false) const
789  { return rep->complex_array_value (frc_str_conv); }
790 
792  float_complex_array_value (bool frc_str_conv = false) const
793  { return rep->float_complex_array_value (frc_str_conv); }
794 
795  bool bool_value (bool warn = false) const
796  { return rep->bool_value (warn); }
797 
798  boolMatrix bool_matrix_value (bool warn = false) const
799  { return rep->bool_matrix_value (warn); }
800 
801  boolNDArray bool_array_value (bool warn = false) const
802  { return rep->bool_array_value (warn); }
803 
804  charMatrix char_matrix_value (bool frc_str_conv = false) const
805  { return rep->char_matrix_value (frc_str_conv); }
806 
807  charNDArray char_array_value (bool frc_str_conv = false) const
808  { return rep->char_array_value (frc_str_conv); }
809 
810  SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const
811  { return rep->sparse_matrix_value (frc_str_conv); }
812 
814  sparse_complex_matrix_value (bool frc_str_conv = false) const
815  { return rep->sparse_complex_matrix_value (frc_str_conv); }
816 
817  SparseBoolMatrix sparse_bool_matrix_value (bool warn = false) const
818  { return rep->sparse_bool_matrix_value (warn); }
819 
820  DiagMatrix diag_matrix_value (bool force = false) const
821  { return rep->diag_matrix_value (force); }
822 
823  FloatDiagMatrix float_diag_matrix_value (bool force = false) const
824  { return rep->float_diag_matrix_value (force); }
825 
826  ComplexDiagMatrix complex_diag_matrix_value (bool force = false) const
827  { return rep->complex_diag_matrix_value (force); }
828 
830  float_complex_diag_matrix_value (bool force = false) const
831  { return rep->float_complex_diag_matrix_value (force); }
832 
834  { return rep->perm_matrix_value (); }
835 
837  { return rep->int8_scalar_value (); }
838 
840  { return rep->int16_scalar_value (); }
841 
843  { return rep->int32_scalar_value (); }
844 
846  { return rep->int64_scalar_value (); }
847 
849  { return rep->uint8_scalar_value (); }
850 
852  { return rep->uint16_scalar_value (); }
853 
855  { return rep->uint32_scalar_value (); }
856 
858  { return rep->uint64_scalar_value (); }
859 
861  { return rep->int8_array_value (); }
862 
864  { return rep->int16_array_value (); }
865 
867  { return rep->int32_array_value (); }
868 
870  { return rep->int64_array_value (); }
871 
873  { return rep->uint8_array_value (); }
874 
876  { return rep->uint16_array_value (); }
877 
879  { return rep->uint32_array_value (); }
880 
882  { return rep->uint64_array_value (); }
883 
884  string_vector all_strings (bool pad = false) const
885  { return rep->all_strings (pad); }
886 
887  std::string string_value (bool force = false) const
888  { return rep->string_value (force); }
889 
891  { return rep->cellstr_value (); }
892 
893  Range range_value (void) const
894  { return rep->range_value (); }
895 
896  octave_map map_value (void) const;
897 
898  octave_scalar_map scalar_map_value (void) const;
899 
900  string_vector map_keys (void) const
901  { return rep->map_keys (); }
902 
903  size_t nparents (void) const
904  { return rep->nparents (); }
905 
906  std::list<std::string> parent_class_name_list (void) const
907  { return rep->parent_class_name_list (); }
908 
910  { return rep->parent_class_names (); }
911 
913  find_parent_class (const std::string& parent_class_name)
914  { return rep->find_parent_class (parent_class_name); }
915 
916  octave_function *function_value (bool silent = false) const;
917 
918  octave_user_function *user_function_value (bool silent = false) const;
919 
920  octave_user_script *user_script_value (bool silent = false) const;
921 
922  octave_user_code *user_code_value (bool silent = false) const;
923 
924  octave_fcn_handle *fcn_handle_value (bool silent = false) const;
925 
926  octave_fcn_inline *fcn_inline_value (bool silent = false) const;
927 
928  octave_value_list list_value (void) const;
929 
930  ColumnVector column_vector_value (bool frc_str_conv = false,
931  bool frc_vec_conv = false) const;
932 
934  complex_column_vector_value (bool frc_str_conv = false,
935  bool frc_vec_conv = false) const;
936 
937  RowVector row_vector_value (bool frc_str_conv = false,
938  bool frc_vec_conv = false) const;
939 
941  complex_row_vector_value (bool frc_str_conv = false,
942  bool frc_vec_conv = false) const;
943 
944 
945  FloatColumnVector float_column_vector_value (bool frc_str_conv = false,
946  bool frc_vec_conv = false) const;
947 
949  float_complex_column_vector_value (bool frc_str_conv = false,
950  bool frc_vec_conv = false) const;
951 
952  FloatRowVector float_row_vector_value (bool frc_str_conv = false,
953  bool frc_vec_conv = false) const;
954 
956  float_complex_row_vector_value (bool frc_str_conv = false,
957  bool frc_vec_conv = false) const;
958 
959 
960 
961 
962  Array<int> int_vector_value (bool req_int = false,
963  bool frc_str_conv = false,
964  bool frc_vec_conv = false) const;
965 
967  octave_idx_type_vector_value (bool req_int = false,
968  bool frc_str_conv = false,
969  bool frc_vec_conv = false) const;
970 
971  Array<double> vector_value (bool frc_str_conv = false,
972  bool frc_vec_conv = false) const;
973 
974  Array<Complex> complex_vector_value (bool frc_str_conv = false,
975  bool frc_vec_conv = false) const;
976 
977  Array<float> float_vector_value (bool frc_str_conv = false,
978  bool frc_vec_conv = false) const;
979 
981  float_complex_vector_value (bool frc_str_conv = false,
982  bool frc_vec_conv = false) const;
983 
984  // Possibly economize a lazy-indexed value.
985 
986  void maybe_economize (void)
987  { rep->maybe_economize (); }
988 
989  // The following two hook conversions are called on any octave_value prior to
990  // storing it to a "permanent" location, like a named variable, a cell or a
991  // struct component, or a return value of a function.
992 
993  octave_value storable_value (void) const;
994 
995  // Ditto, but in place, i.e. equivalent to *this = this->storable_value (),
996  // but possibly more efficient.
997 
998  void make_storable_value (void);
999 
1000  // Conversions. These should probably be private. If a user of this
1001  // class wants a certain kind of constant, he should simply ask for
1002  // it, and we should convert it if possible.
1003 
1004  octave_value convert_to_str (bool pad = false, bool force = false,
1005  char type = '\'') const
1006  { return rep->convert_to_str (pad, force, type); }
1007 
1008  octave_value
1009  convert_to_str_internal (bool pad, bool force, char type) const
1010  { return rep->convert_to_str_internal (pad, force, type); }
1011 
1014 
1015  bool print_as_scalar (void) const
1016  { return rep->print_as_scalar (); }
1017 
1018  void print (std::ostream& os, bool pr_as_read_syntax = false) const
1019  { rep->print (os, pr_as_read_syntax); }
1020 
1021  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
1022  { rep->print_raw (os, pr_as_read_syntax); }
1023 
1024  bool print_name_tag (std::ostream& os, const std::string& name) const
1025  { return rep->print_name_tag (os, name); }
1026 
1027  void print_with_name (std::ostream& os, const std::string& name) const
1028  { rep->print_with_name (os, name, true); }
1029 
1030  void short_disp (std::ostream& os) const { rep->short_disp (os); }
1031 
1032  int type_id (void) const { return rep->type_id (); }
1033 
1034  std::string type_name (void) const { return rep->type_name (); }
1035 
1036  std::string class_name (void) const { return rep->class_name (); }
1037 
1038  // Unary and binary operations.
1039 
1041  const octave_value& a);
1042 
1044 
1045  octave_value& do_non_const_unary_op (unary_op op, const std::string& type,
1046  const std::list<octave_value_list>& idx);
1047 
1049  const octave_value& a,
1050  const octave_value& b);
1051 
1053  const octave_value& a,
1054  const octave_value& b);
1055 
1057  const octave_value& b,
1058  const Array<octave_idx_type>& ra_idx);
1059 
1060  const octave_base_value& get_rep (void) const { return *rep; }
1061 
1062  bool is_copy_of (const octave_value &val) const { return rep == val.rep; }
1063 
1064  void print_info (std::ostream& os,
1065  const std::string& prefix = std::string ()) const;
1066 
1067  bool save_ascii (std::ostream& os) { return rep->save_ascii (os); }
1068 
1069  bool load_ascii (std::istream& is) { return rep->load_ascii (is); }
1070 
1071  bool save_binary (std::ostream& os, bool& save_as_floats)
1072  { return rep->save_binary (os, save_as_floats); }
1073 
1074  bool load_binary (std::istream& is, bool swap,
1076  { return rep->load_binary (is, swap, fmt); }
1077 
1078 #if defined (HAVE_HDF5)
1079  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats)
1080  { return rep->save_hdf5 (loc_id, name, save_as_floats); }
1081 
1082  bool load_hdf5 (hid_t loc_id, const char *name)
1083  { return rep->load_hdf5 (loc_id, name); }
1084 #endif
1085 
1086  int write (octave_stream& os, int block_size,
1087  oct_data_conv::data_type output_type, int skip,
1088  oct_mach_info::float_format flt_fmt) const;
1089 
1090  octave_base_value *internal_rep (void) const { return rep; }
1091 
1092  // Unsafe. These functions exist to support the MEX interface.
1093  // You should not use them anywhere else.
1094  void *mex_get_data (void) const { return rep->mex_get_data (); }
1095 
1096  octave_idx_type *mex_get_ir (void) const { return rep->mex_get_ir (); }
1097 
1098  octave_idx_type *mex_get_jc (void) const { return rep->mex_get_jc (); }
1099 
1100  mxArray *as_mxArray (void) const { return rep->as_mxArray (); }
1101 
1103  { return rep->diag (k); }
1104 
1106  { return rep->diag (m, n); }
1107 
1109  { return rep->sort (dim, mode); }
1111  sortmode mode = ASCENDING) const
1112  { return rep->sort (sidx, dim, mode); }
1113 
1115  { return rep->is_sorted (mode); }
1116 
1118  { return rep->sort_rows_idx (mode); }
1119 
1121  { return rep->is_sorted_rows (mode); }
1122 
1123  void lock (void) { rep->lock (); }
1124 
1125  void unlock (void) { rep->unlock (); }
1126 
1127  bool islocked (void) const { return rep->islocked (); }
1128 
1129  void dump (std::ostream& os) const { rep->dump (os); }
1130 
1131 #define MAPPER_FORWARD(F) \
1132  octave_value F (void) const { return rep->map (octave_base_value::umap_ ## F); }
1133 
1179 
1180  // These functions are prefixed with X to avoid potential macro
1181  // conflicts.
1182 
1199 
1200 #undef MAPPER_FORWARD
1201 
1203  { return rep->map (umap); }
1204 
1205  // Extract the n-th element, aka val(n). Result is undefined if val is not an
1206  // array type or n is out of range. Never error.
1207  octave_value
1209  { return rep->fast_elem_extract (n); }
1210 
1211  // Assign the n-th element, aka val(n) = x. Returns false if val is not an
1212  // array type, x is not a matching scalar type, or n is out of range.
1213  // Never error.
1214  virtual bool
1216  {
1217  make_unique ();
1218  return rep->fast_elem_insert (n, x);
1219  }
1220 
1221 protected:
1222 
1223  // The real representation.
1225 
1226 private:
1227 
1229 
1231 
1232  // This declaration protects against constructing octave_value from
1233  // const octave_base_value* which actually silently calls octave_value (bool).
1234  octave_value (const octave_base_value *);
1235 
1237 };
1238 
1239 // Publish externally used friend functions.
1240 
1243 
1246  const octave_value& a, const octave_value& b);
1247 
1250  const octave_value& a, const octave_value& b);
1251 
1252 #define OV_UNOP_FN(name) \
1253  inline octave_value \
1254  name (const octave_value& a) \
1255  { \
1256  return do_unary_op (octave_value::name, a); \
1257  }
1258 
1259 #define OV_UNOP_OP(name, op) \
1260  inline octave_value \
1261  operator op (const octave_value& a) \
1262  { \
1263  return name (a); \
1264  }
1265 
1266 #define OV_UNOP_FN_OP(name, op) \
1267  OV_UNOP_FN (name) \
1268  OV_UNOP_OP (name, op)
1269 
1273 
1276 
1277 // No simple way to define these for prefix and suffix ops?
1278 //
1279 // incr
1280 // decr
1281 
1282 #define OV_BINOP_FN(name) \
1283  inline octave_value \
1284  name (const octave_value& a1, const octave_value& a2) \
1285  { \
1286  return do_binary_op (octave_value::name, a1, a2); \
1287  }
1288 
1289 #define OV_BINOP_OP(name, op) \
1290  inline octave_value \
1291  operator op (const octave_value& a1, const octave_value& a2) \
1292  { \
1293  return name (a1, a2); \
1294  }
1295 
1296 #define OV_BINOP_FN_OP(name, op) \
1297  OV_BINOP_FN (name) \
1298  OV_BINOP_OP (name, op)
1299 
1304 
1309 
1316 
1323 
1325 
1326 #define OV_COMP_BINOP_FN(name) \
1327  inline octave_value \
1328  name (const octave_value& a1, const octave_value& a2) \
1329  { \
1330  return do_binary_op (octave_value::name, a1, a2); \
1331  }
1332 
1337 
1338 extern OCTINTERP_API void install_types (void);
1339 
1340 // This will eventually go away, but for now it can be used to
1341 // simplify the transition to the new octave_value class hierarchy,
1342 // which uses octave_base_value instead of octave_value for the type
1343 // of octave_value::rep.
1344 #define OV_REP_TYPE octave_base_value
1345 
1346 // Templated value extractors.
1347 template<class Value>
1348 inline Value octave_value_extract (const octave_value&)
1349 { assert (false); }
1350 
1351 #define DEF_VALUE_EXTRACTOR(VALUE,MPREFIX) \
1352 template<> \
1353 inline VALUE octave_value_extract<VALUE> (const octave_value& v) \
1354  { return v.MPREFIX ## _value (); }
1355 
1357 DEF_VALUE_EXTRACTOR (float, float_scalar)
1361 
1370 
1371 
1377 
1387 
1393 
1397 DEF_VALUE_EXTRACTOR (FloatComplexColumnVector, float_complex_column_vector)
1398 
1402 DEF_VALUE_EXTRACTOR (FloatComplexRowVector, float_complex_row_vector)
1403 
1407 DEF_VALUE_EXTRACTOR (FloatComplexDiagMatrix, float_complex_diag_matrix)
1409 
1413 #undef DEF_VALUE_EXTRACTOR
1414 
1415 #define DEF_DUMMY_VALUE_EXTRACTOR(VALUE,DEFVAL) \
1416 template<> \
1417 inline VALUE octave_value_extract<VALUE> (const octave_value&) \
1418  { assert (false); return DEFVAL; }
1419 
1422 #undef DEF_DUMMY_VALUE_EXTRACTOR
1423 
1424 #endif