GNU Octave  3.8.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-2013 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 "oct-alloc.h"
34 #include "str-vec.h"
35 
36 #include "oct-stream.h"
37 #include "ov-base.h"
38 #include "ov-base-scalar.h"
39 #include "ov-bool-mat.h"
40 #include "ov-scalar.h"
41 #include "ov-typeinfo.h"
42 
43 class octave_value_list;
44 
45 class tree_walker;
46 
47 // Real scalar values.
48 
49 class
52 {
53 public:
54 
55  octave_bool (void)
56  : octave_base_scalar<bool> (false) { }
57 
58  octave_bool (bool b)
59  : octave_base_scalar<bool> (b) { }
60 
62  : octave_base_scalar<bool> (s) { }
63 
64  ~octave_bool (void) { }
65 
66  octave_base_value *clone (void) const { return new octave_bool (*this); }
67  octave_base_value *empty_clone (void) const
68  { return new octave_bool_matrix (); }
69 
70  type_conv_info numeric_conversion_function (void) const;
71 
72  octave_value do_index_op (const octave_value_list& idx,
73  bool resize_ok = false);
74 
75  idx_vector index_vector (void) const { return idx_vector (scalar); }
76 
77  builtin_type_t builtin_type (void) const { return btyp_bool; }
78 
79  bool is_real_scalar (void) const { return true; }
80 
81  bool is_bool_scalar (void) const { return true; }
82 
83  bool is_bool_type (void) const { return true; }
84 
85  bool is_real_type (void) const { return true; }
86 
87  bool is_numeric_type (void) const { return false; }
88 
89  bool is_true (void) const { return scalar; }
90 
92  int8_array_value (void) const
93  { return int8NDArray (dim_vector (1, 1), scalar); }
94 
96  int16_array_value (void) const
97  { return int16NDArray (dim_vector (1, 1), scalar); }
98 
100  int32_array_value (void) const
101  { return int32NDArray (dim_vector (1, 1), scalar); }
102 
104  int64_array_value (void) const
105  { return int64NDArray (dim_vector (1, 1), scalar); }
106 
108  uint8_array_value (void) const
109  { return uint8NDArray (dim_vector (1, 1), scalar); }
110 
112  uint16_array_value (void) const
113  { return uint16NDArray (dim_vector (1, 1), scalar); }
114 
116  uint32_array_value (void) const
117  { return uint32NDArray (dim_vector (1, 1), scalar); }
118 
120  uint64_array_value (void) const
121  { return uint64NDArray (dim_vector (1, 1), scalar); }
122 
124  int8_scalar_value (void) const { return octave_int8 (scalar); }
125 
127  int16_scalar_value (void) const { return octave_int16 (scalar); }
128 
130  int32_scalar_value (void) const { return octave_int32 (scalar); }
131 
133  int64_scalar_value (void) const { return octave_int64 (scalar); }
134 
136  uint8_scalar_value (void) const { return octave_uint8 (scalar); }
137 
139  uint16_scalar_value (void) const { return octave_uint16 (scalar); }
140 
142  uint32_scalar_value (void) const { return octave_uint32 (scalar); }
143 
145  uint64_scalar_value (void) const { return octave_uint64 (scalar); }
146 
147  double double_value (bool = false) const { return scalar; }
148 
149  float float_value (bool = false) const { return scalar; }
150 
151  double scalar_value (bool = false) const { return scalar; }
152 
153  float float_scalar_value (bool = false) const { return scalar; }
154 
155  Matrix matrix_value (bool = false) const
156  { return Matrix (1, 1, scalar); }
157 
158  FloatMatrix float_matrix_value (bool = false) const
159  { return FloatMatrix (1, 1, scalar); }
160 
161  NDArray array_value (bool = false) const
162  { return NDArray (dim_vector (1, 1), static_cast<double> (scalar)); }
163 
164  FloatNDArray float_array_value (bool = false) const
165  { return FloatNDArray (dim_vector (1, 1), static_cast<double> (scalar)); }
166 
167  Complex complex_value (bool = false) const { return scalar; }
168 
169  FloatComplex float_complex_value (bool = false) const { return scalar; }
170 
171  ComplexMatrix complex_matrix_value (bool = false) const
172  { return ComplexMatrix (1, 1, Complex (scalar)); }
173 
174  FloatComplexMatrix float_complex_matrix_value (bool = false) const
175  { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); }
176 
177  ComplexNDArray complex_array_value (bool = false) const
178  { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); }
179 
180  FloatComplexNDArray float_complex_array_value (bool = false) const
181  { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); }
182 
183  SparseMatrix sparse_matrix_value (bool = false) const
184  { return SparseMatrix (Matrix (1, 1, scalar)); }
185 
186  // FIXME Need SparseComplexMatrix (Matrix) constructor!!!
187  SparseComplexMatrix sparse_complex_matrix_value (bool = false) const
188  { return SparseComplexMatrix (sparse_matrix_value ()); }
189 
190  SparseBoolMatrix sparse_bool_matrix_value (bool = false) const
191  { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); }
192 
194  char_array_value (bool = false) const
195  {
196  charNDArray retval (dim_vector (1, 1));
197  retval(0) = static_cast<char> (scalar);
198  return retval;
199  }
200 
201  bool bool_value (bool = false) const { return scalar; }
202 
203  boolMatrix bool_matrix_value (bool = false) const
204  { return boolMatrix (1, 1, scalar); }
205 
206  boolNDArray bool_array_value (bool = false) const
207  { return boolNDArray (dim_vector (1, 1), scalar); }
208 
209  octave_value resize (const dim_vector& dv, bool fill = false) const;
210 
211  octave_value convert_to_str_internal (bool pad, bool force, char type) const;
212 
213  bool save_ascii (std::ostream& os);
214 
215  bool load_ascii (std::istream& is);
216 
217  bool save_binary (std::ostream& os, bool& save_as_floats);
218 
219  bool load_binary (std::istream& is, bool swap,
221 
222 #if defined (HAVE_HDF5)
223  bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats);
224 
225  bool load_hdf5 (hid_t loc_id, const char *name);
226 #endif
227 
228  int write (octave_stream& os, int block_size,
229  oct_data_conv::data_type output_type, int skip,
230  oct_mach_info::float_format flt_fmt) const
231  {
232  return os.write (bool_array_value (), block_size, output_type,
233  skip, flt_fmt);
234  }
235 
236  mxArray *as_mxArray (void) const;
237 
238  // Mapper functions are converted to double for treatment
239  octave_value map (unary_mapper_t umap) const
240  {
241  octave_scalar m (scalar_value ());
242  return m.map (umap);
243  }
244 
245 private:
246 
248 
250 };
251 
252 #endif