GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2024 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_base_h)
27 #define octave_ov_base_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <list>
35 #include <memory>
36 #include <string>
37 
38 #include "Range.h"
39 #include "data-conv.h"
40 #include "mx-base.h"
41 #include "str-vec.h"
42 
43 #include "auto-shlib.h"
44 #include "oct-hdf5-types.h"
45 #include "oct-stream.h"
46 
48 
49 class stack_frame;
50 class type_info;
51 
52 // FIXME: This is not ideal, but it avoids including
53 // interpreter-private.h here and bringing in a lot of unnecessary
54 // symbols that require even more header files. Since the typeinfo
55 // object is required to load a user-defined octave_value object,
56 // maybe this function should be declared in a public header file?
57 
58 extern OCTINTERP_API type_info& __get_type_info__ ();
59 
60 // For now just preserve the old interface and don't mark it as deprecated.
61 // This function is currently an internal, private function. Additional
62 // changes may be made before version 8 is finally released.
63 inline type_info& __get_type_info__ (const std::string&) { return __get_type_info__ (); }
64 
65 OCTAVE_END_NAMESPACE(octave)
66 
67 class Cell;
69 class mxArray;
70 class octave_map;
71 class octave_scalar_map;
72 class octave_value;
73 class octave_value_list;
74 class octave_classdef;
75 class octave_function;
77 class octave_user_script;
78 class octave_user_code;
79 class octave_fcn_handle;
80 class octave_value_list;
81 
83 {
103 };
104 
105 extern OCTINTERP_API std::string btyp_class_name [];
106 
107 inline bool btyp_isnumeric (builtin_type_t btyp)
108 { return btyp <= btyp_uint64; }
109 
110 inline bool btyp_isinteger (builtin_type_t btyp)
111 { return btyp >= btyp_int8 && btyp <= btyp_uint64; }
112 
113 inline bool btyp_isfloat (builtin_type_t btyp)
114 { return btyp <= btyp_float_complex; }
115 
116 inline bool btyp_isarray (builtin_type_t btyp)
117 { return btyp <= btyp_char; }
118 
119 //! Determine the resulting type for a possible mixed-type operation.
120 //!
121 //! Rules for the resulting type:
122 //! - bool -> double
123 //! - single + double -> single
124 //! - real + complex -> complex
125 //! - integer + real -> integer
126 //! - uint + uint -> uint (the bigger one)
127 //! - sint + sint -> sint (the bigger one)
128 //!
129 //! @return The resulting type or "unknown type", if the resulting type cannot
130 //! be determined.
131 
132 extern OCTINTERP_API
134 
135 template <typename T>
137 {
139 };
140 
141 template <builtin_type_t BTYP>
143 {
144  typedef void type;
145 };
146 
147 #define DEF_BTYP_TRAITS(BTYP, CLASS) \
148  template <> \
149  struct class_to_btyp<CLASS> \
150  { \
151  static const builtin_type_t btyp = BTYP; \
152  }; \
153  \
154  template <> \
155  struct btyp_to_class<BTYP> \
156  { \
157  typedef CLASS type; \
158  }
159 
174 
175 
176 // T_ID is the type id of struct objects, set by register_type().
177 // T_NAME is the type name of struct objects.
178 
179 #define OCTAVE_EMPTY_CPP_ARG /* empty */
180 
181 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA \
182  DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2 (OCTAVE_EMPTY_CPP_ARG)
183 
184 #define DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA \
185  DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(virtual)
186 
187 #define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA2(VIRTUAL) \
188  public: \
189  VIRTUAL int type_id () const { return s_t_id; } \
190  VIRTUAL std::string type_name () const { return s_t_name; } \
191  VIRTUAL std::string class_name () const { return s_c_name; } \
192  static int static_type_id () { return s_t_id; } \
193  static std::string static_type_name () { return s_t_name; } \
194  static std::string static_class_name () { return s_c_name; } \
195  static void register_type (); \
196  static void register_type (octave::type_info&); \
197  \
198  private: \
199  static int s_t_id; \
200  static const std::string s_t_name; \
201  static const std::string s_c_name;
202 
203 #define DECLARE_TEMPLATE_OV_TYPEID_SPECIALIZATIONS(cls, type) \
204  template <> void cls<type>::register_type (); \
205  template <> void cls<type>::register_type (octave::type_info&); \
206  template <> int cls<type>::s_t_id; \
207  template <> const std::string cls<type>::s_t_name; \
208  template <> const std::string cls<type>::s_c_name;
209 
210 // FIXME: The 'new' operator below creates an 8-byte memory leak for every
211 // registered data type (of which there are 58 built-in to Octave, plus any
212 // user-defined data types). The problem is user-defined types creating
213 // a crash on exit (see bug #53156). See also the FIXME note in function
214 // register_type() in ov-typeinfo.cc.
215 
216 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL(tspec, t, n, c) \
217  tspec int t::s_t_id (-1); \
218  tspec const std::string t::s_t_name (n); \
219  tspec const std::string t::s_c_name (c); \
220  tspec void t::register_type () \
221  { \
222  octave::type_info& type_info = octave::__get_type_info__ (); \
223  \
224  register_type (type_info); \
225  } \
226  tspec void t::register_type (octave::type_info& ti) \
227  { \
228  octave_value v = (new t ()); \
229  s_t_id = ti.register_type (t::s_t_name, t::s_c_name, v); \
230  }
231 
232 #define DEFINE_TEMPLATE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \
233  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL (template <>, t, n, c)
234 
235 #define DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA(t, n, c) \
236  DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA_INTERNAL ( , t, n, c)
237 
238 // A base value type, so that derived types only have to redefine what
239 // they need (if they are derived from octave_base_value instead of
240 // octave_value).
241 
242 class
243 OCTINTERP_API
245 {
246 public:
247 
248  typedef octave_base_value *(*type_conv_fcn) (const octave_base_value&);
249 
250  // type conversion, including result type information
252  {
253  public:
254  type_conv_info (type_conv_fcn f = nullptr, int t = -1)
255  : m_fcn (f), m_type_id (t) { }
256 
257  operator type_conv_fcn () const { return m_fcn; }
258 
259  octave_base_value * operator () (const octave_base_value& v) const
260  { return (*m_fcn) (v); }
261 
262  int type_id () const { return m_type_id; }
263 
264  private:
265  type_conv_fcn m_fcn;
266  int m_type_id;
267  };
268 
269  friend class octave_value;
270 
272 
274 
275  virtual ~octave_base_value () = default;
276 
277  // Unconditional clone. Always clones.
278  virtual octave_base_value *
279  clone () const { return new octave_base_value (*this); }
280 
281  // Empty clone.
282  virtual octave_base_value *
283  empty_clone () const;
284 
285  // Unique clone. Usually clones, but may be overridden to fake the
286  // cloning when sharing copies is to be controlled from within an
287  // instance (see octave_class).
288  virtual octave_base_value *
289  unique_clone () { return clone (); }
290 
291  virtual void break_closure_cycles (const std::shared_ptr<octave::stack_frame>&) { }
292 
293  virtual type_conv_info
295  { return type_conv_info (); }
296 
297  virtual type_conv_info
299  { return type_conv_info (); }
300 
301  virtual octave_value squeeze () const;
302 
303  virtual octave_value full_value () const;
304 
305  // Will return a copy of it-self when the representation
306  // allready is a scalar (.i.e. double). The const variant
307  // as_double () would allocate a new octave value.
308  virtual octave_value as_double_or_copy ();
309 
310  virtual octave_value as_double () const;
311  virtual octave_value as_single () const;
312 
313  virtual octave_value as_int8 () const;
314  virtual octave_value as_int16 () const;
315  virtual octave_value as_int32 () const;
316  virtual octave_value as_int64 () const;
317 
318  virtual octave_value as_uint8 () const;
319  virtual octave_value as_uint16 () const;
320  virtual octave_value as_uint32 () const;
321  virtual octave_value as_uint64 () const;
322 
324  { return nullptr; }
325 
326  virtual void maybe_economize () { }
327 
328  virtual Matrix size ();
329 
330  virtual octave_idx_type xnumel (const octave_value_list&);
331 
332  // FIXME: Do we really need all three of these versions of subsref?
333 
334  virtual octave_value
335  subsref (const std::string& type,
336  const std::list<octave_value_list>& idx);
337 
338  virtual octave_value_list
339  subsref (const std::string& type,
340  const std::list<octave_value_list>& idx,
341  int nargout);
342 
343  virtual octave_value
344  subsref (const std::string& type,
345  const std::list<octave_value_list>& idx,
346  bool auto_add);
347 
348  virtual octave_value_list
349  simple_subsref (char type, octave_value_list& idx, int nargout);
350 
351  virtual octave_value
352  do_index_op (const octave_value_list& idx, bool resize_ok = false);
353 
354  virtual void assign (const std::string&, const octave_value&) { }
355 
356  virtual octave_value
357  subsasgn (const std::string& type,
358  const std::list<octave_value_list>& idx,
359  const octave_value& rhs);
360 
361  virtual octave_value
362  simple_subsasgn (char type, octave_value_list& idx,
363  const octave_value& rhs);
364 
365  virtual octave_value
366  undef_subsasgn (const std::string& type,
367  const std::list<octave_value_list>& idx,
368  const octave_value& rhs);
369 
370  virtual octave::idx_vector index_vector (bool require_integers = false) const;
371 
372  virtual dim_vector dims () const { return dim_vector (); }
373 
375  {
376  const dim_vector dv = dims ();
377 
378  return dv(0);
379  }
380 
382  {
383  const dim_vector dv = dims ();
384 
385  return dv(1);
386  }
387 
388  virtual int ndims () const
389  { return dims ().ndims (); }
390 
391  virtual octave_idx_type numel () const { return dims ().numel (); }
392 
393  virtual std::size_t byte_size () const { return 0; }
394 
395  virtual octave_idx_type nnz () const;
396 
397  virtual octave_idx_type nzmax () const;
398 
399  virtual octave_idx_type nfields () const;
400 
401  virtual octave_value reshape (const dim_vector&) const;
402 
403  virtual octave_value permute (const Array<int>& vec, bool = false) const;
404 
405  virtual octave_value resize (const dim_vector&, bool fill = false) const;
406 
407  virtual MatrixType matrix_type () const;
408 
409  virtual MatrixType matrix_type (const MatrixType& typ) const;
410 
411  virtual bool is_defined () const { return false; }
412 
413  virtual bool is_storable () const { return true; }
414 
415  virtual bool is_legacy_object () const { return false; }
416 
417  bool isempty () const { return (dims ().any_zero ()); }
418 
419  bool is_zero_by_zero () const { return dims().zero_by_zero (); }
420 
421  virtual bool iscell () const { return false; }
422 
423  virtual bool iscellstr () const { return false; }
424 
425  virtual bool is_real_scalar () const { return false; }
426 
427  virtual bool is_real_matrix () const { return false; }
428 
429  virtual bool is_complex_scalar () const { return false; }
430 
431  virtual bool is_complex_matrix () const { return false; }
432 
433  virtual bool is_bool_scalar () const { return false; }
434 
435  virtual bool is_bool_matrix () const { return false; }
436 
437  virtual bool is_char_matrix () const { return false; }
438 
439  virtual bool is_diag_matrix () const { return false; }
440 
441  virtual bool is_perm_matrix () const { return false; }
442 
443  virtual bool is_string () const { return false; }
444 
445  virtual bool is_sq_string () const { return false; }
446 
447  virtual bool is_range () const { return false; }
448 
449  virtual bool isstruct () const { return false; }
450 
451  virtual bool isobject () const { return false; }
452 
453  virtual bool is_classdef_meta () const { return false; }
454 
455  virtual bool is_classdef_superclass_ref () const { return false; }
456 
457  virtual bool is_classdef_object () const { return false; }
458 
459  virtual bool is_package () const { return false; }
460 
461  virtual bool isjava () const { return false; }
462 
463  virtual bool is_cs_list () const { return false; }
464 
465  virtual bool is_magic_colon () const { return false; }
466 
467  virtual bool is_all_va_args () const { return false; }
468 
469  virtual octave_value all (int = 0) const;
470 
471  virtual octave_value any (int = 0) const;
472 
473  virtual builtin_type_t builtin_type () const { return btyp_unknown; }
474 
475  virtual bool is_double_type () const { return false; }
476 
477  virtual bool is_single_type () const { return false; }
478 
479  virtual bool isfloat () const { return false; }
480 
481  virtual bool is_int8_type () const { return false; }
482 
483  virtual bool is_int16_type () const { return false; }
484 
485  virtual bool is_int32_type () const { return false; }
486 
487  virtual bool is_int64_type () const { return false; }
488 
489  virtual bool is_uint8_type () const { return false; }
490 
491  virtual bool is_uint16_type () const { return false; }
492 
493  virtual bool is_uint32_type () const { return false; }
494 
495  virtual bool is_uint64_type () const { return false; }
496 
497  virtual bool islogical () const { return false; }
498 
499  virtual bool isinteger () const { return false; }
500 
501  virtual bool isreal () const { return false; }
502 
503  virtual bool iscomplex () const { return false; }
504 
505  // Would be nice to get rid of the next four functions:
506 
507  virtual bool is_scalar_type () const { return false; }
508 
509  virtual bool is_matrix_type () const { return false; }
510 
511  virtual bool is_full_num_matrix () const { return false; }
512 
513  virtual bool isnumeric () const { return false; }
514 
515  virtual bool issparse () const { return false; }
516 
517  virtual bool is_true () const { return false; }
518 
519  virtual bool is_magic_int () const { return false; }
520 
521  virtual bool isnull () const { return false; }
522 
523  virtual bool is_constant () const { return false; }
524 
525  virtual bool is_function_handle () const { return false; }
526 
527  virtual bool is_anonymous_function () const { return false; }
528 
529  virtual bool is_inline_function () const { return false; }
530 
531  virtual bool is_function () const { return false; }
532 
533  virtual bool is_user_script () const { return false; }
534 
535  virtual bool is_user_function () const { return false; }
536 
537  virtual bool is_user_code () const { return false; }
538 
539  virtual bool is_builtin_function () const { return false; }
540 
541  virtual bool is_dld_function () const { return false; }
542 
543  virtual bool is_mex_function () const { return false; }
544 
545  virtual bool is_function_cache () const { return false; }
546 
547  // Checks if the ov could be a function. If it is undefined,
548  // the name associated with the ov could be a function to call.
549  virtual bool is_maybe_function () const
550  { return !is_defined () || is_function (); }
551 
552  virtual bool has_function_cache () const { return false; }
553 
554  virtual octave_function * get_cached_fcn (const octave_value_list&) { return nullptr; }
555 
556  virtual octave_function * get_cached_fcn (void*, void*) { return nullptr; }
557 
558  virtual void erase_subfunctions () { }
559 
560  virtual short int short_value (bool = false, bool = false) const;
561 
562  virtual unsigned short int ushort_value (bool = false, bool = false) const;
563 
564  virtual int int_value (bool = false, bool = false) const;
565 
566  virtual unsigned int uint_value (bool = false, bool = false) const;
567 
568  virtual int nint_value (bool = false) const;
569 
570  virtual long int long_value (bool = false, bool = false) const;
571 
572  virtual unsigned long int ulong_value (bool = false, bool = false) const;
573 
574  virtual int64_t int64_value (bool = false, bool = false) const;
575 
576  virtual uint64_t uint64_value (bool = false, bool = false) const;
577 
578  virtual double double_value (bool = false) const;
579 
580  virtual float float_value (bool = false) const;
581 
582  virtual double scalar_value (bool frc_str_conv = false) const
583  { return double_value (frc_str_conv); }
584 
585  virtual float float_scalar_value (bool frc_str_conv = false) const
586  { return float_value (frc_str_conv); }
587 
588  virtual Cell cell_value () const;
589 
590  virtual Matrix matrix_value (bool = false) const;
591 
592  virtual FloatMatrix float_matrix_value (bool = false) const;
593 
594  virtual NDArray array_value (bool = false) const;
595 
596  virtual FloatNDArray float_array_value (bool = false) const;
597 
598  virtual Complex complex_value (bool = false) const;
599 
600  virtual FloatComplex float_complex_value (bool = false) const;
601 
602  virtual ComplexMatrix complex_matrix_value (bool = false) const;
603 
604  virtual FloatComplexMatrix float_complex_matrix_value (bool = false) const;
605 
606  virtual ComplexNDArray complex_array_value (bool = false) const;
607 
608  virtual FloatComplexNDArray float_complex_array_value (bool = false) const;
609 
610  virtual bool bool_value (bool = false) const;
611 
612  virtual boolMatrix bool_matrix_value (bool = false) const;
613 
614  virtual boolNDArray bool_array_value (bool = false) const;
615 
616  virtual charMatrix char_matrix_value (bool force = false) const;
617 
618  virtual charNDArray char_array_value (bool = false) const;
619 
620  virtual SparseMatrix sparse_matrix_value (bool = false) const;
621 
622  virtual SparseComplexMatrix sparse_complex_matrix_value (bool = false) const;
623 
624  virtual SparseBoolMatrix sparse_bool_matrix_value (bool = false) const;
625 
626  virtual DiagMatrix diag_matrix_value (bool = false) const;
627 
628  virtual FloatDiagMatrix float_diag_matrix_value (bool = false) const;
629 
630  virtual ComplexDiagMatrix complex_diag_matrix_value (bool = false) const;
631 
632  virtual FloatComplexDiagMatrix
633  float_complex_diag_matrix_value (bool = false) const;
634 
635  virtual PermMatrix perm_matrix_value () const;
636 
637  virtual octave_int8 int8_scalar_value () const;
638 
639  virtual octave_int16 int16_scalar_value () const;
640 
641  virtual octave_int32 int32_scalar_value () const;
642 
643  virtual octave_int64 int64_scalar_value () const;
644 
645  virtual octave_uint8 uint8_scalar_value () const;
646 
647  virtual octave_uint16 uint16_scalar_value () const;
648 
649  virtual octave_uint32 uint32_scalar_value () const;
650 
651  virtual octave_uint64 uint64_scalar_value () const;
652 
653  virtual int8NDArray int8_array_value () const;
654 
655  virtual int16NDArray int16_array_value () const;
656 
657  virtual int32NDArray int32_array_value () const;
658 
659  virtual int64NDArray int64_array_value () const;
660 
661  virtual uint8NDArray uint8_array_value () const;
662 
663  virtual uint16NDArray uint16_array_value () const;
664 
665  virtual uint32NDArray uint32_array_value () const;
666 
667  virtual uint64NDArray uint64_array_value () const;
668 
669  virtual string_vector string_vector_value (bool pad = false) const;
670 
671  virtual std::string string_value (bool force = false) const;
672 
673  virtual Array<std::string> cellstr_value () const;
674 
675  virtual octave::range<double> range_value () const;
676 
677  // For now, enable only range<double>.
678 
679  virtual octave_map map_value () const;
680 
681  virtual octave_scalar_map scalar_map_value () const;
682 
683  virtual string_vector map_keys () const;
684 
685  virtual bool isfield (const std::string&) const;
686 
687  virtual std::size_t nparents () const;
688 
689  virtual std::list<std::string> parent_class_name_list () const;
690 
691  virtual string_vector parent_class_names () const;
692 
693  virtual octave_base_value * find_parent_class (const std::string&)
694  { return nullptr; }
695 
696  virtual octave_base_value * unique_parent_class (const std::string&)
697  { return nullptr; }
698 
699  virtual bool is_instance_of (const std::string&) const
700  { return false; }
701 
702  virtual octave_classdef * classdef_object_value (bool silent = false);
703 
704  virtual octave_function * function_value (bool silent = false);
705 
706  virtual octave_user_function * user_function_value (bool silent = false);
707 
708  virtual octave_user_script * user_script_value (bool silent = false);
709 
710  virtual octave_user_code * user_code_value (bool silent = false);
711 
712  virtual octave_fcn_handle * fcn_handle_value (bool silent = false);
713 
714  virtual octave_value_list list_value () const;
715 
716  virtual octave_value convert_to_str (bool pad = false, bool force = false,
717  char type = '\'') const;
718  virtual octave_value
719  convert_to_str_internal (bool pad, bool force, char type) const;
720 
721  virtual void convert_to_row_or_column_vector ();
722 
723  // The following extractor functions don't perform any implicit type
724  // conversions.
725 
726  virtual std::string xstring_value () const;
727 
728  virtual bool print_as_scalar () const { return false; }
729 
730  virtual void print (std::ostream& os, bool pr_as_read_syntax = false);
731 
732  virtual void
733  print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
734 
735  virtual bool
736  print_name_tag (std::ostream& os, const std::string& name) const;
737 
738  virtual void
739  print_with_name (std::ostream& output_buf, const std::string& name,
740  bool print_padding = true);
741 
742  virtual void short_disp (std::ostream& os) const { os << "..."; }
743 
745 
746  virtual std::string edit_display (const float_display_format&,
748  { return "#VAL"; }
749 
750  virtual void print_info (std::ostream& os, const std::string& prefix) const;
751 
752  virtual bool save_ascii (std::ostream& os);
753 
754  virtual bool load_ascii (std::istream& is);
755 
756  virtual bool save_binary (std::ostream& os, bool save_as_floats);
757 
758  virtual bool load_binary (std::istream& is, bool swap,
760 
761  virtual bool
762  save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
763 
764  virtual bool
765  load_hdf5 (octave_hdf5_id loc_id, const char *name);
766 
767  virtual int
768  write (octave::stream& os, int block_size,
769  oct_data_conv::data_type output_type, int skip,
770  octave::mach_info::float_format flt_fmt) const;
771 
772  virtual const void * mex_get_data () const { return nullptr; }
773 
774  virtual const octave_idx_type * mex_get_ir () const { return nullptr; }
775 
776  virtual const octave_idx_type * mex_get_jc () const { return nullptr; }
777 
778  virtual mxArray * as_mxArray (bool interleaved) const;
779 
780  virtual octave_value diag (octave_idx_type k = 0) const;
781 
783 
784  virtual octave_value sort (octave_idx_type dim = 0,
785  sortmode mode = ASCENDING) const;
787  octave_idx_type dim = 0,
788  sortmode mode = ASCENDING) const;
789 
790  virtual sortmode issorted (sortmode mode = UNSORTED) const;
791 
792  virtual Array<octave_idx_type>
793  sort_rows_idx (sortmode mode = ASCENDING) const;
794 
795  virtual sortmode is_sorted_rows (sortmode mode = UNSORTED) const;
796 
797  virtual void lock ();
798 
799  virtual void unlock ();
800 
801  virtual bool islocked () const { return false; }
802 
803  virtual void call_object_destructor () { }
804 
805  virtual void maybe_call_dtor () { }
806 
807  virtual octave_value dump () const;
808 
809  virtual octave_value storable_value ();
810 
812 
813  // Standard mappers. Register new ones here.
815  {
877  num_unary_mappers = umap_unknown
878  };
879 
880  virtual octave_value map (unary_mapper_t) const;
881 
882  // These are fast indexing & assignment shortcuts for extracting
883  // or inserting a single scalar from/to an array.
884 
885  // Extract the n-th element, aka val(n). Result is undefined if val is not
886  // an array type or n is out of range. Never error.
887  virtual octave_value
889 
890  // Assign the n-th element, aka val(n) = x. Returns false if val is not an
891  // array type, x is not a matching scalar type, or n is out of range.
892  // Never error.
893  virtual bool
895 
896  // This is a helper for the above, to be overridden in scalar types. The
897  // whole point is to handle the insertion efficiently with just *two* VM
898  // calls, which is basically the theoretical minimum.
899  virtual bool
900  fast_elem_insert_self (void *where, builtin_type_t btyp) const;
901 
902 protected:
903 
904  // This should only be called for derived types.
905 
906  OCTINTERP_API octave_value
907  numeric_assign (const std::string& type,
908  const std::list<octave_value_list>& idx,
909  const octave_value& rhs);
910 
911  void reset_indent_level () const
912  { s_curr_print_indent_level = 0; }
913 
915  { s_curr_print_indent_level += 2; }
916 
918  { s_curr_print_indent_level -= 2; }
919 
921  { return s_curr_print_indent_level; }
922 
923  OCTINTERP_API void indent (std::ostream& os) const;
924 
925  OCTINTERP_API void newline (std::ostream& os) const;
926 
927  OCTINTERP_API void reset () const;
928 
929  // A reference count.
930  // NOTE: the declaration is octave_idx_type because with 64-bit indexing,
931  // it is well possible to have more than MAX_INT copies of a single value
932  // (think of an empty cell array with >2G elements).
933  octave::refcount<octave_idx_type> m_count;
934 
935  // FIXME: Create an alias "count" to the real member variable m_count.
936  // This name is deprecated in Octave 9 and will be removed in Octave 11.
937  OCTAVE_DEPRECATED (9, "use octave_base_value::m_count instead")
939 
940  OCTINTERP_API static const char * get_umap_name (unary_mapper_t);
941 
942  OCTINTERP_API void warn_load (const char *type) const;
943  OCTINTERP_API void warn_save (const char *type) const;
944 
945 private:
946 
947  OCTINTERP_API void wrong_type_arg_error () const;
948 
949  //--------
950 
951  static int s_curr_print_indent_level;
952  static bool s_beginning_of_line;
953 
955 };
956 
957 class
958 OCTINTERP_API
960 {
961 public:
962 
963  octave_base_dld_value () = default;
964 
966  {
967  m_containing_dynamic_library.delete_later ();
968  }
969 
971 
972 private:
973 
974  octave::auto_shlib m_containing_dynamic_library;
975 };
976 
977 OCTAVE_DEPRECATED (8, "Vsparse_auto_mutate is obsolete and is now always false")
978 extern OCTINTERP_API bool Vsparse_auto_mutate;
979 
980 // Utility function to convert C++ arguments used in subsref/subsasgn into an
981 // octave_value_list object that can be used to call a function/method in the
982 // interpreter.
983 extern OCTINTERP_API octave_value
984 make_idx_args (const std::string& type,
985  const std::list<octave_value_list>& idx,
986  const std::string& who);
987 
988 // Tells whether some regular octave_value_base methods are being called from
989 // within the "builtin" function.
990 extern OCTINTERP_API bool called_from_builtin ();
991 
992 #endif
Definition: Cell.h:43
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
Definition: dim-vector.h:335
octave_idx_type ndims() const
Number of dimensions.
Definition: dim-vector.h:257
bool zero_by_zero() const
Definition: dim-vector.h:311
octave_base_dld_value()=default
octave_base_dld_value(const octave_base_dld_value &)=default
type_conv_info(type_conv_fcn f=nullptr, int t=-1)
Definition: ov-base.h:254
virtual bool islocked() const
Definition: ov-base.h:801
virtual bool is_uint32_type() const
Definition: ov-base.h:493
octave_idx_type rows() const
Definition: ov-base.h:374
virtual bool is_uint8_type() const
Definition: ov-base.h:489
virtual bool is_function_handle() const
Definition: ov-base.h:525
virtual bool is_mex_function() const
Definition: ov-base.h:543
virtual bool is_classdef_superclass_ref() const
Definition: ov-base.h:455
virtual bool is_package() const
Definition: ov-base.h:459
octave_idx_type columns() const
Definition: ov-base.h:381
virtual void short_disp(std::ostream &os) const
Definition: ov-base.h:742
virtual octave_idx_type numel() const
Definition: ov-base.h:391
virtual octave_base_value * clone() const
Definition: ov-base.h:279
virtual bool is_scalar_type() const
Definition: ov-base.h:507
virtual bool is_double_type() const
Definition: ov-base.h:475
virtual builtin_type_t builtin_type() const
Definition: ov-base.h:473
virtual bool is_range() const
Definition: ov-base.h:447
virtual bool islogical() const
Definition: ov-base.h:497
virtual bool is_uint16_type() const
Definition: ov-base.h:491
virtual int ndims() const
Definition: ov-base.h:388
virtual bool is_constant() const
Definition: ov-base.h:523
void increment_indent_level() const
Definition: ov-base.h:914
virtual bool is_full_num_matrix() const
Definition: ov-base.h:511
int current_print_indent_level() const
Definition: ov-base.h:920
virtual bool is_maybe_function() const
Definition: ov-base.h:549
virtual bool is_int16_type() const
Definition: ov-base.h:483
bool is_zero_by_zero() const
Definition: ov-base.h:419
virtual bool isreal() const
Definition: ov-base.h:501
virtual const void * mex_get_data() const
Definition: ov-base.h:772
virtual octave_base_value * unique_parent_class(const std::string &)
Definition: ov-base.h:696
virtual bool is_real_matrix() const
Definition: ov-base.h:427
virtual type_conv_info numeric_demotion_function() const
Definition: ov-base.h:298
virtual bool is_true() const
Definition: ov-base.h:517
virtual bool is_legacy_object() const
Definition: ov-base.h:415
virtual bool is_magic_int() const
Definition: ov-base.h:519
virtual const octave_idx_type * mex_get_jc() const
Definition: ov-base.h:776
virtual float float_scalar_value(bool frc_str_conv=false) const
Definition: ov-base.h:585
virtual bool is_anonymous_function() const
Definition: ov-base.h:527
virtual bool is_char_matrix() const
Definition: ov-base.h:437
virtual bool is_user_code() const
Definition: ov-base.h:537
virtual bool is_classdef_meta() const
Definition: ov-base.h:453
virtual bool iscell() const
Definition: ov-base.h:421
virtual void maybe_economize()
Definition: ov-base.h:326
virtual bool isobject() const
Definition: ov-base.h:451
virtual octave_base_value * unique_clone()
Definition: ov-base.h:289
virtual bool is_user_function() const
Definition: ov-base.h:535
virtual bool is_function() const
Definition: ov-base.h:531
virtual void assign(const std::string &, const octave_value &)
Definition: ov-base.h:354
virtual bool isstruct() const
Definition: ov-base.h:449
virtual bool issparse() const
Definition: ov-base.h:515
virtual void maybe_call_dtor()
Definition: ov-base.h:805
virtual bool isfloat() const
Definition: ov-base.h:479
virtual std::string edit_display(const float_display_format &, octave_idx_type, octave_idx_type) const
Definition: ov-base.h:746
virtual bool iscomplex() const
Definition: ov-base.h:503
void reset_indent_level() const
Definition: ov-base.h:911
virtual bool is_real_scalar() const
Definition: ov-base.h:425
virtual bool iscellstr() const
Definition: ov-base.h:423
octave::refcount< octave_idx_type > m_count
Definition: ov-base.h:933
virtual type_conv_info numeric_conversion_function() const
Definition: ov-base.h:294
virtual bool is_bool_matrix() const
Definition: ov-base.h:435
virtual bool is_int64_type() const
Definition: ov-base.h:487
virtual bool is_classdef_object() const
Definition: ov-base.h:457
virtual bool is_perm_matrix() const
Definition: ov-base.h:441
virtual bool is_bool_scalar() const
Definition: ov-base.h:433
virtual octave_function * get_cached_fcn(const octave_value_list &)
Definition: ov-base.h:554
virtual bool is_string() const
Definition: ov-base.h:443
virtual bool is_user_script() const
Definition: ov-base.h:533
virtual dim_vector dims() const
Definition: ov-base.h:372
virtual octave_function * get_cached_fcn(void *, void *)
Definition: ov-base.h:556
virtual bool is_diag_matrix() const
Definition: ov-base.h:439
virtual bool isnull() const
Definition: ov-base.h:521
virtual bool is_builtin_function() const
Definition: ov-base.h:539
virtual ~octave_base_value()=default
virtual bool is_magic_colon() const
Definition: ov-base.h:465
virtual bool is_sq_string() const
Definition: ov-base.h:445
void decrement_indent_level() const
Definition: ov-base.h:917
bool isempty() const
Definition: ov-base.h:417
octave_base_value(const octave_base_value &)
Definition: ov-base.h:273
virtual bool isnumeric() const
Definition: ov-base.h:513
virtual bool print_as_scalar() const
Definition: ov-base.h:728
virtual std::size_t byte_size() const
Definition: ov-base.h:393
virtual bool is_dld_function() const
Definition: ov-base.h:541
virtual bool isjava() const
Definition: ov-base.h:461
virtual octave_base_value * try_narrowing_conversion()
Definition: ov-base.h:323
virtual double scalar_value(bool frc_str_conv=false) const
Definition: ov-base.h:582
virtual octave_base_value * find_parent_class(const std::string &)
Definition: ov-base.h:693
virtual bool is_int8_type() const
Definition: ov-base.h:481
virtual void erase_subfunctions()
Definition: ov-base.h:558
virtual bool is_uint64_type() const
Definition: ov-base.h:495
virtual bool is_inline_function() const
Definition: ov-base.h:529
virtual bool is_instance_of(const std::string &) const
Definition: ov-base.h:699
virtual bool is_int32_type() const
Definition: ov-base.h:485
virtual bool is_storable() const
Definition: ov-base.h:413
virtual bool is_defined() const
Definition: ov-base.h:411
virtual bool is_function_cache() const
Definition: ov-base.h:545
virtual void call_object_destructor()
Definition: ov-base.h:803
virtual bool is_single_type() const
Definition: ov-base.h:477
virtual void break_closure_cycles(const std::shared_ptr< octave::stack_frame > &)
Definition: ov-base.h:291
virtual bool is_complex_matrix() const
Definition: ov-base.h:431
virtual bool has_function_cache() const
Definition: ov-base.h:552
virtual bool is_all_va_args() const
Definition: ov-base.h:467
virtual const octave_idx_type * mex_get_ir() const
Definition: ov-base.h:774
virtual bool isinteger() const
Definition: ov-base.h:499
virtual bool is_cs_list() const
Definition: ov-base.h:463
virtual bool is_complex_scalar() const
Definition: ov-base.h:429
virtual bool is_matrix_type() const
Definition: ov-base.h:509
bool isfield(const std::string &field_name) const
Definition: ov.h:997
octave_value as_uint64() const
Definition: ov.h:456
octave_value_list list_value() const
uint64_t uint64_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:835
octave_int8 int8_scalar_value() const
Definition: ov.h:926
void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition: ov.h:1324
boolNDArray bool_array_value(bool warn=false) const
Definition: ov.h:891
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:900
octave_value simple_subsasgn(char type, octave_value_list &idx, const octave_value &rhs)
Definition: ov.h:518
octave_uint64 uint64_scalar_value() const
Definition: ov.h:947
bool bool_value(bool warn=false) const
Definition: ov.h:885
octave_base_value * clone() const
octave_value convert_to_str_internal(bool pad, bool force, char type) const
Definition: ov.h:1312
octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov.h:476
octave_uint16 uint16_scalar_value() const
Definition: ov.h:941
charMatrix char_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:894
octave_value as_int32() const
Definition: ov.h:450
int32NDArray int32_array_value() const
Definition: ov.h:956
uint16NDArray uint16_array_value() const
Definition: ov.h:965
DiagMatrix diag_matrix_value(bool force=false) const
Definition: ov.h:910
bool fast_elem_insert(octave_idx_type n, const octave_value &x)
Assign the n-th element, aka 'val(n) = x'.
Definition: ov.h:1536
octave_value as_int8() const
Definition: ov.h:448
int16NDArray int16_array_value() const
Definition: ov.h:953
Cell cell_value() const
octave_user_function * user_function_value(bool silent=false) const
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:812
void print_with_name(std::ostream &os, const std::string &name) const
Definition: ov.h:1330
int8NDArray int8_array_value() const
Definition: ov.h:950
octave_int64 int64_scalar_value() const
Definition: ov.h:935
octave::idx_vector index_vector(bool require_integers=false) const
Definition: ov.h:534
int64_t int64_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:831
octave::range< double > range_value() const
Definition: ov.h:985
short int short_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:805
octave_scalar_map scalar_map_value() const
octave_idx_type nzmax() const
Definition: ov.h:567
octave_value permute(const Array< int > &vec, bool inv=false) const
Definition: ov.h:574
FloatDiagMatrix float_diag_matrix_value(bool force=false) const
Definition: ov.h:913
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:871
octave_value_list simple_subsref(char type, octave_value_list &idx, int nargout)
void lock()
Definition: ov.h:1431
bool load_binary(std::istream &is, bool swap, octave::mach_info::float_format fmt)
octave_value dump() const
Definition: ov.h:1439
Complex complex_value(bool frc_str_conv=false) const
Definition: ov.h:865
FloatComplexDiagMatrix float_complex_diag_matrix_value(bool force=false) const
Definition: ov.h:920
octave_value undef_subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_value as_uint8() const
Definition: ov.h:453
unsigned short int ushort_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:809
Matrix size()
Definition: ov.h:462
bool save_hdf5(octave_hdf5_id loc_id, const char *name, bool save_as_floats)
Definition: ov.h:1376
MatrixType matrix_type() const
Definition: ov.h:583
octave_value sort(octave_idx_type dim=0, sortmode mode=ASCENDING) const
Definition: ov.h:1416
octave_value as_int16() const
Definition: ov.h:449
octave_user_code * user_code_value(bool silent=false) const
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:878
string_vector parent_class_names() const
Definition: ov.h:1006
octave_value as_single() const
Definition: ov.h:446
bool is_defined() const
Definition: ov.h:592
bool save_binary(std::ostream &os, bool save_as_floats)
Definition: ov.h:1370
charNDArray char_array_value(bool frc_str_conv=false) const
Definition: ov.h:897
void make_storable_value()
octave_uint32 uint32_scalar_value() const
Definition: ov.h:944
bool save_ascii(std::ostream &os)
Definition: ov.h:1366
string_vector map_keys() const
Definition: ov.h:994
bool is_function() const
Definition: ov.h:777
FloatComplex float_complex_value(bool frc_str_conv=false) const
Definition: ov.h:868
std::size_t nparents() const
Definition: ov.h:1000
octave_idx_type xnumel(const octave_value_list &idx)
Definition: ov.h:467
octave_value storable_value() const
float_display_format get_edit_display_format() const
octave_value as_uint32() const
Definition: ov.h:455
uint64NDArray uint64_array_value() const
Definition: ov.h:971
float float_value(bool frc_str_conv=false) const
Definition: ov.h:844
bool load_hdf5(octave_hdf5_id loc_id, const char *name)
octave_function * function_value(bool silent=false) const
unsigned long int ulong_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:827
octave_value any(int dim=0) const
Definition: ov.h:687
octave_idx_type nfields() const
Definition: ov.h:569
octave_value reshape(const dim_vector &dv) const
Definition: ov.h:571
bool load_ascii(std::istream &is)
octave_map map_value() const
void convert_to_row_or_column_vector()
Definition: ov.h:1315
octave_fcn_handle * fcn_handle_value(bool silent=false) const
boolMatrix bool_matrix_value(bool warn=false) const
Definition: ov.h:888
octave_idx_type nnz() const
Definition: ov.h:565
octave_value fast_elem_extract(octave_idx_type n) const
Extract the n-th element, aka 'val(n)'.
Definition: ov.h:1524
std::string string_value(bool force=false) const
Definition: ov.h:974
ComplexDiagMatrix complex_diag_matrix_value(bool force=false) const
Definition: ov.h:916
octave_uint8 uint8_scalar_value() const
Definition: ov.h:938
int nint_value(bool frc_str_conv=false) const
Definition: ov.h:819
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:856
void print_info(std::ostream &os, const std::string &prefix="") const
octave_value map(octave_base_value::unary_mapper_t umap) const
Definition: ov.h:1513
octave_int16 int16_scalar_value() const
Definition: ov.h:929
octave_base_value * empty_clone() const
Definition: ov.h:337
long int long_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:823
string_vector string_vector_value(bool pad=false) const
Definition: ov.h:977
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
Definition: ov.h:1428
octave_classdef * classdef_object_value(bool silent=false) const
int64NDArray int64_array_value() const
Definition: ov.h:959
SparseBoolMatrix sparse_bool_matrix_value(bool warn=false) const
Definition: ov.h:907
NDArray array_value(bool frc_str_conv=false) const
Definition: ov.h:859
int write(octave::stream &os, int block_size, oct_data_conv::data_type output_type, int skip, octave::mach_info::float_format flt_fmt) const
octave_value as_uint16() const
Definition: ov.h:454
octave_value as_int64() const
Definition: ov.h:451
octave_value as_double() const
Definition: ov.h:445
octave_value convert_to_str(bool pad=false, bool force=false, char type='\'') const
Definition: ov.h:1307
uint8NDArray uint8_array_value() const
Definition: ov.h:962
bool print_name_tag(std::ostream &os, const std::string &name) const
Definition: ov.h:1327
octave_value full_value() const
Definition: ov.h:435
sortmode issorted(sortmode mode=UNSORTED) const
Definition: ov.h:1422
octave_value all(int dim=0) const
Definition: ov.h:684
std::string xstring_value(const char *fmt,...) const
octave_int32 int32_scalar_value() const
Definition: ov.h:932
FloatComplexNDArray float_complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:882
octave_value resize(const dim_vector &dv, bool fill=false) const
Definition: ov.h:580
std::list< std::string > parent_class_name_list() const
Definition: ov.h:1003
FloatNDArray float_array_value(bool frc_str_conv=false) const
Definition: ov.h:862
mxArray * as_mxArray(bool interleaved=false) const
Definition: ov.h:1407
uint32NDArray uint32_array_value() const
Definition: ov.h:968
Matrix matrix_value(bool frc_str_conv=false) const
Definition: ov.h:853
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:875
void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition: ov.h:1321
octave_value diag(octave_idx_type k=0) const
Definition: ov.h:1410
double double_value(bool frc_str_conv=false) const
Definition: ov.h:841
unsigned int uint_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:816
PermMatrix perm_matrix_value() const
Definition: ov.h:923
octave_value as_double_or_copy() const
Definition: ov.h:442
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
Definition: ov.h:904
octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
octave_user_script * user_script_value(bool silent=false) const
Array< std::string > cellstr_value() const
Definition: ov.h:982
dim_vector dims() const
Definition: ov.h:541
void unlock()
Definition: ov.h:1433
Array< octave_idx_type > sort_rows_idx(sortmode mode=ASCENDING) const
Definition: ov.h:1425
octave_value squeeze() const
Definition: ov.h:431
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
octave::idx_vector idx_vector
Definition: idx-vector.h:1022
F77_RET_T const F77_DBLE * x
F77_RET_T const F77_DBLE const F77_DBLE * f
float_format
Definition: mach-info.h:38
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
std::complex< double > Complex
Definition: oct-cmplx.h:33
std::complex< float > FloatComplex
Definition: oct-cmplx.h:34
int64_t octave_hdf5_id
sortmode
Definition: oct-sort.h:97
@ UNSORTED
Definition: oct-sort.h:97
@ ASCENDING
Definition: oct-sort.h:97
bool btyp_isnumeric(builtin_type_t btyp)
Definition: ov-base.h:107
#define DEF_BTYP_TRAITS(BTYP, CLASS)
Definition: ov-base.h:147
bool btyp_isinteger(builtin_type_t btyp)
Definition: ov-base.h:110
bool Vsparse_auto_mutate
Definition: ov-base.cc:104
#define DECLARE_OV_BASE_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:184
octave_value make_idx_args(const std::string &type, const std::list< octave_value_list > &idx, const std::string &who)
Definition: ov-base.cc:1461
type_info & __get_type_info__()
bool btyp_isarray(builtin_type_t btyp)
Definition: ov-base.h:116
std::string btyp_class_name[]
Definition: ov-base.cc:91
bool btyp_isfloat(builtin_type_t btyp)
Definition: ov-base.h:113
builtin_type_t btyp_mixed_numeric(builtin_type_t x, builtin_type_t y)
Determine the resulting type for a possible mixed-type operation.
Definition: ov-base.cc:67
bool called_from_builtin()
Definition: ov-base.cc:1524
builtin_type_t
Definition: ov-base.h:83
@ btyp_float_complex
Definition: ov-base.h:87
@ btyp_cell
Definition: ov-base.h:99
@ btyp_func_handle
Definition: ov-base.h:100
@ btyp_double
Definition: ov-base.h:84
@ btyp_int32
Definition: ov-base.h:90
@ btyp_float
Definition: ov-base.h:85
@ btyp_struct
Definition: ov-base.h:98
@ btyp_uint16
Definition: ov-base.h:93
@ btyp_int64
Definition: ov-base.h:91
@ btyp_bool
Definition: ov-base.h:96
@ btyp_unknown
Definition: ov-base.h:101
@ btyp_uint64
Definition: ov-base.h:95
@ btyp_int16
Definition: ov-base.h:89
@ btyp_uint32
Definition: ov-base.h:94
@ btyp_num_types
Definition: ov-base.h:102
@ btyp_char
Definition: ov-base.h:97
@ btyp_uint8
Definition: ov-base.h:92
@ btyp_int8
Definition: ov-base.h:88
@ btyp_complex
Definition: ov-base.h:86
static const builtin_type_t btyp
Definition: ov-base.h:138