Mercurial > hg > octave-nkf
annotate src/ov-bool.h @ 11474:8a40037533e2
struct printing changes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 10 Jan 2011 14:05:12 -0500 |
parents | d9e57045b9e1 |
children | fd0a3ac60b0e |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 2000, 2002, 2003, 2004, 2005, 2006, |
8920 | 4 2007, 2008 John W. Eaton |
2871 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2871 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2871 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_bool_h) | |
25 #define octave_bool_h 1 | |
26 | |
27 #include <cstdlib> | |
28 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
2871 | 30 #include <string> |
31 | |
32 #include "lo-utils.h" | |
33 #include "mx-base.h" | |
34 #include "oct-alloc.h" | |
35 #include "str-vec.h" | |
36 | |
4970 | 37 #include "oct-stream.h" |
2871 | 38 #include "ov-base.h" |
3223 | 39 #include "ov-base-scalar.h" |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10343
diff
changeset
|
40 #include "ov-bool-mat.h" |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
41 #include "ov-scalar.h" |
2871 | 42 #include "ov-typeinfo.h" |
43 | |
44 class octave_value_list; | |
45 | |
46 class tree_walker; | |
47 | |
48 // Real scalar values. | |
49 | |
50 class | |
10343
2ef5144ccb0d
Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
51 OCTINTERP_API |
3223 | 52 octave_bool : public octave_base_scalar<bool> |
2871 | 53 { |
54 public: | |
55 | |
56 octave_bool (void) | |
3223 | 57 : octave_base_scalar<bool> (false) { } |
2871 | 58 |
59 octave_bool (bool b) | |
3223 | 60 : octave_base_scalar<bool> (b) { } |
2871 | 61 |
62 octave_bool (const octave_bool& s) | |
3223 | 63 : octave_base_scalar<bool> (s) { } |
2871 | 64 |
65 ~octave_bool (void) { } | |
66 | |
5759 | 67 octave_base_value *clone (void) const { return new octave_bool (*this); } |
10544
9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
Jaroslav Hajek <highegg@gmail.com>
parents:
10343
diff
changeset
|
68 octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); } |
2871 | 69 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
70 type_conv_info numeric_conversion_function (void) const; |
2871 | 71 |
5885 | 72 octave_value do_index_op (const octave_value_list& idx, |
10313 | 73 bool resize_ok = false); |
2871 | 74 |
75 idx_vector index_vector (void) const { return idx_vector (scalar); } | |
76 | |
9685 | 77 builtin_type_t builtin_type (void) const { return btyp_bool; } |
78 | |
2871 | 79 bool is_real_scalar (void) const { return true; } |
80 | |
5881 | 81 bool is_bool_scalar (void) const { return true; } |
82 | |
3209 | 83 bool is_bool_type (void) const { return true; } |
84 | |
2871 | 85 bool is_real_type (void) const { return true; } |
3209 | 86 |
9841
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
87 bool is_numeric_type (void) const { return false; } |
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
88 |
2871 | 89 bool is_true (void) const { return scalar; } |
90 | |
5533 | 91 int8NDArray |
92 int8_array_value (void) const | |
93 { return int8NDArray (dim_vector (1, 1), scalar); } | |
94 | |
95 int16NDArray | |
96 int16_array_value (void) const | |
97 { return int16NDArray (dim_vector (1, 1), scalar); } | |
98 | |
99 int32NDArray | |
100 int32_array_value (void) const | |
101 { return int32NDArray (dim_vector (1, 1), scalar); } | |
102 | |
103 int64NDArray | |
104 int64_array_value (void) const | |
105 { return int64NDArray (dim_vector (1, 1), scalar); } | |
106 | |
107 uint8NDArray | |
108 uint8_array_value (void) const | |
109 { return uint8NDArray (dim_vector (1, 1), scalar); } | |
110 | |
111 uint16NDArray | |
112 uint16_array_value (void) const | |
113 { return uint16NDArray (dim_vector (1, 1), scalar); } | |
114 | |
115 uint32NDArray | |
116 uint32_array_value (void) const | |
117 { return uint32NDArray (dim_vector (1, 1), scalar); } | |
118 | |
119 uint64NDArray | |
120 uint64_array_value (void) const | |
121 { return uint64NDArray (dim_vector (1, 1), scalar); } | |
122 | |
2871 | 123 double double_value (bool = false) const { return scalar; } |
124 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
125 float float_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 |
2916 | 127 double scalar_value (bool = false) const { return scalar; } |
128 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
129 float float_scalar_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
130 |
3145 | 131 Matrix matrix_value (bool = false) const |
132 { return Matrix (1, 1, scalar); } | |
2871 | 133 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
134 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
135 { return FloatMatrix (1, 1, scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 |
4630 | 137 NDArray array_value (bool = false) const |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
138 { return NDArray (dim_vector (1, 1), static_cast<double> (scalar)); } |
4630 | 139 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
140 FloatNDArray float_array_value (bool = false) const |
7919
9d080df0c843
new NDArray constructor for ArrayN<octave_idx_type>
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
141 { return FloatNDArray (dim_vector (1, 1), static_cast<double> (scalar)); } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
142 |
2871 | 143 Complex complex_value (bool = false) const { return scalar; } |
144 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
145 FloatComplex float_complex_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
146 |
2871 | 147 ComplexMatrix complex_matrix_value (bool = false) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
148 { return ComplexMatrix (1, 1, Complex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
150 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
151 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); } |
2871 | 152 |
4630 | 153 ComplexNDArray complex_array_value (bool = false) const |
154 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } | |
155 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
156 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
157 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
158 |
6099 | 159 SparseMatrix sparse_matrix_value (bool = false) const |
160 { return SparseMatrix (Matrix (1, 1, scalar)); } | |
161 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
162 // FIXME Need SparseComplexMatrix (Matrix) constructor!!! |
6099 | 163 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
164 { return SparseComplexMatrix (sparse_matrix_value ()); } | |
165 | |
166 SparseBoolMatrix sparse_bool_matrix_value (bool = false) const | |
167 { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); } | |
168 | |
5533 | 169 charNDArray |
170 char_array_value (bool = false) const | |
171 { | |
172 charNDArray retval (dim_vector (1, 1)); | |
173 retval(0) = static_cast<char> (scalar); | |
174 return retval; | |
175 } | |
176 | |
5944 | 177 bool bool_value (bool = false) const { return scalar; } |
2871 | 178 |
5944 | 179 boolMatrix bool_matrix_value (bool = false) const |
2871 | 180 { return boolMatrix (1, 1, scalar); } |
181 | |
5944 | 182 boolNDArray bool_array_value (bool = false) const |
4847 | 183 { return boolNDArray (dim_vector (1, 1), scalar); } |
184 | |
5731 | 185 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 186 |
5279 | 187 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871 | 188 |
6974 | 189 bool save_ascii (std::ostream& os); |
4687 | 190 |
191 bool load_ascii (std::istream& is); | |
192 | |
193 bool save_binary (std::ostream& os, bool& save_as_floats); | |
194 | |
195 bool load_binary (std::istream& is, bool swap, | |
10313 | 196 oct_mach_info::float_format fmt); |
4687 | 197 |
198 #if defined (HAVE_HDF5) | |
199 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
200 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9841
diff
changeset
|
201 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 202 #endif |
203 | |
4970 | 204 int write (octave_stream& os, int block_size, |
10313 | 205 oct_data_conv::data_type output_type, int skip, |
206 oct_mach_info::float_format flt_fmt) const | |
4970 | 207 { |
208 return os.write (bool_array_value (), block_size, output_type, | |
10313 | 209 skip, flt_fmt); |
4970 | 210 } |
211 | |
5900 | 212 mxArray *as_mxArray (void) const; |
213 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
214 // Mapper functions are converted to double for treatment |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
215 octave_value map (unary_mapper_t umap) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
216 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
217 octave_scalar m (scalar_value ()); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
218 return m.map (umap); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
219 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 |
2871 | 221 private: |
222 | |
4612 | 223 DECLARE_OCTAVE_ALLOCATOR |
2871 | 224 |
4612 | 225 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871 | 226 }; |
227 | |
228 #endif |