GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-base-scalar.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_scalar_h)
27 #define octave_ov_base_scalar_h 1
28 
29 #include "octave-config.h"
30 
31 #include <cstdlib>
32 
33 #include <iosfwd>
34 #include <string>
35 
36 #include "lo-mappers.h"
37 #include "lo-utils.h"
38 #include "str-vec.h"
39 #include "MatrixType.h"
40 
41 #include "ov-base.h"
42 #include "ov-typeinfo.h"
43 
44 // Real scalar values.
45 
46 template <typename ST>
47 class
48 OCTINTERP_API
50 {
51 public:
52 
53  typedef ST scalar_type;
54 
56  : octave_base_value (), scalar () { }
57 
58  octave_base_scalar (const ST& s)
59  : octave_base_value (), scalar (s) { }
60 
62  : octave_base_value (), scalar (s.scalar) { }
63 
64  ~octave_base_scalar () = default;
65 
66  octave_value squeeze () const { return scalar; }
67 
68  octave_value full_value () const { return scalar; }
69 
70  // We don't need to override all three forms of subsref. The using
71  // declaration will avoid warnings about partially-overloaded virtual
72  // functions.
74 
75  OCTINTERP_API octave_value
76  subsref (const std::string& type, const std::list<octave_value_list>& idx);
77 
78  octave_value_list subsref (const std::string& type,
79  const std::list<octave_value_list>& idx, int)
80  { return subsref (type, idx); }
81 
82  OCTINTERP_API octave_value
83  subsasgn (const std::string& type, const std::list<octave_value_list>& idx,
84  const octave_value& rhs);
85 
86  bool is_constant () const { return true; }
87 
88  bool is_defined () const { return true; }
89 
90  OCTINTERP_API dim_vector dims () const;
91 
92  octave_idx_type numel () const { return 1; }
93 
94  int ndims () const { return 2; }
95 
96  octave_idx_type nnz () const { return (scalar != ST () ? 1 : 0); }
97 
98  OCTINTERP_API octave_value permute (const Array<int>&, bool = false) const;
99 
100  OCTINTERP_API octave_value reshape (const dim_vector& new_dims) const;
101 
102  std::size_t byte_size () const { return sizeof (ST); }
103 
104  octave_value all (int = 0) const { return (scalar != ST ()); }
105 
106  octave_value any (int = 0) const { return (scalar != ST ()); }
107 
108  OCTINTERP_API octave_value diag (octave_idx_type k = 0) const;
109 
110  OCTINTERP_API octave_value diag (octave_idx_type m, octave_idx_type n) const;
111 
113  { return octave_value (scalar); }
115  sortmode) const
116  {
117  sidx.resize (dim_vector (1, 1));
118  sidx(0) = 0;
119  return octave_value (scalar);
120  }
121 
123  { return mode == UNSORTED ? ASCENDING : mode; }
124 
126  {
127  return Array<octave_idx_type> (dim_vector (1, 1),
128  static_cast<octave_idx_type> (0));
129  }
130 
132  { return mode == UNSORTED ? ASCENDING : mode; }
133 
136  { return matrix_type (); }
137 
138  bool is_maybe_function () const { return false; }
139 
140  bool is_scalar_type () const { return true; }
141 
142  bool isnumeric () const { return true; }
143 
144  OCTINTERP_API bool is_true () const;
145 
146  OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false);
147 
148  OCTINTERP_API void
149  print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
150 
151  OCTINTERP_API bool
152  print_name_tag (std::ostream& os, const std::string& name) const;
153 
154  OCTINTERP_API void short_disp (std::ostream& os) const;
155 
156  OCTINTERP_API float_display_format get_edit_display_format () const;
157 
158  OCTINTERP_API std::string
159  edit_display (const float_display_format& fmt,
160  octave_idx_type i, octave_idx_type j) const;
161 
162  // This function exists to support the MEX interface.
163  // You should not use it anywhere else.
164  const void * mex_get_data () const { return &scalar; }
165 
166  const ST& scalar_ref () const { return scalar; }
167 
168  ST& scalar_ref () { return scalar; }
169 
170  OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const;
171 
172  OCTINTERP_API bool
173  fast_elem_insert_self (void *where, builtin_type_t btyp) const;
174 
175 protected:
176 
177  // The value of this scalar.
178  ST scalar;
179 };
180 
181 #endif
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array-base.cc:1023
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
octave_base_scalar(const ST &s)
Array< octave_idx_type > sort_rows_idx(sortmode) const
octave_idx_type nnz() const
octave_base_scalar(const octave_base_scalar &s)
std::size_t byte_size() const
~octave_base_scalar()=default
MatrixType matrix_type(const MatrixType &) const
bool is_scalar_type() const
MatrixType matrix_type() const
octave_value full_value() const
const void * mex_get_data() const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
bool is_constant() const
octave_value any(int=0) const
bool isnumeric() const
octave_value sort(octave_idx_type, sortmode) const
bool is_maybe_function() const
octave_value squeeze() const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
const ST & scalar_ref() const
sortmode issorted(sortmode mode=UNSORTED) const
bool is_defined() const
octave_idx_type numel() const
octave_value all(int=0) const
octave_value_list subsref(const std::string &type, const std::list< octave_value_list > &idx, int)
virtual octave_value subsref(const std::string &type, const std::list< octave_value_list > &idx)
Definition: ov-base.cc:248
bool is_true(const std::string &s)
Definition: mkoctfile.cc:604
T octave_idx_type m
Definition: mx-inlines.cc:781
octave_idx_type n
Definition: mx-inlines.cc:761
sortmode
Definition: oct-sort.h:97
@ UNSORTED
Definition: oct-sort.h:97
@ ASCENDING
Definition: oct-sort.h:97
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
builtin_type_t
Definition: ov-base.h:83