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-scalar.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_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
46template <typename ST>
47class OCTINTERP_API octave_base_scalar : public octave_base_value
48{
49public:
50
51 typedef ST scalar_type;
52
53 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_scalar ()
54 : octave_base_value (), scalar () { }
55
56 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_scalar (const ST& s)
57 : octave_base_value (), scalar (s) { }
58
59 OCTINTERP_OVERRIDABLE_FUNC_API octave_base_scalar (const octave_base_scalar& s)
60 : octave_base_value (), scalar (s.scalar) { }
61
62 OCTINTERP_OVERRIDABLE_FUNC_API ~octave_base_scalar () = default;
63
64 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
65 squeeze () const { return scalar; }
66
67 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
68 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 OCTINTERP_OVERRIDABLE_FUNC_API octave_value_list
79 subsref (const std::string& type, 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 OCTINTERP_OVERRIDABLE_FUNC_API bool is_constant () const { return true; }
87
88 OCTINTERP_OVERRIDABLE_FUNC_API bool is_defined () const { return true; }
89
90 OCTINTERP_API dim_vector dims () const;
91
92 OCTINTERP_OVERRIDABLE_FUNC_API octave_idx_type numel () const { return 1; }
93
94 OCTINTERP_OVERRIDABLE_FUNC_API int ndims () const { return 2; }
95
96 OCTINTERP_OVERRIDABLE_FUNC_API octave_idx_type
97 nnz () const { return (scalar != ST () ? 1 : 0); }
98
99 OCTINTERP_API octave_value permute (const Array<int>&, bool = false) const;
100
101 OCTINTERP_API octave_value reshape (const dim_vector& new_dims) const;
102
103 OCTINTERP_OVERRIDABLE_FUNC_API std::size_t
104 byte_size () const { return sizeof (ST); }
105
106 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
107 all (int = 0) const { return (scalar != ST ()); }
108
109 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
110 any (int = 0) const { return (scalar != ST ()); }
111
112 OCTINTERP_API octave_value diag (octave_idx_type k = 0) const;
113
114 OCTINTERP_API octave_value diag (octave_idx_type m, octave_idx_type n) const;
115
116 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
118 { return octave_value (scalar); }
119
120 OCTINTERP_OVERRIDABLE_FUNC_API octave_value
122 {
123 sidx.resize (dim_vector (1, 1));
124 sidx(0) = 0;
125 return octave_value (scalar);
126 }
127
128 OCTINTERP_OVERRIDABLE_FUNC_API sortmode
130 { return mode == UNSORTED ? ASCENDING : mode; }
131
132 OCTINTERP_OVERRIDABLE_FUNC_API Array<octave_idx_type>
134 {
135 return Array<octave_idx_type> (dim_vector (1, 1),
136 static_cast<octave_idx_type> (0));
137 }
138
139 OCTINTERP_OVERRIDABLE_FUNC_API sortmode
141 { return mode == UNSORTED ? ASCENDING : mode; }
142
143 OCTINTERP_OVERRIDABLE_FUNC_API MatrixType
144 matrix_type () const
145 { return MatrixType::Diagonal; }
146
147 OCTINTERP_OVERRIDABLE_FUNC_API MatrixType
148 matrix_type (const MatrixType&) const
149 { return matrix_type (); }
150
151 OCTINTERP_OVERRIDABLE_FUNC_API bool
152 is_maybe_function () const { return false; }
153
154 OCTINTERP_OVERRIDABLE_FUNC_API bool
155 is_scalar_type () const { return true; }
156
157 OCTINTERP_OVERRIDABLE_FUNC_API bool
158 isnumeric () const { return true; }
159
160 OCTINTERP_API bool is_true () const;
161
162 OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false);
163
164 OCTINTERP_API void
165 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
166
167 OCTINTERP_API bool
168 print_name_tag (std::ostream& os, const std::string& name) const;
169
170 OCTINTERP_API void short_disp (std::ostream& os) const;
171
172 OCTINTERP_API float_display_format get_edit_display_format () const;
173
174 OCTINTERP_API std::string
177
178 // This function exists to support the MEX interface.
179 // You should not use it anywhere else.
180 OCTINTERP_OVERRIDABLE_FUNC_API const void *
181 mex_get_data () const { return &scalar; }
182
183 OCTINTERP_OVERRIDABLE_FUNC_API const ST& scalar_ref () const
184 { return scalar; }
185
186 OCTINTERP_OVERRIDABLE_FUNC_API ST& scalar_ref ()
187 { return scalar; }
188
189 OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const;
190
191 OCTINTERP_API bool
192 fast_elem_insert_self (void *where, builtin_type_t btyp) const;
193
194protected:
195
196 // The value of this scalar.
198};
199
200#endif
N Dimensional Array with copy-on-write semantics.
Definition Array.h:130
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
octave_base_scalar(const ST &s)
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
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
const ST & scalar_ref() const
Array< octave_idx_type > sort_rows_idx(sortmode) 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
sortmode issorted(sortmode mode=UNSORTED) const
const void * mex_get_data() 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:245
virtual void short_disp(std::ostream &os) const
Definition ov-base.h:761
virtual octave_value fast_elem_extract(octave_idx_type n) const
Definition ov-base.cc:1394
virtual bool print_name_tag(std::ostream &os, const std::string &name) const
Definition ov-base.cc:469
virtual MatrixType matrix_type() const
Definition ov-base.cc:407
virtual octave_value diag(octave_idx_type k=0) const
Definition ov-base.cc:1036
virtual bool is_true() const
Definition ov-base.h:529
virtual octave_value permute(const Array< int > &vec, bool=false) const
Definition ov-base.cc:395
virtual float_display_format get_edit_display_format() const
Definition ov-base.cc:503
virtual std::string edit_display(const float_display_format &, octave_idx_type, octave_idx_type) const
Definition ov-base.h:769
virtual void print_raw(std::ostream &os, bool pr_as_read_syntax=false) const
Definition ov-base.cc:463
virtual octave_value reshape(const dim_vector &) const
Definition ov-base.cc:389
virtual dim_vector dims() const
Definition ov-base.h:382
virtual bool fast_elem_insert_self(void *where, builtin_type_t btyp) const
Definition ov-base.cc:1406
virtual void print(std::ostream &os, bool pr_as_read_syntax=false)
Definition ov-base.cc:457
virtual octave_value subsasgn(const std::string &type, const std::list< octave_value_list > &idx, const octave_value &rhs)
Definition ov-base.cc:294
friend class octave_value
Definition ov-base.h:278
sortmode
Definition oct-sort.h:97
@ UNSORTED
Definition oct-sort.h:97
@ ASCENDING
Definition oct-sort.h:97
builtin_type_t
Definition ov-base.h:83