GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
ov-bool.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_bool_h)
27#define octave_ov_bool_h 1
28
29#include "octave-config.h"
30
31#include <cstdlib>
32
33#include <iosfwd>
34#include <string>
35
36#include "lo-utils.h"
37#include "mx-base.h"
38#include "str-vec.h"
39
40#include "oct-stream.h"
41#include "ov-base.h"
42#include "ov-base-scalar.h"
43#include "ov-bool-mat.h"
44#include "ov-scalar.h"
45#include "ov-typeinfo.h"
46
48
49// Real scalar values.
50
51extern template class OCTINTERP_EXTERN_TEMPLATE_API octave_base_scalar<bool>;
52
53class OCTINTERP_API octave_bool : public octave_base_scalar<bool>
54{
55public:
56
58 : octave_base_scalar<bool> (false) { }
59
60 octave_bool (bool b)
61 : octave_base_scalar<bool> (b) { }
62
65
66 ~octave_bool () = default;
67
68 octave_base_value * clone () const { return new octave_bool (*this); }
70 { return new octave_bool_matrix (); }
71
72 type_conv_info numeric_conversion_function () const;
73
74 octave_value do_index_op (const octave_value_list& idx,
75 bool resize_ok = false);
76
77 octave::idx_vector index_vector (bool /* require_integers */ = false) const
78 { return octave::idx_vector (scalar); }
79
81
82 bool is_real_scalar () const { return true; }
83
84 bool is_bool_scalar () const { return true; }
85
86 bool islogical () const { return true; }
87
88 bool isreal () const { return true; }
89
90 bool isnumeric () const { return false; }
91
92 bool is_true () const { return scalar; }
93
96 { return int8NDArray (dim_vector (1, 1), scalar); }
97
100 { return int16NDArray (dim_vector (1, 1), scalar); }
101
104 { return int32NDArray (dim_vector (1, 1), scalar); }
105
108 { return int64NDArray (dim_vector (1, 1), scalar); }
109
112 { return uint8NDArray (dim_vector (1, 1), scalar); }
113
116 { return uint16NDArray (dim_vector (1, 1), scalar); }
117
120 { return uint32NDArray (dim_vector (1, 1), scalar); }
121
124 { return uint64NDArray (dim_vector (1, 1), scalar); }
125
127 int8_scalar_value () const { return octave_int8 (scalar); }
128
130 int16_scalar_value () const { return octave_int16 (scalar); }
131
133 int32_scalar_value () const { return octave_int32 (scalar); }
134
136 int64_scalar_value () const { return octave_int64 (scalar); }
137
139 uint8_scalar_value () const { return octave_uint8 (scalar); }
140
142 uint16_scalar_value () const { return octave_uint16 (scalar); }
143
145 uint32_scalar_value () const { return octave_uint32 (scalar); }
146
148 uint64_scalar_value () const { return octave_uint64 (scalar); }
149
150 double double_value (bool = false) const { return scalar; }
151
152 float float_value (bool = false) const { return scalar; }
153
154 double scalar_value (bool = false) const { return scalar; }
155
156 float float_scalar_value (bool = false) const { return scalar; }
157
158 Matrix matrix_value (bool = false) const
159 { return Matrix (1, 1, scalar); }
160
161 FloatMatrix float_matrix_value (bool = false) const
162 { return FloatMatrix (1, 1, scalar); }
163
164 NDArray array_value (bool = false) const
165 { return NDArray (dim_vector (1, 1), double_value ()); }
166
167 FloatNDArray float_array_value (bool = false) const
168 { return FloatNDArray (dim_vector (1, 1), float_value ()); }
169
170 Complex complex_value (bool = false) const { return scalar; }
171
172 FloatComplex float_complex_value (bool = false) const { return scalar; }
173
175 { return ComplexMatrix (1, 1, Complex (scalar)); }
176
178 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
179
181 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
182
184 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
185
187 { return SparseMatrix (Matrix (1, 1, scalar)); }
188
189 // FIXME: Need SparseComplexMatrix (Matrix) constructor!
191 { return SparseComplexMatrix (sparse_matrix_value ()); }
192
194 { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); }
195
197 char_array_value (bool = false) const
198 {
199 charNDArray retval (dim_vector (1, 1));
200 retval(0) = static_cast<char> (scalar);
201 return retval;
202 }
203
204 bool bool_value (bool = false) const { return scalar; }
205
206 boolMatrix bool_matrix_value (bool = false) const
207 { return boolMatrix (1, 1, scalar); }
208
209 boolNDArray bool_array_value (bool = false) const
210 { return boolNDArray (dim_vector (1, 1), scalar); }
211
212 octave_value as_double () const;
213 octave_value as_single () const;
214
215 octave_value as_int8 () const;
216 octave_value as_int16 () const;
217 octave_value as_int32 () const;
218 octave_value as_int64 () const;
219
220 octave_value as_uint8 () const;
221 octave_value as_uint16 () const;
222 octave_value as_uint32 () const;
223 octave_value as_uint64 () const;
224
225 octave_value resize (const dim_vector& dv, bool fill = false) const;
226
227 octave_value convert_to_str_internal (bool pad, bool force, char type) const;
228
229 bool save_ascii (std::ostream& os);
230
231 bool load_ascii (std::istream& is);
232
233 bool save_binary (std::ostream& os, bool save_as_floats);
234
235 bool load_binary (std::istream& is, bool swap,
236 octave::mach_info::float_format fmt);
237
238 bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
239
240 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
241
242 int write (octave::stream& os, int block_size,
243 oct_data_conv::data_type output_type, int skip,
244 octave::mach_info::float_format flt_fmt) const
245 {
246 return os.write (bool_array_value (), block_size, output_type,
247 skip, flt_fmt);
248 }
249
250 mxArray * as_mxArray (bool interleaved) const;
251
252 // Mapper functions are converted to double for treatment
254 {
255 octave_scalar m (scalar_value ());
256 return m.map (umap);
257 }
258
259private:
260
262};
263
264#endif
Vector representing the dimensions (size) of an Array.
Definition dim-vector.h:90
octave_uint16 uint16_scalar_value() const
Definition ov-bool.h:142
octave_bool(const octave_bool &s)
Definition ov-bool.h:63
octave::idx_vector index_vector(bool=false) const
Definition ov-bool.h:77
uint32NDArray uint32_array_value() const
Definition ov-bool.h:119
octave_base_value * empty_clone() const
Definition ov-bool.h:69
charNDArray char_array_value(bool=false) const
Definition ov-bool.h:197
FloatComplex float_complex_value(bool=false) const
Definition ov-bool.h:172
ComplexMatrix complex_matrix_value(bool=false) const
Definition ov-bool.h:174
octave_bool()
Definition ov-bool.h:57
bool isreal() const
Definition ov-bool.h:88
octave_int8 int8_scalar_value() const
Definition ov-bool.h:127
float float_value(bool=false) const
Definition ov-bool.h:152
Matrix matrix_value(bool=false) const
Definition ov-bool.h:158
octave_uint64 uint64_scalar_value() const
Definition ov-bool.h:148
~octave_bool()=default
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition ov-bool.h:183
int8NDArray int8_array_value() const
Definition ov-bool.h:95
Complex complex_value(bool=false) const
Definition ov-bool.h:170
FloatMatrix float_matrix_value(bool=false) const
Definition ov-bool.h:161
SparseMatrix sparse_matrix_value(bool=false) const
Definition ov-bool.h:186
boolMatrix bool_matrix_value(bool=false) const
Definition ov-bool.h:206
double scalar_value(bool=false) const
Definition ov-bool.h:154
uint64NDArray uint64_array_value() const
Definition ov-bool.h:123
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
Definition ov-bool.h:242
bool isnumeric() const
Definition ov-bool.h:90
uint16NDArray uint16_array_value() const
Definition ov-bool.h:115
double double_value(bool=false) const
Definition ov-bool.h:150
octave_int64 int64_scalar_value() const
Definition ov-bool.h:136
bool bool_value(bool=false) const
Definition ov-bool.h:204
bool is_true() const
Definition ov-bool.h:92
octave_int32 int32_scalar_value() const
Definition ov-bool.h:133
boolNDArray bool_array_value(bool=false) const
Definition ov-bool.h:209
octave_bool(bool b)
Definition ov-bool.h:60
uint8NDArray uint8_array_value() const
Definition ov-bool.h:111
octave_int16 int16_scalar_value() const
Definition ov-bool.h:130
octave_value map(unary_mapper_t umap) const
Definition ov-bool.h:253
float float_scalar_value(bool=false) const
Definition ov-bool.h:156
octave_uint32 uint32_scalar_value() const
Definition ov-bool.h:145
builtin_type_t builtin_type() const
Definition ov-bool.h:80
bool is_bool_scalar() const
Definition ov-bool.h:84
octave_base_value * clone() const
Definition ov-bool.h:68
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition ov-bool.h:190
bool islogical() const
Definition ov-bool.h:86
int32NDArray int32_array_value() const
Definition ov-bool.h:103
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition ov-bool.h:193
bool is_real_scalar() const
Definition ov-bool.h:82
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition ov-bool.h:177
NDArray array_value(bool=false) const
Definition ov-bool.h:164
int16NDArray int16_array_value() const
Definition ov-bool.h:99
FloatNDArray float_array_value(bool=false) const
Definition ov-bool.h:167
octave_uint8 uint8_scalar_value() const
Definition ov-bool.h:139
int64NDArray int64_array_value() const
Definition ov-bool.h:107
ComplexNDArray complex_array_value(bool=false) const
Definition ov-bool.h:180
octave_value map(unary_mapper_t umap) const
Definition ov-scalar.cc:370
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition ovl.h:115
intNDArray< octave_int16 > int16NDArray
intNDArray< octave_int32 > int32NDArray
intNDArray< octave_int64 > int64NDArray
intNDArray< octave_int8 > int8NDArray
Definition int8NDArray.h:36
std::complex< double > Complex
Definition oct-cmplx.h:33
std::complex< float > FloatComplex
Definition oct-cmplx.h:34
int64_t octave_hdf5_id
octave_int< uint32_t > octave_uint32
octave_int< int32_t > octave_int32
octave_int< int16_t > octave_int16
octave_int< int8_t > octave_int8
octave_int< int64_t > octave_int64
octave_int< uint64_t > octave_uint64
octave_int< uint16_t > octave_uint16
octave_int< uint8_t > octave_uint8
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA_API(API)
Definition ov-base.h:185
builtin_type_t
Definition ov-base.h:83
@ btyp_bool
Definition ov-base.h:96
intNDArray< octave_uint16 > uint16NDArray
intNDArray< octave_uint32 > uint32NDArray
intNDArray< octave_uint64 > uint64NDArray
intNDArray< octave_uint8 > uint8NDArray