GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
ov-bool.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2021 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 
47 class octave_value_list;
48 
49 // Real scalar values.
50 
51 class
52 OCTINTERP_API
54 {
55 public:
56 
57  octave_bool (void)
58  : octave_base_scalar<bool> (false) { }
59 
60  octave_bool (bool b)
61  : octave_base_scalar<bool> (b) { }
62 
64  : octave_base_scalar<bool> (s) { }
65 
66  ~octave_bool (void) = default;
67 
68  octave_base_value * clone (void) const { return new octave_bool (*this); }
70  { return new octave_bool_matrix (); }
71 
72  type_conv_info numeric_conversion_function (void) const;
73 
74  octave_value do_index_op (const octave_value_list& idx,
75  bool resize_ok = false);
76 
77  idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); }
78 
79  builtin_type_t builtin_type (void) const { return btyp_bool; }
80 
81  bool is_real_scalar (void) const { return true; }
82 
83  bool is_bool_scalar (void) const { return true; }
84 
85  bool islogical (void) const { return true; }
86 
87  bool isreal (void) const { return true; }
88 
89  bool isnumeric (void) const { return false; }
90 
91  bool is_true (void) const { return scalar; }
92 
94  int8_array_value (void) const
95  { return int8NDArray (dim_vector (1, 1), scalar); }
96 
98  int16_array_value (void) const
99  { return int16NDArray (dim_vector (1, 1), scalar); }
100 
102  int32_array_value (void) const
103  { return int32NDArray (dim_vector (1, 1), scalar); }
104 
106  int64_array_value (void) const
107  { return int64NDArray (dim_vector (1, 1), scalar); }
108 
110  uint8_array_value (void) const
111  { return uint8NDArray (dim_vector (1, 1), scalar); }
112 
114  uint16_array_value (void) const
115  { return uint16NDArray (dim_vector (1, 1), scalar); }
116 
118  uint32_array_value (void) const
119  { return uint32NDArray (dim_vector (1, 1), scalar); }
120 
122  uint64_array_value (void) const
123  { return uint64NDArray (dim_vector (1, 1), scalar); }
124 
126  int8_scalar_value (void) const { return octave_int8 (scalar); }
127 
129  int16_scalar_value (void) const { return octave_int16 (scalar); }
130 
132  int32_scalar_value (void) const { return octave_int32 (scalar); }
133 
135  int64_scalar_value (void) const { return octave_int64 (scalar); }
136 
138  uint8_scalar_value (void) const { return octave_uint8 (scalar); }
139 
141  uint16_scalar_value (void) const { return octave_uint16 (scalar); }
142 
144  uint32_scalar_value (void) const { return octave_uint32 (scalar); }
145 
147  uint64_scalar_value (void) const { return octave_uint64 (scalar); }
148 
149  double double_value (bool = false) const { return scalar; }
150 
151  float float_value (bool = false) const { return scalar; }
152 
153  double scalar_value (bool = false) const { return scalar; }
154 
155  float float_scalar_value (bool = false) const { return scalar; }
156 
157  Matrix matrix_value (bool = false) const
158  { return Matrix (1, 1, scalar); }
159 
160  FloatMatrix float_matrix_value (bool = false) const
161  { return FloatMatrix (1, 1, scalar); }
162 
163  NDArray array_value (bool = false) const
164  { return NDArray (dim_vector (1, 1), double_value ()); }
165 
166  FloatNDArray float_array_value (bool = false) const
167  { return FloatNDArray (dim_vector (1, 1), float_value ()); }
168 
169  Complex complex_value (bool = false) const { return scalar; }
170 
171  FloatComplex float_complex_value (bool = false) const { return scalar; }
172 
173  ComplexMatrix complex_matrix_value (bool = false) const
174  { return ComplexMatrix (1, 1, Complex (scalar)); }
175 
177  { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
178 
179  ComplexNDArray complex_array_value (bool = false) const
180  { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
181 
183  { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
184 
185  SparseMatrix sparse_matrix_value (bool = false) const
186  { return SparseMatrix (Matrix (1, 1, scalar)); }
187 
188  // FIXME: Need SparseComplexMatrix (Matrix) constructor!
190  { return SparseComplexMatrix (sparse_matrix_value ()); }
191 
193  { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); }
194 
196  char_array_value (bool = false) const
197  {
198  charNDArray retval (dim_vector (1, 1));
199  retval(0) = static_cast<char> (scalar);
200  return retval;
201  }
202 
203  bool bool_value (bool = false) const { return scalar; }
204 
205  boolMatrix bool_matrix_value (bool = false) const
206  { return boolMatrix (1, 1, scalar); }
207 
208  boolNDArray bool_array_value (bool = false) const
209  { return boolNDArray (dim_vector (1, 1), scalar); }
210 
211  octave_value as_double (void) const;
212  octave_value as_single (void) const;
213 
214  octave_value as_int8 (void) const;
215  octave_value as_int16 (void) const;
216  octave_value as_int32 (void) const;
217  octave_value as_int64 (void) const;
218 
219  octave_value as_uint8 (void) const;
220  octave_value as_uint16 (void) const;
221  octave_value as_uint32 (void) const;
222  octave_value as_uint64 (void) const;
223 
224  octave_value resize (const dim_vector& dv, bool fill = false) const;
225 
226  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
227 
228  bool save_ascii (std::ostream& os);
229 
230  bool load_ascii (std::istream& is);
231 
232  bool save_binary (std::ostream& os, bool save_as_floats);
233 
234  bool load_binary (std::istream& is, bool swap,
236 
237  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
238 
239  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
240 
241  int write (octave::stream& os, int block_size,
242  oct_data_conv::data_type output_type, int skip,
243  octave::mach_info::float_format flt_fmt) const
244  {
245  return os.write (bool_array_value (), block_size, output_type,
246  skip, flt_fmt);
247  }
248 
249  mxArray * as_mxArray (void) const;
250 
251  // Mapper functions are converted to double for treatment
253  {
254  octave_scalar m (scalar_value ());
255  return m.map (umap);
256  }
257 
258 private:
259 
261 };
262 
263 #endif
Definition: dMatrix.h:42
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:95
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, mach_info::float_format flt_fmt)
Definition: oct-stream.cc:6777
octave_bool(const octave_bool &s)
Definition: ov-bool.h:63
octave_uint16 uint16_scalar_value(void) const
Definition: ov-bool.h:141
charNDArray char_array_value(bool=false) const
Definition: ov-bool.h:196
FloatComplex float_complex_value(bool=false) const
Definition: ov-bool.h:171
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool.h:173
bool isnumeric(void) const
Definition: ov-bool.h:89
octave_base_value * clone(void) const
Definition: ov-bool.h:68
~octave_bool(void)=default
bool is_bool_scalar(void) const
Definition: ov-bool.h:83
float float_value(bool=false) const
Definition: ov-bool.h:151
Matrix matrix_value(bool=false) const
Definition: ov-bool.h:157
uint64NDArray uint64_array_value(void) const
Definition: ov-bool.h:122
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-bool.h:182
Complex complex_value(bool=false) const
Definition: ov-bool.h:169
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-bool.h:160
int16NDArray int16_array_value(void) const
Definition: ov-bool.h:98
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-bool.h:185
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool.h:205
double scalar_value(bool=false) const
Definition: ov-bool.h:153
uint32NDArray uint32_array_value(void) const
Definition: ov-bool.h:118
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:241
octave_int64 int64_scalar_value(void) const
Definition: ov-bool.h:135
bool is_real_scalar(void) const
Definition: ov-bool.h:81
double double_value(bool=false) const
Definition: ov-bool.h:149
int64NDArray int64_array_value(void) const
Definition: ov-bool.h:106
octave_uint32 uint32_scalar_value(void) const
Definition: ov-bool.h:144
bool bool_value(bool=false) const
Definition: ov-bool.h:203
uint8NDArray uint8_array_value(void) const
Definition: ov-bool.h:110
octave_uint64 uint64_scalar_value(void) const
Definition: ov-bool.h:147
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool.h:208
octave_bool(bool b)
Definition: ov-bool.h:60
octave_base_value * empty_clone(void) const
Definition: ov-bool.h:69
bool isreal(void) const
Definition: ov-bool.h:87
octave_value map(unary_mapper_t umap) const
Definition: ov-bool.h:252
int32NDArray int32_array_value(void) const
Definition: ov-bool.h:102
float float_scalar_value(bool=false) const
Definition: ov-bool.h:155
octave_int8 int8_scalar_value(void) const
Definition: ov-bool.h:126
octave_int16 int16_scalar_value(void) const
Definition: ov-bool.h:129
uint16NDArray uint16_array_value(void) const
Definition: ov-bool.h:114
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-bool.h:189
bool islogical(void) const
Definition: ov-bool.h:85
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool.h:192
idx_vector index_vector(bool=false) const
Definition: ov-bool.h:77
bool is_true(void) const
Definition: ov-bool.h:91
builtin_type_t builtin_type(void) const
Definition: ov-bool.h:79
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-bool.h:176
NDArray array_value(bool=false) const
Definition: ov-bool.h:163
FloatNDArray float_array_value(bool=false) const
Definition: ov-bool.h:166
octave_bool(void)
Definition: ov-bool.h:57
int8NDArray int8_array_value(void) const
Definition: ov-bool.h:94
octave_uint8 uint8_scalar_value(void) const
Definition: ov-bool.h:138
octave_int32 int32_scalar_value(void) const
Definition: ov-bool.h:132
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-bool.h:179
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
Definition: ovl.h:117
QString name
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:36
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:36
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:36
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:36
T octave_idx_type m
Definition: mx-inlines.cc:773
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
static double as_double(time_t sec, long usec)
Definition: oct-time.h:37
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:158
builtin_type_t
Definition: ov-base.h:72
@ btyp_bool
Definition: ov-base.h:85
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:669
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:36
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:36
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:36
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:36