GNU Octave 7.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-2022 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
48OCTINTERP_API
50{
51public:
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 (void) = default;
65
66 octave_value squeeze (void) const { return scalar; }
67
68 octave_value full_value (void) 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 (void) const { return true; }
87
88 bool is_defined (void) const { return true; }
89
90 OCTINTERP_API dim_vector dims (void) const;
91
92 octave_idx_type numel (void) const { return 1; }
93
94 int ndims (void) const { return 2; }
95
96 octave_idx_type nnz (void) 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 (void) 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_scalar_type (void) const { return true; }
139
140 bool isnumeric (void) const { return true; }
141
142 OCTINTERP_API bool is_true (void) const;
143
144 OCTINTERP_API void print (std::ostream& os, bool pr_as_read_syntax = false);
145
146 OCTINTERP_API void
147 print_raw (std::ostream& os, bool pr_as_read_syntax = false) const;
148
149 OCTINTERP_API bool
150 print_name_tag (std::ostream& os, const std::string& name) const;
151
152 OCTINTERP_API void short_disp (std::ostream& os) const;
153
154 OCTINTERP_API float_display_format get_edit_display_format (void) const;
155
156 OCTINTERP_API std::string
157 edit_display (const float_display_format& fmt,
159
160 // This function exists to support the MEX interface.
161 // You should not use it anywhere else.
162 const void * mex_get_data (void) const { return &scalar; }
163
164 const ST& scalar_ref (void) const { return scalar; }
165
166 ST& scalar_ref (void) { return scalar; }
167
168 OCTINTERP_API octave_value fast_elem_extract (octave_idx_type n) const;
169
170 OCTINTERP_API bool
171 fast_elem_insert_self (void *where, builtin_type_t btyp) const;
172
173protected:
174
175 // The value of this scalar.
177};
178
179#endif
OCTARRAY_API void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
Definition: Array.cc:1010
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:94
bool is_scalar_type(void) const
const void * mex_get_data(void) const
octave_base_scalar(const ST &s)
octave_idx_type nnz(void) const
bool isnumeric(void) const
octave_base_scalar(const octave_base_scalar &s)
bool is_constant(void) const
octave_value squeeze(void) const
int ndims(void) const
const ST & scalar_ref(void) const
MatrixType matrix_type(const MatrixType &) const
sortmode is_sorted_rows(sortmode mode=UNSORTED) const
~octave_base_scalar(void)=default
Array< octave_idx_type > sort_rows_idx(sortmode) const
octave_value any(int=0) const
octave_value sort(octave_idx_type, sortmode) const
octave_idx_type numel(void) const
std::size_t byte_size(void) const
octave_value sort(Array< octave_idx_type > &sidx, octave_idx_type, sortmode) const
sortmode issorted(sortmode mode=UNSORTED) const
MatrixType matrix_type(void) const
octave_value full_value(void) const
bool is_defined(void) 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:201
QString name
bool is_true(const std::string &s)
static float_display_format get_edit_display_format(const octave_value &val)
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:75
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:679