GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ov-bool.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2015 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if !defined (octave_ov_bool_h)
24 #define octave_ov_bool_h 1
25 
26 #include <cstdlib>
27 
28 #include <iosfwd>
29 #include <string>
30 
31 #include "lo-utils.h"
32 #include "mx-base.h"
33 #include "str-vec.h"
34 
35 #include "oct-stream.h"
36 #include "ov-base.h"
37 #include "ov-base-scalar.h"
38 #include "ov-bool-mat.h"
39 #include "ov-scalar.h"
40 #include "ov-typeinfo.h"
41 
42 class octave_value_list;
43 
44 class tree_walker;
45 
46 // Real scalar values.
47 
48 class
51 {
52 public:
53 
54  octave_bool (void)
55  : octave_base_scalar<bool> (false) { }
56 
57  octave_bool (bool b)
58  : octave_base_scalar<bool> (b) { }
59 
61  : octave_base_scalar<bool> (s) { }
62 
63  ~octave_bool (void) { }
64 
65  octave_base_value *clone (void) const { return new octave_bool (*this); }
67  { return new octave_bool_matrix (); }
68 
69  type_conv_info numeric_conversion_function (void) const;
70 
71  octave_value do_index_op (const octave_value_list& idx,
72  bool resize_ok = false);
73 
74  idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); }
75 
76  builtin_type_t builtin_type (void) const { return btyp_bool; }
77 
78  bool is_real_scalar (void) const { return true; }
79 
80  bool is_bool_scalar (void) const { return true; }
81 
82  bool is_bool_type (void) const { return true; }
83 
84  bool is_real_type (void) const { return true; }
85 
86  bool is_numeric_type (void) const { return false; }
87 
88  bool is_true (void) const { return scalar; }
89 
91  int8_array_value (void) const
92  { return int8NDArray (dim_vector (1, 1), scalar); }
93 
95  int16_array_value (void) const
96  { return int16NDArray (dim_vector (1, 1), scalar); }
97 
99  int32_array_value (void) const
100  { return int32NDArray (dim_vector (1, 1), scalar); }
101 
103  int64_array_value (void) const
104  { return int64NDArray (dim_vector (1, 1), scalar); }
105 
107  uint8_array_value (void) const
108  { return uint8NDArray (dim_vector (1, 1), scalar); }
109 
111  uint16_array_value (void) const
112  { return uint16NDArray (dim_vector (1, 1), scalar); }
113 
115  uint32_array_value (void) const
116  { return uint32NDArray (dim_vector (1, 1), scalar); }
117 
119  uint64_array_value (void) const
120  { return uint64NDArray (dim_vector (1, 1), scalar); }
121 
123  int8_scalar_value (void) const { return octave_int8 (scalar); }
124 
126  int16_scalar_value (void) const { return octave_int16 (scalar); }
127 
129  int32_scalar_value (void) const { return octave_int32 (scalar); }
130 
132  int64_scalar_value (void) const { return octave_int64 (scalar); }
133 
135  uint8_scalar_value (void) const { return octave_uint8 (scalar); }
136 
138  uint16_scalar_value (void) const { return octave_uint16 (scalar); }
139 
141  uint32_scalar_value (void) const { return octave_uint32 (scalar); }
142 
144  uint64_scalar_value (void) const { return octave_uint64 (scalar); }
145 
146  double double_value (bool = false) const { return scalar; }
147 
148  float float_value (bool = false) const { return scalar; }
149 
150  double scalar_value (bool = false) const { return scalar; }
151 
152  float float_scalar_value (bool = false) const { return scalar; }
153 
154  Matrix matrix_value (bool = false) const
155  { return Matrix (1, 1, scalar); }
156 
157  FloatMatrix float_matrix_value (bool = false) const
158  { return FloatMatrix (1, 1, scalar); }
159 
160  NDArray array_value (bool = false) const
161  { return NDArray (dim_vector (1, 1), static_cast<double> (scalar)); }
162 
163  FloatNDArray float_array_value (bool = false) const
164  { return FloatNDArray (dim_vector (1, 1), static_cast<double> (scalar)); }
165 
166  Complex complex_value (bool = false) const { return scalar; }
167 
168  FloatComplex float_complex_value (bool = false) const { return scalar; }
169 
170  ComplexMatrix complex_matrix_value (bool = false) const
171  { return ComplexMatrix (1, 1, Complex (scalar)); }
172 
174  { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
175 
176  ComplexNDArray complex_array_value (bool = false) const
177  { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
178 
180  { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
181 
182  SparseMatrix sparse_matrix_value (bool = false) const
183  { return SparseMatrix (Matrix (1, 1, scalar)); }
184 
185  // FIXME Need SparseComplexMatrix (Matrix) constructor!!!
187  { return SparseComplexMatrix (sparse_matrix_value ()); }
188 
190  { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); }
191 
193  char_array_value (bool = false) const
194  {
195  charNDArray retval (dim_vector (1, 1));
196  retval(0) = static_cast<char> (scalar);
197  return retval;
198  }
199 
200  bool bool_value (bool = false) const { return scalar; }
201 
202  boolMatrix bool_matrix_value (bool = false) const
203  { return boolMatrix (1, 1, scalar); }
204 
205  boolNDArray bool_array_value (bool = false) const
206  { return boolNDArray (dim_vector (1, 1), scalar); }
207 
208  octave_value resize (const dim_vector& dv, bool fill = false) const;
209 
210  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
211 
212  bool save_ascii (std::ostream& os);
213 
214  bool load_ascii (std::istream& is);
215 
216  bool save_binary (std::ostream& os, bool& save_as_floats);
217 
218  bool load_binary (std::istream& is, bool swap,
220 
221  bool save_hdf5 (octave_hdf5_id loc_id, const char *name, bool save_as_floats);
222 
223  bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
224 
225  int write (octave_stream& os, int block_size,
226  oct_data_conv::data_type output_type, int skip,
227  oct_mach_info::float_format flt_fmt) const
228  {
229  return os.write (bool_array_value (), block_size, output_type,
230  skip, flt_fmt);
231  }
232 
233  mxArray *as_mxArray (void) const;
234 
235  // Mapper functions are converted to double for treatment
237  {
238  octave_scalar m (scalar_value ());
239  return m.map (umap);
240  }
241 
242 private:
243 
244 
246 };
247 
248 #endif
bool is_bool_scalar(void) const
Definition: ov-bool.h:80
int8NDArray int8_array_value(void) const
Definition: ov-bool.h:91
octave_int< uint32_t > octave_uint32
ComplexNDArray complex_array_value(bool=false) const
Definition: ov-bool.h:176
int bool
Definition: mex.h:56
intNDArray< octave_int64 > int64NDArray
Definition: int64NDArray.h:31
uint16NDArray uint16_array_value(void) const
Definition: ov-bool.h:111
int32NDArray int32_array_value(void) const
Definition: ov-bool.h:99
FloatComplexNDArray float_complex_array_value(bool=false) const
Definition: ov-bool.h:179
octave_uint64 uint64_scalar_value(void) const
Definition: ov-bool.h:144
octave_bool(void)
Definition: ov-bool.h:54
octave_uint32 uint32_scalar_value(void) const
Definition: ov-bool.h:141
intNDArray< octave_uint32 > uint32NDArray
Definition: uint32NDArray.h:31
intNDArray< octave_uint8 > uint8NDArray
Definition: uint8NDArray.h:31
intNDArray< octave_uint16 > uint16NDArray
Definition: uint16NDArray.h:31
FloatComplex float_complex_value(bool=false) const
Definition: ov-bool.h:168
builtin_type_t builtin_type(void) const
Definition: ov-bool.h:76
Matrix matrix_value(bool=false) const
Definition: ov-bool.h:154
bool is_real_type(void) const
Definition: ov-bool.h:84
int16NDArray int16_array_value(void) const
Definition: ov-bool.h:95
octave_int< int16_t > octave_int16
double double_value(bool=false) const
Definition: ov-bool.h:146
idx_vector index_vector(bool=false) const
Definition: ov-bool.h:74
intNDArray< octave_int16 > int16NDArray
Definition: int16NDArray.h:31
builtin_type_t
Definition: ov-base.h:59
float float_scalar_value(bool=false) const
Definition: ov-bool.h:152
octave_value map(unary_mapper_t umap) const
Definition: ov-scalar.cc:297
ComplexMatrix complex_matrix_value(bool=false) const
Definition: ov-bool.h:170
FloatComplexMatrix float_complex_matrix_value(bool=false) const
Definition: ov-bool.h:173
octave_int< int32_t > octave_int32
uint8NDArray uint8_array_value(void) const
Definition: ov-bool.h:107
FloatMatrix float_matrix_value(bool=false) const
Definition: ov-bool.h:157
#define DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
Definition: ov-base.h:142
octave_base_value * clone(void) const
Definition: ov-bool.h:65
octave_int< uint16_t > octave_uint16
octave_bool(bool b)
Definition: ov-bool.h:57
bool bool_value(bool=false) const
Definition: ov-bool.h:200
#define OCTINTERP_API
Definition: mexproto.h:66
intNDArray< octave_int8 > int8NDArray
Definition: int8NDArray.h:31
FloatNDArray float_array_value(bool=false) const
Definition: ov-bool.h:163
double scalar_value(bool=false) const
Definition: ov-bool.h:150
octave_value map(unary_mapper_t umap) const
Definition: ov-bool.h:236
bool is_true(void) const
Definition: ov-bool.h:88
octave_int< int64_t > octave_int64
uint32NDArray uint32_array_value(void) const
Definition: ov-bool.h:115
octave_base_value * empty_clone(void) const
Definition: ov-bool.h:66
octave_int< uint64_t > octave_uint64
SparseComplexMatrix sparse_complex_matrix_value(bool=false) const
Definition: ov-bool.h:186
Definition: dMatrix.h:35
bool is_real_scalar(void) const
Definition: ov-bool.h:78
NDArray array_value(bool=false) const
Definition: ov-bool.h:160
octave_int8 int8_scalar_value(void) const
Definition: ov-bool.h:123
~octave_bool(void)
Definition: ov-bool.h:63
int64NDArray int64_array_value(void) const
Definition: ov-bool.h:103
octave_int32 int32_scalar_value(void) const
Definition: ov-bool.h:129
intNDArray< octave_int32 > int32NDArray
Definition: int32NDArray.h:31
SparseMatrix sparse_matrix_value(bool=false) const
Definition: ov-bool.h:182
float float_value(bool=false) const
Definition: ov-bool.h:148
boolMatrix bool_matrix_value(bool=false) const
Definition: ov-bool.h:202
octave_idx_type write(const octave_value &data, octave_idx_type block_size, oct_data_conv::data_type output_type, octave_idx_type skip, oct_mach_info::float_format flt_fmt)
Definition: oct-stream.cc:3546
octave_uint8 uint8_scalar_value(void) const
Definition: ov-bool.h:135
octave_uint16 uint16_scalar_value(void) const
Definition: ov-bool.h:138
octave_int16 int16_scalar_value(void) const
Definition: ov-bool.h:126
Complex complex_value(bool=false) const
Definition: ov-bool.h:166
SparseBoolMatrix sparse_bool_matrix_value(bool=false) const
Definition: ov-bool.h:189
octave_int64 int64_scalar_value(void) const
Definition: ov-bool.h:132
bool is_bool_type(void) const
Definition: ov-bool.h:82
std::complex< float > FloatComplex
Definition: oct-cmplx.h:30
int write(octave_stream &os, int block_size, oct_data_conv::data_type output_type, int skip, oct_mach_info::float_format flt_fmt) const
Definition: ov-bool.h:225
std::complex< double > Complex
Definition: oct-cmplx.h:29
charNDArray char_array_value(bool=false) const
Definition: ov-bool.h:193
octave_int< uint8_t > octave_uint8
boolNDArray bool_array_value(bool=false) const
Definition: ov-bool.h:205
octave_int< int8_t > octave_int8
uint64NDArray uint64_array_value(void) const
Definition: ov-bool.h:119
octave_bool(const octave_bool &s)
Definition: ov-bool.h:60
bool is_numeric_type(void) const
Definition: ov-bool.h:86
static bool scalar(const dim_vector &dims)
Definition: ov-struct.cc:736
intNDArray< octave_uint64 > uint64NDArray
Definition: uint64NDArray.h:31