1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 #if ! defined (octave_ov_h)
27 #define octave_ov_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 #include <list>
36 #include <memory>
37 #include <map>
38 
39 #include "Range.h"
40 #include "data-conv.h"
41 #include "idx-vector.h"
42 #include "mach-info.h"
43 #include "mx-base.h"
44 #include "oct-sort.h"
45 #include "oct-time.h"
46 #include "str-vec.h"
47 
48 namespace octave
49 {
50   class stack_frame;
51   class type_info;
52 }
53 
54 class Cell;
55 class float_format;
56 class mxArray;
57 class octave_map;
58 class octave_scalar_map;
59 class octave_function;
60 class octave_user_function;
61 class octave_fcn_handle;
62 class octave_value_list;
63 
64 #include "oct-stream.h"
65 #include "ov-base.h"
66 
67 // Forward declarations of friend functions that have default arguments.
68 
69 OCTINTERP_API octave_value do_colon_op (const octave_value& base,
70                                         const octave_value& limit,
71                                         bool is_for_cmd_expr = false);
72 
73 OCTINTERP_API octave_value do_colon_op (const octave_value& base,
74                                         const octave_value& increment,
75                                         const octave_value& limit,
76                                         bool is_for_cmd_expr = false);
77 
78 class
79 OCTINTERP_API
80 octave_value
81 {
82 public:
83 
84   enum unary_op
85   {
86     op_not,            // not
87     op_uplus,          // uplus
88     op_uminus,         // uminus
89     op_transpose,      // transpose
90     op_hermitian,      // ctranspose
91     op_incr,
92     op_decr,
93     num_unary_ops,
94     unknown_unary_op
95   };
96 
97   enum binary_op
98   {
99     op_add,            // plus
100     op_sub,            // minus
101     op_mul,            // mtimes
102     op_div,            // mrdivide
103     op_pow,            // mpower
104     op_ldiv,           // mldivide
105     op_lt,             // lt
106     op_le,             // le
107     op_eq,             // eq
108     op_ge,             // ge
109     op_gt,             // gt
110     op_ne,             // ne
111     op_el_mul,         // times
112     op_el_div,         // rdivide
113     op_el_pow,         // power
114     op_el_ldiv,        // ldivide
115     op_el_and,         // and
116     op_el_or,          // or
117     op_struct_ref,
118     num_binary_ops,
119     unknown_binary_op
120   };
121 
122   enum compound_binary_op
123   {
124     // ** compound operations **
125     op_trans_mul,
126     op_mul_trans,
127     op_herm_mul,
128     op_mul_herm,
129     op_trans_ldiv,
130     op_herm_ldiv,
131     op_el_not_and,
132     op_el_not_or,
133     op_el_and_not,
134     op_el_or_not,
135     num_compound_binary_ops,
136     unknown_compound_binary_op
137   };
138 
139   enum assign_op
140   {
141     op_asn_eq,
142     op_add_eq,
143     op_sub_eq,
144     op_mul_eq,
145     op_div_eq,
146     op_ldiv_eq,
147     op_pow_eq,
148     op_el_mul_eq,
149     op_el_div_eq,
150     op_el_ldiv_eq,
151     op_el_pow_eq,
152     op_el_and_eq,
153     op_el_or_eq,
154     num_assign_ops,
155     unknown_assign_op
156   };
157 
158   static binary_op assign_op_to_binary_op (assign_op);
159 
160   static assign_op binary_op_to_assign_op (binary_op);
161 
162   static std::string unary_op_as_string (unary_op);
163   static std::string unary_op_fcn_name (unary_op);
164 
165   static std::string binary_op_as_string (binary_op);
166   static std::string binary_op_fcn_name (binary_op);
167 
168   static std::string binary_op_fcn_name (compound_binary_op);
169 
170   static std::string assign_op_as_string (assign_op);
171 
172   static octave_value empty_conv (const std::string& type,
173                                   const octave_value& rhs = octave_value ());
174 
175   enum magic_colon { magic_colon_t };
176 
octave_value(void)177   octave_value (void)
178     : rep (nil_rep ())
179   {
180     rep->count++;
181   }
182 
183   octave_value (short int i);
184   octave_value (unsigned short int i);
185   octave_value (int i);
186   octave_value (unsigned int i);
187   octave_value (long int i);
188   octave_value (unsigned long int i);
189 
190   // FIXME: These are kluges.  They turn into doubles internally, which will
191   // break for very large values.  We just use them to store things like
192   // 64-bit ino_t, etc, and hope that those values are never actually larger
193   // than can be represented exactly in a double.
194 
195 #if defined (OCTAVE_HAVE_LONG_LONG_INT)
196   octave_value (long long int i);
197 #endif
198 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT)
199   octave_value (unsigned long long int i);
200 #endif
201 
202   octave_value (octave::sys::time t);
203   octave_value (double d);
204   octave_value (float d);
205   octave_value (const Array<octave_value>& a, bool is_cs_list = false);
206   octave_value (const Cell& c, bool is_cs_list = false);
207   octave_value (const Matrix& m, const MatrixType& t = MatrixType ());
208   octave_value (const FloatMatrix& m, const MatrixType& t = MatrixType ());
209   octave_value (const NDArray& nda);
210   octave_value (const FloatNDArray& nda);
211   octave_value (const Array<double>& m);
212   octave_value (const Array<float>& m);
213   octave_value (const DiagMatrix& d);
214   octave_value (const DiagArray2<double>& d);
215   octave_value (const DiagArray2<float>& d);
216   octave_value (const DiagArray2<Complex>& d);
217   octave_value (const DiagArray2<FloatComplex>& d);
218   octave_value (const FloatDiagMatrix& d);
219   octave_value (const RowVector& v);
220   octave_value (const FloatRowVector& v);
221   octave_value (const ColumnVector& v);
222   octave_value (const FloatColumnVector& v);
223   octave_value (const Complex& C);
224   octave_value (const FloatComplex& C);
225   octave_value (const ComplexMatrix& m, const MatrixType& t = MatrixType ());
226   octave_value (const FloatComplexMatrix& m,
227                 const MatrixType& t = MatrixType ());
228   octave_value (const ComplexNDArray& cnda);
229   octave_value (const FloatComplexNDArray& cnda);
230   octave_value (const Array<Complex>& m);
231   octave_value (const Array<FloatComplex>& m);
232   octave_value (const ComplexDiagMatrix& d);
233   octave_value (const FloatComplexDiagMatrix& d);
234   octave_value (const ComplexRowVector& v);
235   octave_value (const FloatComplexRowVector& v);
236   octave_value (const ComplexColumnVector& v);
237   octave_value (const FloatComplexColumnVector& v);
238   octave_value (const PermMatrix& p);
239   octave_value (bool b);
240   octave_value (const boolMatrix& bm, const MatrixType& t = MatrixType ());
241   octave_value (const boolNDArray& bnda);
242   octave_value (const Array<bool>& bnda);
243   octave_value (char c, char type = '\'');
244   octave_value (const char *s, char type = '\'');
245   octave_value (const std::string& s, char type = '\'');
246   octave_value (const string_vector& s, char type = '\'');
247   octave_value (const charMatrix& chm,  char type = '\'');
248   octave_value (const charNDArray& chnda, char type = '\'');
249   octave_value (const Array<char>& chnda, char type = '\'');
250 
251   octave_value (const SparseMatrix& m, const MatrixType& t = MatrixType ());
252   octave_value (const Sparse<double>& m, const MatrixType& t = MatrixType ());
253   octave_value (const SparseComplexMatrix& m,
254                 const MatrixType& t = MatrixType ());
255   octave_value (const Sparse<Complex>& m, const MatrixType& t = MatrixType ());
256   octave_value (const SparseBoolMatrix& bm,
257                 const MatrixType& t = MatrixType ());
258   octave_value (const Sparse<bool>& m, const MatrixType& t = MatrixType ());
259   octave_value (const octave_int8& i);
260   octave_value (const octave_int16& i);
261   octave_value (const octave_int32& i);
262   octave_value (const octave_int64& i);
263   octave_value (const octave_uint8& i);
264   octave_value (const octave_uint16& i);
265   octave_value (const octave_uint32& i);
266   octave_value (const octave_uint64& i);
267   octave_value (const int8NDArray& inda);
268   octave_value (const Array<octave_int8>& inda);
269   octave_value (const int16NDArray& inda);
270   octave_value (const Array<octave_int16>& inda);
271   octave_value (const int32NDArray& inda);
272   octave_value (const Array<octave_int32>& inda);
273   octave_value (const int64NDArray& inda);
274   octave_value (const Array<octave_int64>& inda);
275   octave_value (const uint8NDArray& inda);
276   octave_value (const Array<octave_uint8>& inda);
277   octave_value (const uint16NDArray& inda);
278   octave_value (const Array<octave_uint16>& inda);
279   octave_value (const uint32NDArray& inda);
280   octave_value (const Array<octave_uint32>& inda);
281   octave_value (const uint64NDArray& inda);
282   octave_value (const Array<octave_uint64>& inda);
283   octave_value (const Array<octave_idx_type>& inda,
284                 bool zero_based = false, bool cache_index = false);
285   octave_value (const Array<std::string>& cellstr);
286   octave_value (const idx_vector& idx, bool lazy = true);
287   octave_value (double base, double limit, double inc);
288   octave_value (const Range& r, bool force_range = false);
289   octave_value (const octave_map& m);
290   octave_value (const octave_scalar_map& m);
291   octave_value (const std::map<std::string, octave_value>&);
292   octave_value (const octave_map& m, const std::string& id,
293                 const std::list<std::string>& plist);
294   octave_value (const octave_scalar_map& m, const std::string& id,
295                 const std::list<std::string>& plist);
296 
297   // This one is explicit because it can cause some trouble to
298   // accidentally create a cs-list when one was not intended.
299   explicit octave_value (const octave_value_list& m);
300 
301   octave_value (octave_value::magic_colon);
302 
303   octave_value (octave_base_value *new_rep, bool borrow = false);
304 
305   // Copy constructor.
306 
octave_value(const octave_value & a)307   octave_value (const octave_value& a)
308     : rep (a.rep)
309   {
310     rep->count++;
311   }
312 
octave_value(octave_value && a)313   octave_value (octave_value&& a)
314     : rep (a.rep)
315   {
316     a.rep = nullptr;
317   }
318 
319   // This should only be called for derived types.
320 
321   octave_base_value * clone (void) const;
322 
empty_clone(void)323   octave_base_value * empty_clone (void) const
324   { return rep->empty_clone (); }
325 
326   // Delete the representation of this constant if the count drops to zero.
327 
~octave_value(void)328   ~octave_value (void)
329   {
330     // Because we define a move constructor and a move assignment
331     // operator, rep may be a nullptr here.  We should only need to
332     // protect the move assignment operator in a similar way.
333 
334     if (rep && --rep->count == 0 && rep != nil_rep ())
335       delete rep;
336   }
337 
make_unique(void)338   void make_unique (void)
339   {
340     if (rep->count > 1)
341       {
342         octave_base_value *r = rep->unique_clone ();
343 
344         if (--rep->count == 0 && rep != nil_rep ())
345           delete rep;
346 
347         rep = r;
348       }
349   }
350 
351   // This uniquifies the value if it is referenced by more than a certain
352   // number of shallow copies.  This is useful for optimizations where we
353   // know a certain copy, typically within a cell array, to be obsolete.
make_unique(int obsolete_copies)354   void make_unique (int obsolete_copies)
355   {
356     if (rep->count > obsolete_copies + 1)
357       {
358         octave_base_value *r = rep->unique_clone ();
359 
360         if (--rep->count == 0 && rep != nil_rep ())
361           delete rep;
362 
363         rep = r;
364       }
365   }
366 
367   // Convert any nested function handles in this object to use weak
368   // references to their enclosing stack frame context.  Used to break
369   // shared_ptr reference cycles for handles to nested functions
370   // (closures).
371   void break_closure_cycles (const std::shared_ptr<octave::stack_frame>&);
372 
373   // Simple assignment.
374 
375   octave_value& operator = (const octave_value& a)
376   {
377     if (rep != a.rep)
378       {
379         if (--rep->count == 0 && rep != nil_rep ())
380           delete rep;
381 
382         rep = a.rep;
383         rep->count++;
384       }
385 
386     return *this;
387   }
388 
389   octave_value& operator = (octave_value&& a)
390   {
391     // Because we define a move constructor and a move assignment
392     // operator, rep may be a nullptr here.  We should only need to
393     // protect the destructor in a similar way.
394 
395     if (this != &a)
396       {
397         if (rep && --rep->count == 0 && rep != nil_rep ())
398           delete rep;
399 
400         rep = a.rep;
401         a.rep = nullptr;
402       }
403 
404     return *this;
405   }
406 
get_count(void)407   octave_idx_type get_count (void) const { return rep->count; }
408 
numeric_conversion_function(void)409   octave_base_value::type_conv_info numeric_conversion_function (void) const
410   { return rep->numeric_conversion_function (); }
411 
numeric_demotion_function(void)412   octave_base_value::type_conv_info numeric_demotion_function (void) const
413   { return rep->numeric_demotion_function (); }
414 
415   void maybe_mutate (void);
416 
squeeze(void)417   octave_value squeeze (void) const
418   { return rep->squeeze (); }
419 
420   // The result of full().
full_value(void)421   octave_value full_value (void) const
422   { return rep->full_value (); }
423 
424   // Type conversions.
425 
as_double(void)426   octave_value as_double (void) const { return rep->as_double (); }
as_single(void)427   octave_value as_single (void) const { return rep->as_single (); }
428 
as_int8(void)429   octave_value as_int8 (void) const { return rep->as_int8 (); }
as_int16(void)430   octave_value as_int16 (void) const { return rep->as_int16 (); }
as_int32(void)431   octave_value as_int32 (void) const { return rep->as_int32 (); }
as_int64(void)432   octave_value as_int64 (void) const { return rep->as_int64 (); }
433 
as_uint8(void)434   octave_value as_uint8 (void) const { return rep->as_uint8 (); }
as_uint16(void)435   octave_value as_uint16 (void) const { return rep->as_uint16 (); }
as_uint32(void)436   octave_value as_uint32 (void) const { return rep->as_uint32 (); }
as_uint64(void)437   octave_value as_uint64 (void) const { return rep->as_uint64 (); }
438 
try_narrowing_conversion(void)439   octave_base_value * try_narrowing_conversion (void)
440   { return rep->try_narrowing_conversion (); }
441 
442   // Close to dims (), but can be overloaded for classes.
size(void)443   Matrix size (void)
444   { return rep->size (); }
445 
446   // FIXME: should this function be deprecated and removed?  It supports
447   // an undocumented feature of Matlab.
xnumel(const octave_value_list & idx)448   octave_idx_type xnumel (const octave_value_list& idx)
449   { return rep->xnumel (idx); }
450 
451   // FIXME: Do we really need all these different versions of subsref
452   // and related functions?
453 
454   octave_value single_subsref (const std::string& type,
455                                const octave_value_list& idx);
456 
subsref(const std::string & type,const std::list<octave_value_list> & idx)457   octave_value subsref (const std::string& type,
458                         const std::list<octave_value_list>& idx)
459   { return rep->subsref (type, idx); }
460 
subsref(const std::string & type,const std::list<octave_value_list> & idx,bool auto_add)461   octave_value subsref (const std::string& type,
462                         const std::list<octave_value_list>& idx,
463                         bool auto_add)
464   { return rep->subsref (type, idx, auto_add); }
465 
466   octave_value_list subsref (const std::string& type,
467                              const std::list<octave_value_list>& idx,
468                              int nargout);
469 
470   octave_value next_subsref (const std::string& type, const
471                              std::list<octave_value_list>& idx,
472                              std::size_t skip = 1);
473 
474   octave_value_list next_subsref (int nargout,
475                                   const std::string& type, const
476                                   std::list<octave_value_list>& idx,
477                                   std::size_t skip = 1);
478 
479   octave_value next_subsref (bool auto_add, const std::string& type, const
480                              std::list<octave_value_list>& idx,
481                              std::size_t skip = 1);
482 
483   octave_value do_index_op (const octave_value_list& idx,
484                             bool resize_ok = false)
485   { return rep->do_index_op (idx, resize_ok); }
486 
487   octave_value subsasgn (const std::string& type,
488                          const std::list<octave_value_list>& idx,
489                          const octave_value& rhs);
490 
491   octave_value undef_subsasgn (const std::string& type,
492                                const std::list<octave_value_list>& idx,
493                                const octave_value& rhs);
494 
495   octave_value& assign (assign_op op, const std::string& type,
496                         const std::list<octave_value_list>& idx,
497                         const octave_value& rhs);
498 
499   octave_value& assign (assign_op, const octave_value& rhs);
500 
501   idx_vector index_vector (bool require_integers = false) const
502   {
503     return rep->index_vector (require_integers);
504   }
505 
506   // Size.
507 
dims(void)508   dim_vector dims (void) const { return rep->dims (); }
509 
510   std::string get_dims_str (void) const;
511 
rows(void)512   octave_idx_type rows (void) const { return rep->rows (); }
513 
columns(void)514   octave_idx_type columns (void) const { return rep->columns (); }
515 
516   octave_idx_type length (void) const;
517 
ndims(void)518   int ndims (void) const { return rep->ndims (); }
519 
all_zero_dims(void)520   bool all_zero_dims (void) const { return dims ().all_zero (); }
521 
522   // Are the dimensions of this constant zero by zero?
is_zero_by_zero(void)523   bool is_zero_by_zero (void) const
524   { return (ndims () == 2 && rows () == 0 && columns () == 0); }
525 
numel(void)526   octave_idx_type numel (void) const
527   { return rep->numel (); }
528 
byte_size(void)529   std::size_t byte_size (void) const
530   { return rep->byte_size (); }
531 
nnz(void)532   octave_idx_type nnz (void) const { return rep->nnz (); }
533 
nzmax(void)534   octave_idx_type nzmax (void) const { return rep->nzmax (); }
535 
nfields(void)536   octave_idx_type nfields (void) const { return rep->nfields (); }
537 
reshape(const dim_vector & dv)538   octave_value reshape (const dim_vector& dv) const
539   { return rep->reshape (dv); }
540 
541   octave_value permute (const Array<int>& vec, bool inv = false) const
542   { return rep->permute (vec, inv); }
543 
ipermute(const Array<int> & vec)544   octave_value ipermute (const Array<int>& vec) const
545   { return rep->permute (vec, true); }
546 
547   octave_value resize (const dim_vector& dv, bool fill = false) const
548   { return rep->resize (dv, fill);}
549 
matrix_type(void)550   MatrixType matrix_type (void) const
551   { return rep->matrix_type (); }
552 
matrix_type(const MatrixType & typ)553   MatrixType matrix_type (const MatrixType& typ) const
554   { return rep->matrix_type (typ); }
555 
556   // Does this constant have a type?  Both of these are provided since it is
557   // sometimes more natural to write is_undefined() instead of ! is_defined().
558 
is_defined(void)559   bool is_defined (void) const
560   { return rep->is_defined (); }
561 
is_undefined(void)562   bool is_undefined (void) const
563   { return ! is_defined (); }
564 
isempty(void)565   bool isempty (void) const
566   { return rep->isempty (); }
567 
iscell(void)568   bool iscell (void) const
569   { return rep->iscell (); }
570 
iscellstr(void)571   bool iscellstr (void) const
572   { return rep->iscellstr (); }
573 
is_real_scalar(void)574   bool is_real_scalar (void) const
575   { return rep->is_real_scalar (); }
576 
is_real_matrix(void)577   bool is_real_matrix (void) const
578   { return rep->is_real_matrix (); }
579 
is_complex_scalar(void)580   bool is_complex_scalar (void) const
581   { return rep->is_complex_scalar (); }
582 
is_complex_matrix(void)583   bool is_complex_matrix (void) const
584   { return rep->is_complex_matrix (); }
585 
is_bool_scalar(void)586   bool is_bool_scalar (void) const
587   { return rep->is_bool_scalar (); }
588 
is_bool_matrix(void)589   bool is_bool_matrix (void) const
590   { return rep->is_bool_matrix (); }
591 
is_char_matrix(void)592   bool is_char_matrix (void) const
593   { return rep->is_char_matrix (); }
594 
is_diag_matrix(void)595   bool is_diag_matrix (void) const
596   { return rep->is_diag_matrix (); }
597 
is_perm_matrix(void)598   bool is_perm_matrix (void) const
599   { return rep->is_perm_matrix (); }
600 
is_string(void)601   bool is_string (void) const
602   { return rep->is_string (); }
603 
is_sq_string(void)604   bool is_sq_string (void) const
605   { return rep->is_sq_string (); }
606 
is_dq_string(void)607   bool is_dq_string (void) const
608   { return rep->is_string () && ! rep->is_sq_string (); }
609 
is_range(void)610   bool is_range (void) const
611   { return rep->is_range (); }
612 
isstruct(void)613   bool isstruct (void) const
614   { return rep->isstruct (); }
615 
is_classdef_meta(void)616   bool is_classdef_meta (void) const
617   { return rep->is_classdef_meta (); }
618 
is_classdef_object(void)619   bool is_classdef_object (void) const
620   { return rep->is_classdef_object (); }
621 
is_classdef_superclass_ref(void)622   bool is_classdef_superclass_ref (void) const
623   { return rep->is_classdef_superclass_ref (); }
624 
is_package(void)625   bool is_package (void) const
626   { return rep->is_package (); }
627 
isobject(void)628   bool isobject (void) const
629   { return rep->isobject (); }
630 
isjava(void)631   bool isjava (void) const
632   { return rep->isjava (); }
633 
is_cs_list(void)634   bool is_cs_list (void) const
635   { return rep->is_cs_list (); }
636 
is_magic_colon(void)637   bool is_magic_colon (void) const
638   { return rep->is_magic_colon (); }
639 
isnull(void)640   bool isnull (void) const
641   { return rep->isnull (); }
642 
643   // Are any or all of the elements in this constant nonzero?
644 
645   octave_value all (int dim = 0) const
646   { return rep->all (dim); }
647 
648   octave_value any (int dim = 0) const
649   { return rep->any (dim); }
650 
builtin_type(void)651   builtin_type_t builtin_type (void) const
652   { return rep->builtin_type (); }
653 
654   // Floating point types.
655 
is_double_type(void)656   bool is_double_type (void) const
657   { return rep->is_double_type (); }
658 
is_single_type(void)659   bool is_single_type (void) const
660   { return rep->is_single_type (); }
661 
isfloat(void)662   bool isfloat (void) const
663   { return rep->isfloat (); }
664 
665   // Integer types.
666 
is_int8_type(void)667   bool is_int8_type (void) const
668   { return rep->is_int8_type (); }
669 
is_int16_type(void)670   bool is_int16_type (void) const
671   { return rep->is_int16_type (); }
672 
is_int32_type(void)673   bool is_int32_type (void) const
674   { return rep->is_int32_type (); }
675 
is_int64_type(void)676   bool is_int64_type (void) const
677   { return rep->is_int64_type (); }
678 
is_uint8_type(void)679   bool is_uint8_type (void) const
680   { return rep->is_uint8_type (); }
681 
is_uint16_type(void)682   bool is_uint16_type (void) const
683   { return rep->is_uint16_type (); }
684 
is_uint32_type(void)685   bool is_uint32_type (void) const
686   { return rep->is_uint32_type (); }
687 
is_uint64_type(void)688   bool is_uint64_type (void) const
689   { return rep->is_uint64_type (); }
690 
isinteger(void)691   bool isinteger (void) const
692   { return rep->isinteger (); }
693 
694   // Other type stuff.
695 
islogical(void)696   bool islogical (void) const
697   { return rep->islogical (); }
698 
isreal(void)699   bool isreal (void) const
700   { return rep->isreal (); }
701 
iscomplex(void)702   bool iscomplex (void) const
703   { return rep->iscomplex (); }
704 
is_scalar_type(void)705   bool is_scalar_type (void) const
706   { return rep->is_scalar_type (); }
707 
is_matrix_type(void)708   bool is_matrix_type (void) const
709   { return rep->is_matrix_type (); }
710 
isnumeric(void)711   bool isnumeric (void) const
712   { return rep->isnumeric (); }
713 
issparse(void)714   bool issparse (void) const
715   { return rep->issparse (); }
716 
717   // Does this constant correspond to a truth value?
718 
is_true(void)719   bool is_true (void) const
720   { return rep->is_true (); }
721 
722   // Do two constants match (in a switch statement)?
723 
724   bool is_equal (const octave_value&) const;
725 
is_constant(void)726   bool is_constant (void) const
727   { return rep->is_constant (); }
728 
is_function_handle(void)729   bool is_function_handle (void) const
730   { return rep->is_function_handle (); }
731 
is_anonymous_function(void)732   bool is_anonymous_function (void) const
733   { return rep->is_anonymous_function (); }
734 
is_inline_function(void)735   bool is_inline_function (void) const
736   { return rep->is_inline_function (); }
737 
is_function(void)738   bool is_function (void) const
739   { return rep->is_function (); }
740 
is_user_script(void)741   bool is_user_script (void) const
742   { return rep->is_user_script (); }
743 
is_user_function(void)744   bool is_user_function (void) const
745   { return rep->is_user_function (); }
746 
is_user_code(void)747   bool is_user_code (void) const
748   { return rep->is_user_code (); }
749 
is_builtin_function(void)750   bool is_builtin_function (void) const
751   { return rep->is_builtin_function (); }
752 
is_dld_function(void)753   bool is_dld_function (void) const
754   { return rep->is_dld_function (); }
755 
is_mex_function(void)756   bool is_mex_function (void) const
757   { return rep->is_mex_function (); }
758 
erase_subfunctions(void)759   void erase_subfunctions (void) { rep->erase_subfunctions (); }
760 
761   // Values.
762 
eval(void)763   octave_value eval (void) { return *this; }
764 
765   short int
766   short_value (bool req_int = false, bool frc_str_conv = false) const
767   { return rep->short_value (req_int, frc_str_conv); }
768 
769   unsigned short int
770   ushort_value (bool req_int = false, bool frc_str_conv = false) const
771   { return rep->ushort_value (req_int, frc_str_conv); }
772 
773   int int_value (bool req_int = false, bool frc_str_conv = false) const
774   { return rep->int_value (req_int, frc_str_conv); }
775 
776   unsigned int
777   uint_value (bool req_int = false, bool frc_str_conv = false) const
778   { return rep->uint_value (req_int, frc_str_conv); }
779 
780   int nint_value (bool frc_str_conv = false) const
781   { return rep->nint_value (frc_str_conv); }
782 
783   long int
784   long_value (bool req_int = false, bool frc_str_conv = false) const
785   { return rep->long_value (req_int, frc_str_conv); }
786 
787   unsigned long int
788   ulong_value (bool req_int = false, bool frc_str_conv = false) const
789   { return rep->ulong_value (req_int, frc_str_conv); }
790 
791   int64_t
792   int64_value (bool req_int = false, bool frc_str_conv = false) const
793   { return rep->int64_value (req_int, frc_str_conv); }
794 
795   uint64_t
796   uint64_value (bool req_int = false, bool frc_str_conv = false) const
797   { return rep->uint64_value (req_int, frc_str_conv); }
798 
799   octave_idx_type
800   idx_type_value (bool req_int = false, bool frc_str_conv = false) const;
801 
802   double double_value (bool frc_str_conv = false) const
803   { return rep->double_value (frc_str_conv); }
804 
805   float float_value (bool frc_str_conv = false) const
806   { return rep->float_value (frc_str_conv); }
807 
808   double scalar_value (bool frc_str_conv = false) const
809   { return rep->scalar_value (frc_str_conv); }
810 
811   float float_scalar_value (bool frc_str_conv = false) const
812   { return rep->float_scalar_value (frc_str_conv); }
813 
814   Matrix matrix_value (bool frc_str_conv = false) const
815   { return rep->matrix_value (frc_str_conv); }
816 
817   FloatMatrix float_matrix_value (bool frc_str_conv = false) const
818   { return rep->float_matrix_value (frc_str_conv); }
819 
820   NDArray array_value (bool frc_str_conv = false) const
821   { return rep->array_value (frc_str_conv); }
822 
823   FloatNDArray float_array_value (bool frc_str_conv = false) const
824   { return rep->float_array_value (frc_str_conv); }
825 
826   Complex complex_value (bool frc_str_conv = false) const
827   { return rep->complex_value (frc_str_conv); }
828 
829   FloatComplex float_complex_value (bool frc_str_conv = false) const
830   { return rep->float_complex_value (frc_str_conv); }
831 
832   ComplexMatrix complex_matrix_value (bool frc_str_conv = false) const
833   { return rep->complex_matrix_value (frc_str_conv); }
834 
835   FloatComplexMatrix
836   float_complex_matrix_value (bool frc_str_conv = false) const
837   { return rep->float_complex_matrix_value (frc_str_conv); }
838 
839   ComplexNDArray complex_array_value (bool frc_str_conv = false) const
840   { return rep->complex_array_value (frc_str_conv); }
841 
842   FloatComplexNDArray
843   float_complex_array_value (bool frc_str_conv = false) const
844   { return rep->float_complex_array_value (frc_str_conv); }
845 
846   bool bool_value (bool warn = false) const
847   { return rep->bool_value (warn); }
848 
849   boolMatrix bool_matrix_value (bool warn = false) const
850   { return rep->bool_matrix_value (warn); }
851 
852   boolNDArray bool_array_value (bool warn = false) const
853   { return rep->bool_array_value (warn); }
854 
855   charMatrix char_matrix_value (bool frc_str_conv = false) const
856   { return rep->char_matrix_value (frc_str_conv); }
857 
858   charNDArray char_array_value (bool frc_str_conv = false) const
859   { return rep->char_array_value (frc_str_conv); }
860 
861   SparseMatrix sparse_matrix_value (bool frc_str_conv = false) const
862   { return rep->sparse_matrix_value (frc_str_conv); }
863 
864   SparseComplexMatrix
865   sparse_complex_matrix_value (bool frc_str_conv = false) const
866   { return rep->sparse_complex_matrix_value (frc_str_conv); }
867 
868   SparseBoolMatrix sparse_bool_matrix_value (bool warn = false) const
869   { return rep->sparse_bool_matrix_value (warn); }
870 
871   DiagMatrix diag_matrix_value (bool force = false) const
872   { return rep->diag_matrix_value (force); }
873 
874   FloatDiagMatrix float_diag_matrix_value (bool force = false) const
875   { return rep->float_diag_matrix_value (force); }
876 
877   ComplexDiagMatrix complex_diag_matrix_value (bool force = false) const
878   { return rep->complex_diag_matrix_value (force); }
879 
880   FloatComplexDiagMatrix
881   float_complex_diag_matrix_value (bool force = false) const
882   { return rep->float_complex_diag_matrix_value (force); }
883 
perm_matrix_value(void)884   PermMatrix perm_matrix_value (void) const
885   { return rep->perm_matrix_value (); }
886 
int8_scalar_value(void)887   octave_int8 int8_scalar_value (void) const
888   { return rep->int8_scalar_value (); }
889 
int16_scalar_value(void)890   octave_int16 int16_scalar_value (void) const
891   { return rep->int16_scalar_value (); }
892 
int32_scalar_value(void)893   octave_int32 int32_scalar_value (void) const
894   { return rep->int32_scalar_value (); }
895 
int64_scalar_value(void)896   octave_int64 int64_scalar_value (void) const
897   { return rep->int64_scalar_value (); }
898 
uint8_scalar_value(void)899   octave_uint8 uint8_scalar_value (void) const
900   { return rep->uint8_scalar_value (); }
901 
uint16_scalar_value(void)902   octave_uint16 uint16_scalar_value (void) const
903   { return rep->uint16_scalar_value (); }
904 
uint32_scalar_value(void)905   octave_uint32 uint32_scalar_value (void) const
906   { return rep->uint32_scalar_value (); }
907 
uint64_scalar_value(void)908   octave_uint64 uint64_scalar_value (void) const
909   { return rep->uint64_scalar_value (); }
910 
int8_array_value(void)911   int8NDArray int8_array_value (void) const
912   { return rep->int8_array_value (); }
913 
int16_array_value(void)914   int16NDArray int16_array_value (void) const
915   { return rep->int16_array_value (); }
916 
int32_array_value(void)917   int32NDArray int32_array_value (void) const
918   { return rep->int32_array_value (); }
919 
int64_array_value(void)920   int64NDArray int64_array_value (void) const
921   { return rep->int64_array_value (); }
922 
uint8_array_value(void)923   uint8NDArray uint8_array_value (void) const
924   { return rep->uint8_array_value (); }
925 
uint16_array_value(void)926   uint16NDArray uint16_array_value (void) const
927   { return rep->uint16_array_value (); }
928 
uint32_array_value(void)929   uint32NDArray uint32_array_value (void) const
930   { return rep->uint32_array_value (); }
931 
uint64_array_value(void)932   uint64NDArray uint64_array_value (void) const
933   { return rep->uint64_array_value (); }
934 
935   std::string string_value (bool force = false) const
936   { return rep->string_value (force); }
937 
938   string_vector string_vector_value (bool pad = false) const
939   { return rep->string_vector_value (pad); }
940 
941   Cell cell_value (void) const;
942 
cellstr_value(void)943   Array<std::string> cellstr_value (void) const
944   { return rep->cellstr_value (); }
945 
range_value(void)946   Range range_value (void) const
947   { return rep->range_value (); }
948 
949   octave_map map_value (void) const;
950 
951   octave_scalar_map scalar_map_value (void) const;
952 
map_keys(void)953   string_vector map_keys (void) const
954   { return rep->map_keys (); }
955 
nparents(void)956   std::size_t nparents (void) const
957   { return rep->nparents (); }
958 
parent_class_name_list(void)959   std::list<std::string> parent_class_name_list (void) const
960   { return rep->parent_class_name_list (); }
961 
parent_class_names(void)962   string_vector parent_class_names (void) const
963   { return rep->parent_class_names (); }
964 
965   octave_base_value *
find_parent_class(const std::string & parent_class_name)966   find_parent_class (const std::string& parent_class_name)
967   { return rep->find_parent_class (parent_class_name); }
968 
is_instance_of(const std::string & cls_name)969   bool is_instance_of (const std::string& cls_name) const
970   { return rep->is_instance_of (cls_name); }
971 
972   octave_classdef * classdef_object_value (bool silent = false) const;
973 
974   octave_function * function_value (bool silent = false) const;
975 
976   octave_user_function * user_function_value (bool silent = false) const;
977 
978   octave_user_script * user_script_value (bool silent = false) const;
979 
980   octave_user_code * user_code_value (bool silent = false) const;
981 
982   octave_fcn_handle * fcn_handle_value (bool silent = false) const;
983 
984   octave_value_list list_value (void) const;
985 
986   ColumnVector column_vector_value (bool frc_str_conv = false,
987                                     bool frc_vec_conv = false) const;
988 
989   ComplexColumnVector
990   complex_column_vector_value (bool frc_str_conv = false,
991                                bool frc_vec_conv = false) const;
992 
993   RowVector row_vector_value (bool frc_str_conv = false,
994                               bool frc_vec_conv = false) const;
995 
996   ComplexRowVector
997   complex_row_vector_value (bool frc_str_conv = false,
998                             bool frc_vec_conv = false) const;
999 
1000   FloatColumnVector float_column_vector_value (bool frc_str_conv = false,
1001                                                bool frc_vec_conv = false) const;
1002 
1003   FloatComplexColumnVector
1004   float_complex_column_vector_value (bool frc_str_conv = false,
1005                                      bool frc_vec_conv = false) const;
1006 
1007   FloatRowVector float_row_vector_value (bool frc_str_conv = false,
1008                                          bool frc_vec_conv = false) const;
1009 
1010   FloatComplexRowVector
1011   float_complex_row_vector_value (bool frc_str_conv = false,
1012                                   bool frc_vec_conv = false) const;
1013 
1014   Array<int> int_vector_value (bool req_int = false,
1015                                bool frc_str_conv = false,
1016                                bool frc_vec_conv = false) const;
1017 
1018   Array<octave_idx_type>
1019   octave_idx_type_vector_value (bool req_int = false,
1020                                 bool frc_str_conv = false,
1021                                 bool frc_vec_conv = false) const;
1022 
1023   Array<double> vector_value (bool frc_str_conv = false,
1024                               bool frc_vec_conv = false) const;
1025 
1026   Array<Complex> complex_vector_value (bool frc_str_conv = false,
1027                                        bool frc_vec_conv = false) const;
1028 
1029   Array<float> float_vector_value (bool frc_str_conv = false,
1030                                    bool frc_vec_conv = false) const;
1031 
1032   Array<FloatComplex>
1033   float_complex_vector_value (bool frc_str_conv = false,
1034                               bool frc_vec_conv = false) const;
1035 
1036   // Extract values of specific types without any implicit type conversions.
1037   // Throw an error if an object is the wrong type for the requested value
1038   // extraction.
1039   //
1040   // These functions are intended to provide a simple way to extract values of
1041   // specific types and display error messages that are more meaningful than
1042   // the generic "error: wrong type argument 'cell'" message.
1043 
1044   short int xshort_value (const char *fmt, ...) const;
1045 
1046   unsigned short int xushort_value (const char *fmt, ...) const;
1047 
1048   int xint_value (const char *fmt, ...) const;
1049 
1050   unsigned int xuint_value (const char *fmt, ...) const;
1051 
1052   int xnint_value (const char *fmt, ...) const;
1053 
1054   long int xlong_value (const char *fmt, ...) const;
1055 
1056   unsigned long int xulong_value (const char *fmt, ...) const;
1057 
1058   int64_t xint64_value (const char *fmt, ...) const;
1059 
1060   uint64_t xuint64_value (const char *fmt, ...) const;
1061 
1062   octave_idx_type xidx_type_value (const char *fmt, ...) const;
1063 
1064   double xdouble_value (const char *fmt, ...) const;
1065 
1066   float xfloat_value (const char *fmt, ...) const;
1067 
1068   double xscalar_value (const char *fmt, ...) const;
1069 
1070   float xfloat_scalar_value (const char *fmt, ...) const;
1071 
1072   Matrix xmatrix_value (const char *fmt, ...) const;
1073 
1074   FloatMatrix xfloat_matrix_value (const char *fmt, ...) const;
1075 
1076   NDArray xarray_value (const char *fmt, ...) const;
1077 
1078   FloatNDArray xfloat_array_value (const char *fmt, ...) const;
1079 
1080   Complex xcomplex_value (const char *fmt, ...) const;
1081 
1082   FloatComplex xfloat_complex_value (const char *fmt, ...) const;
1083 
1084   ComplexMatrix xcomplex_matrix_value (const char *fmt, ...) const;
1085 
1086   FloatComplexMatrix xfloat_complex_matrix_value (const char *fmt, ...) const;
1087 
1088   ComplexNDArray xcomplex_array_value (const char *fmt, ...) const;
1089 
1090   FloatComplexNDArray xfloat_complex_array_value (const char *fmt, ...) const;
1091 
1092   bool xbool_value (const char *fmt, ...) const;
1093 
1094   boolMatrix xbool_matrix_value (const char *fmt, ...) const;
1095 
1096   boolNDArray xbool_array_value (const char *fmt, ...) const;
1097 
1098   charMatrix xchar_matrix_value (const char *fmt, ...) const;
1099 
1100   charNDArray xchar_array_value (const char *fmt, ...) const;
1101 
1102   SparseMatrix xsparse_matrix_value (const char *fmt, ...) const;
1103 
1104   SparseComplexMatrix xsparse_complex_matrix_value (const char *fmt, ...) const;
1105 
1106   SparseBoolMatrix xsparse_bool_matrix_value (const char *fmt, ...) const;
1107 
1108   DiagMatrix xdiag_matrix_value (const char *fmt, ...) const;
1109 
1110   FloatDiagMatrix xfloat_diag_matrix_value (const char *fmt, ...) const;
1111 
1112   ComplexDiagMatrix xcomplex_diag_matrix_value (const char *fmt, ...) const;
1113 
1114   FloatComplexDiagMatrix xfloat_complex_diag_matrix_value (const char *fmt, ...) const;
1115 
1116   PermMatrix xperm_matrix_value (const char *fmt, ...) const;
1117 
1118   octave_int8 xint8_scalar_value (const char *fmt, ...) const;
1119 
1120   octave_int16 xint16_scalar_value (const char *fmt, ...) const;
1121 
1122   octave_int32 xint32_scalar_value (const char *fmt, ...) const;
1123 
1124   octave_int64 xint64_scalar_value (const char *fmt, ...) const;
1125 
1126   octave_uint8 xuint8_scalar_value (const char *fmt, ...) const;
1127 
1128   octave_uint16 xuint16_scalar_value (const char *fmt, ...) const;
1129 
1130   octave_uint32 xuint32_scalar_value (const char *fmt, ...) const;
1131 
1132   octave_uint64 xuint64_scalar_value (const char *fmt, ...) const;
1133 
1134   int8NDArray xint8_array_value (const char *fmt, ...) const;
1135 
1136   int16NDArray xint16_array_value (const char *fmt, ...) const;
1137 
1138   int32NDArray xint32_array_value (const char *fmt, ...) const;
1139 
1140   int64NDArray xint64_array_value (const char *fmt, ...) const;
1141 
1142   uint8NDArray xuint8_array_value (const char *fmt, ...) const;
1143 
1144   uint16NDArray xuint16_array_value (const char *fmt, ...) const;
1145 
1146   uint32NDArray xuint32_array_value (const char *fmt, ...) const;
1147 
1148   uint64NDArray xuint64_array_value (const char *fmt, ...) const;
1149 
1150   std::string xstring_value (const char *fmt, ...) const;
1151 
1152   string_vector xstring_vector_value (const char *fmt, ...) const;
1153 
1154   Cell xcell_value (const char *fmt, ...) const;
1155 
1156   Array<std::string> xcellstr_value (const char *fmt, ...) const;
1157 
1158   Range xrange_value (const char *fmt, ...) const;
1159 
1160   octave_map xmap_value (const char *fmt, ...) const;
1161 
1162   octave_scalar_map xscalar_map_value (const char *fmt, ...) const;
1163 
1164   ColumnVector xcolumn_vector_value (const char *fmt, ...) const;
1165 
1166   ComplexColumnVector
1167   xcomplex_column_vector_value (const char *fmt, ...) const;
1168 
1169   RowVector xrow_vector_value (const char *fmt, ...) const;
1170 
1171   ComplexRowVector xcomplex_row_vector_value (const char *fmt, ...) const;
1172 
1173   FloatColumnVector xfloat_column_vector_value (const char *fmt, ...) const;
1174 
1175   FloatComplexColumnVector
1176   xfloat_complex_column_vector_value (const char *fmt, ...) const;
1177 
1178   FloatRowVector xfloat_row_vector_value (const char *fmt, ...) const;
1179 
1180   FloatComplexRowVector
1181   xfloat_complex_row_vector_value (const char *fmt, ...) const;
1182 
1183   Array<int> xint_vector_value (const char *fmt, ...) const;
1184 
1185   Array<octave_idx_type>
1186   xoctave_idx_type_vector_value (const char *fmt, ...) const;
1187 
1188   Array<double> xvector_value (const char *fmt, ...) const;
1189 
1190   Array<Complex> xcomplex_vector_value (const char *fmt, ...) const;
1191 
1192   Array<float> xfloat_vector_value (const char *fmt, ...) const;
1193 
1194   Array<FloatComplex> xfloat_complex_vector_value (const char *fmt, ...) const;
1195 
1196   octave_function * xfunction_value (const char *fmt, ...) const;
1197   octave_user_function * xuser_function_value (const char *fmt, ...) const;
1198   octave_user_script * xuser_script_value (const char *fmt, ...) const;
1199   octave_user_code * xuser_code_value (const char *fmt, ...) const;
1200   octave_fcn_handle * xfcn_handle_value (const char *fmt, ...) const;
1201 
1202   octave_value_list xlist_value (const char *fmt, ...) const;
1203 
1204   // Possibly economize a lazy-indexed value.
1205 
maybe_economize(void)1206   void maybe_economize (void)
1207   { rep->maybe_economize (); }
1208 
1209   // The following two hook conversions are called on any octave_value prior to
1210   // storing it to a "permanent" location, like a named variable, a cell or a
1211   // struct component, or a return value of a function.
1212 
1213   octave_value storable_value (void) const;
1214 
1215   // Ditto, but in place, i.e., equivalent to *this = this->storable_value (),
1216   // but possibly more efficient.
1217 
1218   void make_storable_value (void);
1219 
1220   // FIXME: These should probably be private.
1221   // Conversions.  If a user of this class wants a certain kind of constant,
1222   // he should simply ask for it, and we should convert it if possible.
1223 
1224   octave_value convert_to_str (bool pad = false, bool force = false,
1225                                char type = '\'') const
1226   { return rep->convert_to_str (pad, force, type); }
1227 
1228   octave_value
convert_to_str_internal(bool pad,bool force,char type)1229   convert_to_str_internal (bool pad, bool force, char type) const
1230   { return rep->convert_to_str_internal (pad, force, type); }
1231 
convert_to_row_or_column_vector(void)1232   void convert_to_row_or_column_vector (void)
1233   { rep->convert_to_row_or_column_vector (); }
1234 
print_as_scalar(void)1235   bool print_as_scalar (void) const
1236   { return rep->print_as_scalar (); }
1237 
1238   void print (std::ostream& os, bool pr_as_read_syntax = false)
1239   { rep->print (os, pr_as_read_syntax); }
1240 
1241   void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
1242   { rep->print_raw (os, pr_as_read_syntax); }
1243 
print_name_tag(std::ostream & os,const std::string & name)1244   bool print_name_tag (std::ostream& os, const std::string& name) const
1245   { return rep->print_name_tag (os, name); }
1246 
print_with_name(std::ostream & os,const std::string & name)1247   void print_with_name (std::ostream& os, const std::string& name) const
1248   { rep->print_with_name (os, name, true); }
1249 
short_disp(std::ostream & os)1250   void short_disp (std::ostream& os) const { rep->short_disp (os); }
1251 
1252   float_display_format get_edit_display_format (void) const;
1253 
edit_display(const float_display_format & fmt,octave_idx_type i,octave_idx_type j)1254   std::string edit_display (const float_display_format& fmt,
1255                             octave_idx_type i, octave_idx_type j) const
1256   {
1257     return rep->edit_display (fmt, i, j);
1258   }
1259 
type_id(void)1260   int type_id (void) const { return rep->type_id (); }
1261 
type_name(void)1262   std::string type_name (void) const { return rep->type_name (); }
1263 
class_name(void)1264   std::string class_name (void) const { return rep->class_name (); }
1265 
1266   // Unary and binary operations.
1267 
1268   friend OCTINTERP_API octave_value
1269   do_unary_op (octave::type_info& ti, unary_op op, const octave_value& a);
1270 
1271   octave_value& do_non_const_unary_op (unary_op op);
1272 
1273   octave_value& do_non_const_unary_op (unary_op op, const std::string& type,
1274                                        const std::list<octave_value_list>& idx);
1275 
1276   friend OCTINTERP_API octave_value
1277   do_binary_op (octave::type_info& ti, binary_op op,
1278                 const octave_value& a, const octave_value& b);
1279 
1280   friend OCTINTERP_API octave_value
1281   do_binary_op (octave::type_info& ti, compound_binary_op op,
1282                 const octave_value& a, const octave_value& b);
1283 
1284   friend OCTINTERP_API octave_value
1285   do_cat_op (octave::type_info& ti, const octave_value& a,
1286              const octave_value& b, const Array<octave_idx_type>& ra_idx);
1287 
do_colon_op(const octave_value & base,const octave_value & limit,bool is_for_cmd_expr)1288   friend OCTINTERP_API octave_value do_colon_op (const octave_value& base,
1289                                                  const octave_value& limit,
1290                                                  bool is_for_cmd_expr)
1291   {
1292     return do_colon_op (base, octave_value (), limit, is_for_cmd_expr);
1293   }
1294 
1295   friend OCTINTERP_API octave_value do_colon_op (const octave_value& base,
1296                                                  const octave_value& increment,
1297                                                  const octave_value& limit,
1298                                                  bool is_for_cmd_expr);
1299 
get_rep(void)1300   const octave_base_value& get_rep (void) const { return *rep; }
1301 
is_copy_of(const octave_value & val)1302   bool is_copy_of (const octave_value& val) const { return rep == val.rep; }
1303 
1304   void print_info (std::ostream& os,
1305                    const std::string& prefix = "") const;
1306 
save_ascii(std::ostream & os)1307   bool save_ascii (std::ostream& os) { return rep->save_ascii (os); }
1308 
load_ascii(std::istream & is)1309   bool load_ascii (std::istream& is) { return rep->load_ascii (is); }
1310 
save_binary(std::ostream & os,bool save_as_floats)1311   bool save_binary (std::ostream& os, bool save_as_floats)
1312   { return rep->save_binary (os, save_as_floats); }
1313 
load_binary(std::istream & is,bool swap,octave::mach_info::float_format fmt)1314   bool load_binary (std::istream& is, bool swap,
1315                     octave::mach_info::float_format fmt)
1316   { return rep->load_binary (is, swap, fmt); }
1317 
save_hdf5(octave_hdf5_id loc_id,const char * name,bool save_as_floats)1318   bool save_hdf5 (octave_hdf5_id loc_id, const char *name,
1319                   bool save_as_floats)
1320   { return rep->save_hdf5 (loc_id, name, save_as_floats); }
1321 
load_hdf5(octave_hdf5_id loc_id,const char * name)1322   bool load_hdf5 (octave_hdf5_id loc_id, const char *name)
1323   { return rep->load_hdf5 (loc_id, name); }
1324 
1325   int write (octave::stream& os, int block_size,
1326              oct_data_conv::data_type output_type, int skip,
1327              octave::mach_info::float_format flt_fmt) const;
1328 
internal_rep(void)1329   octave_base_value * internal_rep (void) const { return rep; }
1330 
1331   // Unsafe.  These functions exist to support the MEX interface.
1332   // You should not use them anywhere else.
mex_get_data(void)1333   void * mex_get_data (void) const { return rep->mex_get_data (); }
1334 
mex_get_ir(void)1335   octave_idx_type * mex_get_ir (void) const { return rep->mex_get_ir (); }
1336 
mex_get_jc(void)1337   octave_idx_type * mex_get_jc (void) const { return rep->mex_get_jc (); }
1338 
as_mxArray(void)1339   mxArray * as_mxArray (void) const { return rep->as_mxArray (); }
1340 
1341   octave_value diag (octave_idx_type k = 0) const
1342   { return rep->diag (k); }
1343 
diag(octave_idx_type m,octave_idx_type n)1344   octave_value diag (octave_idx_type m, octave_idx_type n) const
1345   { return rep->diag (m, n); }
1346 
1347   octave_value sort (octave_idx_type dim = 0, sortmode mode = ASCENDING) const
1348   { return rep->sort (dim, mode); }
1349   octave_value sort (Array<octave_idx_type> &sidx, octave_idx_type dim = 0,
1350                      sortmode mode = ASCENDING) const
1351   { return rep->sort (sidx, dim, mode); }
1352 
1353   sortmode issorted (sortmode mode = UNSORTED) const
1354   { return rep->issorted (mode); }
1355 
1356   Array<octave_idx_type> sort_rows_idx (sortmode mode = ASCENDING) const
1357   { return rep->sort_rows_idx (mode); }
1358 
1359   sortmode is_sorted_rows (sortmode mode = UNSORTED) const
1360   { return rep->is_sorted_rows (mode); }
1361 
lock(void)1362   void lock (void) { rep->lock (); }
1363 
unlock(void)1364   void unlock (void) { rep->unlock (); }
1365 
islocked(void)1366   bool islocked (void) const { return rep->islocked (); }
1367 
call_object_destructor(void)1368   void call_object_destructor (void) { return rep->call_object_destructor (); }
1369 
dump(void)1370   octave_value dump (void) const { return rep->dump (); }
1371 
1372 #define MAPPER_FORWARD(F) \
1373   octave_value F (void) const                           \
1374   {                                                     \
1375     return rep->map (octave_base_value::umap_ ## F);    \
1376   }
1377 
1378   MAPPER_FORWARD (abs)
MAPPER_FORWARD(acos)1379   MAPPER_FORWARD (acos)
1380   MAPPER_FORWARD (acosh)
1381   MAPPER_FORWARD (angle)
1382   MAPPER_FORWARD (arg)
1383   MAPPER_FORWARD (asin)
1384   MAPPER_FORWARD (asinh)
1385   MAPPER_FORWARD (atan)
1386   MAPPER_FORWARD (atanh)
1387   MAPPER_FORWARD (cbrt)
1388   MAPPER_FORWARD (ceil)
1389   MAPPER_FORWARD (conj)
1390   MAPPER_FORWARD (cos)
1391   MAPPER_FORWARD (cosh)
1392   MAPPER_FORWARD (erf)
1393   MAPPER_FORWARD (erfinv)
1394   MAPPER_FORWARD (erfcinv)
1395   MAPPER_FORWARD (erfc)
1396   MAPPER_FORWARD (erfcx)
1397   MAPPER_FORWARD (erfi)
1398   MAPPER_FORWARD (dawson)
1399   MAPPER_FORWARD (exp)
1400   MAPPER_FORWARD (expm1)
1401   MAPPER_FORWARD (isfinite)
1402   MAPPER_FORWARD (fix)
1403   MAPPER_FORWARD (floor)
1404   MAPPER_FORWARD (gamma)
1405   MAPPER_FORWARD (imag)
1406   MAPPER_FORWARD (isinf)
1407   MAPPER_FORWARD (isna)
1408   MAPPER_FORWARD (isnan)
1409   MAPPER_FORWARD (lgamma)
1410   MAPPER_FORWARD (log)
1411   MAPPER_FORWARD (log2)
1412   MAPPER_FORWARD (log10)
1413   MAPPER_FORWARD (log1p)
1414   MAPPER_FORWARD (real)
1415   MAPPER_FORWARD (round)
1416   MAPPER_FORWARD (roundb)
1417   MAPPER_FORWARD (signum)
1418   MAPPER_FORWARD (sin)
1419   MAPPER_FORWARD (sinh)
1420   MAPPER_FORWARD (sqrt)
1421   MAPPER_FORWARD (tan)
1422   MAPPER_FORWARD (tanh)
1423 
1424   // These functions are prefixed with X to avoid potential macro conflicts.
1425 
1426   MAPPER_FORWARD (xisalnum)
1427   MAPPER_FORWARD (xisalpha)
1428   MAPPER_FORWARD (xisascii)
1429   MAPPER_FORWARD (xiscntrl)
1430   MAPPER_FORWARD (xisdigit)
1431   MAPPER_FORWARD (xisgraph)
1432   MAPPER_FORWARD (xislower)
1433   MAPPER_FORWARD (xisprint)
1434   MAPPER_FORWARD (xispunct)
1435   MAPPER_FORWARD (xisspace)
1436   MAPPER_FORWARD (xisupper)
1437   MAPPER_FORWARD (xisxdigit)
1438   MAPPER_FORWARD (xsignbit)
1439   MAPPER_FORWARD (xtolower)
1440   MAPPER_FORWARD (xtoupper)
1441 
1442 #undef MAPPER_FORWARD
1443 
1444   octave_value map (octave_base_value::unary_mapper_t umap) const
1445   { return rep->map (umap); }
1446 
1447   //! Extract the n-th element, aka 'val(n)'.
1448   //!
1449   //! @return Result is undefined if 'val' is not an array type
1450   //!         or @p n is out of range.
1451   //!
1452   //! @warning Function calls should never error.
1453 
1454   octave_value
fast_elem_extract(octave_idx_type n)1455   fast_elem_extract (octave_idx_type n) const
1456   { return rep->fast_elem_extract (n); }
1457 
1458   //! Assign the n-th element, aka 'val(n) = x'.
1459   //!
1460   //! @returns false if 'val' is not an array type,
1461   //!          @p x is not a matching scalar type,
1462   //!          or @p n is out of range.
1463   //!
1464   //! @warning Function calls should never error.
1465 
1466   bool
fast_elem_insert(octave_idx_type n,const octave_value & x)1467   fast_elem_insert (octave_idx_type n, const octave_value& x)
1468   {
1469     make_unique ();
1470     return rep->fast_elem_insert (n, x);
1471   }
1472 
1473 protected:
1474 
1475   //! The real representation.
1476   octave_base_value *rep;
1477 
1478 private:
1479 
1480   static octave_base_value *nil_rep (void);
1481 
1482   assign_op unary_op_to_assign_op (unary_op op);
1483 
1484   binary_op op_eq_to_binary_op (assign_op op);
1485 
1486   // This declaration protects against constructing octave_value from
1487   // const octave_base_value* which actually silently calls octave_value (bool).
1488   octave_value (const octave_base_value *);
1489 
1490 };
1491 
1492 // Publish externally used friend functions.  Which compiler requires
1493 // these extra declarations?
1494 
1495 extern OCTINTERP_API octave_value
1496 do_unary_op (octave::type_info& ti, octave_value::unary_op op,
1497              const octave_value& a);
1498 
1499 extern OCTINTERP_API octave_value
1500 do_unary_op (octave_value::unary_op op, const octave_value& a);
1501 
1502 extern OCTINTERP_API octave_value
1503 do_binary_op (octave::type_info& ti, octave_value::binary_op op,
1504               const octave_value& a, const octave_value& b);
1505 
1506 extern OCTINTERP_API octave_value
1507 do_binary_op (octave::type_info& ti, octave_value::compound_binary_op op,
1508               const octave_value& a, const octave_value& b);
1509 
1510 extern OCTINTERP_API octave_value
1511 do_binary_op (octave_value::binary_op op, const octave_value& a,
1512               const octave_value& b);
1513 
1514 extern OCTINTERP_API octave_value
1515 do_binary_op (octave_value::compound_binary_op op, const octave_value& a,
1516               const octave_value& b);
1517 
1518 extern OCTINTERP_API octave_value
1519 do_cat_op (octave::type_info& ti, const octave_value& a,
1520            const octave_value& b, const Array<octave_idx_type>& ra_idx);
1521 
1522 extern OCTINTERP_API octave_value
1523 do_cat_op (const octave_value& a, const octave_value& b,
1524            const Array<octave_idx_type>& ra_idx);
1525 
1526 #define OV_UNOP_FN(name)                        \
1527   inline octave_value                           \
1528   name (const octave_value& a)                  \
1529   {                                             \
1530     return do_unary_op (octave_value::name, a); \
1531   }
1532 
1533 #define OV_UNOP_OP(name, op)                    \
1534   inline octave_value                           \
1535   operator op (const octave_value& a)           \
1536   {                                             \
1537     return name (a);                            \
1538   }
1539 
1540 #define OV_UNOP_FN_OP(name, op)                 \
1541   OV_UNOP_FN (name)                             \
1542   OV_UNOP_OP (name, op)
1543 
1544 OV_UNOP_FN_OP (op_not, !)
1545 OV_UNOP_FN_OP (op_uplus, +)
1546 OV_UNOP_FN_OP (op_uminus, -)
1547 
1548 OV_UNOP_FN (op_transpose)
1549 OV_UNOP_FN (op_hermitian)
1550 
1551 // No simple way to define these for prefix and suffix ops?
1552 //
1553 //   incr
1554 //   decr
1555 
1556 #define OV_BINOP_FN(name)                               \
1557   inline octave_value                                   \
1558   name (const octave_value& a1, const octave_value& a2) \
1559   {                                                     \
1560     return do_binary_op (octave_value::name, a1, a2);   \
1561   }
1562 
1563 #define OV_BINOP_OP(name, op)                                   \
1564   inline octave_value                                           \
1565   operator op (const octave_value& a1, const octave_value& a2)  \
1566   {                                                             \
1567     return name (a1, a2);                                       \
1568   }
1569 
1570 #define OV_BINOP_FN_OP(name, op)                \
1571   OV_BINOP_FN (name)                            \
1572   OV_BINOP_OP (name, op)
1573 
1574 OV_BINOP_FN_OP (op_add, +)
1575 OV_BINOP_FN_OP (op_sub, -)
1576 OV_BINOP_FN_OP (op_mul, *)
1577 OV_BINOP_FN_OP (op_div, /)
1578 
1579 OV_BINOP_FN (op_pow)
1580 OV_BINOP_FN (op_ldiv)
1581 
1582 OV_BINOP_FN_OP (op_lt, <)
1583 OV_BINOP_FN_OP (op_le, <=)
1584 OV_BINOP_FN_OP (op_eq, ==)
1585 OV_BINOP_FN_OP (op_ge, >=)
1586 OV_BINOP_FN_OP (op_gt, >)
1587 OV_BINOP_FN_OP (op_ne, !=)
1588 
1589 OV_BINOP_FN (op_el_mul)
1590 OV_BINOP_FN (op_el_div)
1591 OV_BINOP_FN (op_el_pow)
1592 OV_BINOP_FN (op_el_ldiv)
1593 OV_BINOP_FN (op_el_and)
1594 OV_BINOP_FN (op_el_or)
1595 
1596 OV_BINOP_FN (op_struct_ref)
1597 
1598 #define OV_COMP_BINOP_FN(name)                          \
1599   inline octave_value                                   \
1600   name (const octave_value& a1, const octave_value& a2) \
1601   {                                                     \
1602     return do_binary_op (octave_value::name, a1, a2);   \
1603   }
1604 
1605 OV_COMP_BINOP_FN (op_trans_mul)
1606 OV_COMP_BINOP_FN (op_mul_trans)
1607 OV_COMP_BINOP_FN (op_herm_mul)
1608 OV_COMP_BINOP_FN (op_mul_herm)
1609 
1610 extern OCTINTERP_API void install_types (octave::type_info&);
1611 
1612 // Templated value extractors.
1613 template <typename Value>
octave_value_extract(const octave_value &)1614 inline Value octave_value_extract (const octave_value&)
1615 { assert (false); }
1616 
1617 #define DEF_VALUE_EXTRACTOR(VALUE,MPREFIX)                              \
1618   template <>                                                           \
1619   inline VALUE octave_value_extract<VALUE> (const octave_value& v)      \
1620   {                                                                     \
1621     return v.MPREFIX ## _value ();                                      \
1622   }
1623 
1624 DEF_VALUE_EXTRACTOR (double, scalar)
1625 DEF_VALUE_EXTRACTOR (float, float_scalar)
1626 DEF_VALUE_EXTRACTOR (Complex, complex)
1627 DEF_VALUE_EXTRACTOR (FloatComplex, float_complex)
1628 DEF_VALUE_EXTRACTOR (bool, bool)
1629 
1630 DEF_VALUE_EXTRACTOR (octave_int8, int8_scalar)
1631 DEF_VALUE_EXTRACTOR (octave_int16, int16_scalar)
1632 DEF_VALUE_EXTRACTOR (octave_int32, int32_scalar)
1633 DEF_VALUE_EXTRACTOR (octave_int64, int64_scalar)
1634 DEF_VALUE_EXTRACTOR (octave_uint8, uint8_scalar)
1635 DEF_VALUE_EXTRACTOR (octave_uint16, uint16_scalar)
1636 DEF_VALUE_EXTRACTOR (octave_uint32, uint32_scalar)
1637 DEF_VALUE_EXTRACTOR (octave_uint64, uint64_scalar)
1638 
1639 DEF_VALUE_EXTRACTOR (NDArray, array)
1640 DEF_VALUE_EXTRACTOR (FloatNDArray, float_array)
1641 DEF_VALUE_EXTRACTOR (ComplexNDArray, complex_array)
1642 DEF_VALUE_EXTRACTOR (FloatComplexNDArray, float_complex_array)
1643 DEF_VALUE_EXTRACTOR (boolNDArray, bool_array)
1644 
1645 DEF_VALUE_EXTRACTOR (charNDArray, char_array)
1646 DEF_VALUE_EXTRACTOR (int8NDArray, int8_array)
1647 DEF_VALUE_EXTRACTOR (int16NDArray, int16_array)
1648 DEF_VALUE_EXTRACTOR (int32NDArray, int32_array)
1649 DEF_VALUE_EXTRACTOR (int64NDArray, int64_array)
1650 DEF_VALUE_EXTRACTOR (uint8NDArray, uint8_array)
1651 DEF_VALUE_EXTRACTOR (uint16NDArray, uint16_array)
1652 DEF_VALUE_EXTRACTOR (uint32NDArray, uint32_array)
1653 DEF_VALUE_EXTRACTOR (uint64NDArray, uint64_array)
1654 
1655 DEF_VALUE_EXTRACTOR (Matrix, matrix)
1656 DEF_VALUE_EXTRACTOR (FloatMatrix, float_matrix)
1657 DEF_VALUE_EXTRACTOR (ComplexMatrix, complex_matrix)
1658 DEF_VALUE_EXTRACTOR (FloatComplexMatrix, float_complex_matrix)
1659 DEF_VALUE_EXTRACTOR (boolMatrix, bool_matrix)
1660 
1661 DEF_VALUE_EXTRACTOR (ColumnVector, column_vector)
1662 DEF_VALUE_EXTRACTOR (FloatColumnVector, float_column_vector)
1663 DEF_VALUE_EXTRACTOR (ComplexColumnVector, complex_column_vector)
1664 DEF_VALUE_EXTRACTOR (FloatComplexColumnVector, float_complex_column_vector)
1665 
1666 DEF_VALUE_EXTRACTOR (RowVector, row_vector)
1667 DEF_VALUE_EXTRACTOR (FloatRowVector, float_row_vector)
1668 DEF_VALUE_EXTRACTOR (ComplexRowVector, complex_row_vector)
1669 DEF_VALUE_EXTRACTOR (FloatComplexRowVector, float_complex_row_vector)
1670 
1671 DEF_VALUE_EXTRACTOR (DiagMatrix, diag_matrix)
1672 DEF_VALUE_EXTRACTOR (FloatDiagMatrix, float_diag_matrix)
1673 DEF_VALUE_EXTRACTOR (ComplexDiagMatrix, complex_diag_matrix)
1674 DEF_VALUE_EXTRACTOR (FloatComplexDiagMatrix, float_complex_diag_matrix)
1675 DEF_VALUE_EXTRACTOR (PermMatrix, perm_matrix)
1676 
1677 DEF_VALUE_EXTRACTOR (SparseMatrix, sparse_matrix)
1678 DEF_VALUE_EXTRACTOR (SparseComplexMatrix, sparse_complex_matrix)
1679 DEF_VALUE_EXTRACTOR (SparseBoolMatrix, sparse_bool_matrix)
1680 #undef DEF_VALUE_EXTRACTOR
1681 
1682 #define DEF_DUMMY_VALUE_EXTRACTOR(VALUE,DEFVAL)                         \
1683   template <>                                                           \
1684   inline VALUE octave_value_extract<VALUE> (const octave_value&)        \
1685   {                                                                     \
1686     assert (false);                                                     \
1687     return DEFVAL;                                                      \
1688   }
1689 
1690 DEF_DUMMY_VALUE_EXTRACTOR (char, 0)
1691 DEF_DUMMY_VALUE_EXTRACTOR (octave_value, octave_value ())
1692 #undef DEF_DUMMY_VALUE_EXTRACTOR
1693 
1694 #endif
1695