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