Mercurial > octave-nkf
annotate src/ov-bool.h @ 10544:9961fc022d9d
fix assignment to non-existing variables and octave_value::assign
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 23 Apr 2010 11:23:43 +0200 |
parents | 2ef5144ccb0d |
children | d9e57045b9e1 |
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_map; | |
45 class octave_value_list; | |
46 | |
47 class tree_walker; | |
48 | |
49 // Real scalar values. | |
50 | |
51 class | |
10343
2ef5144ccb0d
Add few OCTINTERP_API tags.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10313
diff
changeset
|
52 OCTINTERP_API |
3223 | 53 octave_bool : public octave_base_scalar<bool> |
2871 | 54 { |
55 public: | |
56 | |
57 octave_bool (void) | |
3223 | 58 : octave_base_scalar<bool> (false) { } |
2871 | 59 |
60 octave_bool (bool b) | |
3223 | 61 : octave_base_scalar<bool> (b) { } |
2871 | 62 |
63 octave_bool (const octave_bool& s) | |
3223 | 64 : octave_base_scalar<bool> (s) { } |
2871 | 65 |
66 ~octave_bool (void) { } | |
67 | |
5759 | 68 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
|
69 octave_base_value *empty_clone (void) const { return new octave_bool_matrix (); } |
2871 | 70 |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
8202
diff
changeset
|
71 type_conv_info numeric_conversion_function (void) const; |
2871 | 72 |
5885 | 73 octave_value do_index_op (const octave_value_list& idx, |
10313 | 74 bool resize_ok = false); |
2871 | 75 |
76 idx_vector index_vector (void) const { return idx_vector (scalar); } | |
77 | |
9685 | 78 builtin_type_t builtin_type (void) const { return btyp_bool; } |
79 | |
2871 | 80 bool is_real_scalar (void) const { return true; } |
81 | |
5881 | 82 bool is_bool_scalar (void) const { return true; } |
83 | |
3209 | 84 bool is_bool_type (void) const { return true; } |
85 | |
2871 | 86 bool is_real_type (void) const { return true; } |
3209 | 87 |
9841
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
88 bool is_numeric_type (void) const { return false; } |
6f1ea8241c99
make isnumeric yield false on logicals
Jaroslav Hajek <highegg@gmail.com>
parents:
9812
diff
changeset
|
89 |
2871 | 90 bool is_true (void) const { return scalar; } |
91 | |
5533 | 92 int8NDArray |
93 int8_array_value (void) const | |
94 { return int8NDArray (dim_vector (1, 1), scalar); } | |
95 | |
96 int16NDArray | |
97 int16_array_value (void) const | |
98 { return int16NDArray (dim_vector (1, 1), scalar); } | |
99 | |
100 int32NDArray | |
101 int32_array_value (void) const | |
102 { return int32NDArray (dim_vector (1, 1), scalar); } | |
103 | |
104 int64NDArray | |
105 int64_array_value (void) const | |
106 { return int64NDArray (dim_vector (1, 1), scalar); } | |
107 | |
108 uint8NDArray | |
109 uint8_array_value (void) const | |
110 { return uint8NDArray (dim_vector (1, 1), scalar); } | |
111 | |
112 uint16NDArray | |
113 uint16_array_value (void) const | |
114 { return uint16NDArray (dim_vector (1, 1), scalar); } | |
115 | |
116 uint32NDArray | |
117 uint32_array_value (void) const | |
118 { return uint32NDArray (dim_vector (1, 1), scalar); } | |
119 | |
120 uint64NDArray | |
121 uint64_array_value (void) const | |
122 { return uint64NDArray (dim_vector (1, 1), scalar); } | |
123 | |
2871 | 124 double double_value (bool = false) const { return scalar; } |
125 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
126 float float_value (bool = false) const { return scalar; } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
127 |
2916 | 128 double scalar_value (bool = false) const { return scalar; } |
129 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
130 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
|
131 |
3145 | 132 Matrix matrix_value (bool = false) const |
133 { return Matrix (1, 1, scalar); } | |
2871 | 134 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
135 FloatMatrix float_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
136 { return FloatMatrix (1, 1, scalar); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
137 |
4630 | 138 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
|
139 { return NDArray (dim_vector (1, 1), static_cast<double> (scalar)); } |
4630 | 140 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
141 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
|
142 { 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
|
143 |
2871 | 144 Complex complex_value (bool = false) const { return scalar; } |
145 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
146 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
|
147 |
2871 | 148 ComplexMatrix complex_matrix_value (bool = false) const |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
149 { return ComplexMatrix (1, 1, Complex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
150 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
151 FloatComplexMatrix float_complex_matrix_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
152 { return FloatComplexMatrix (1, 1, FloatComplex (scalar)); } |
2871 | 153 |
4630 | 154 ComplexNDArray complex_array_value (bool = false) const |
155 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } | |
156 | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
157 FloatComplexNDArray float_complex_array_value (bool = false) const |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
158 { return FloatComplexNDArray (dim_vector (1, 1), FloatComplex (scalar)); } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7740
diff
changeset
|
159 |
6099 | 160 SparseMatrix sparse_matrix_value (bool = false) const |
161 { return SparseMatrix (Matrix (1, 1, scalar)); } | |
162 | |
8202
cf59d542f33e
replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents:
7919
diff
changeset
|
163 // FIXME Need SparseComplexMatrix (Matrix) constructor!!! |
6099 | 164 SparseComplexMatrix sparse_complex_matrix_value (bool = false) const |
165 { return SparseComplexMatrix (sparse_matrix_value ()); } | |
166 | |
167 SparseBoolMatrix sparse_bool_matrix_value (bool = false) const | |
168 { return SparseBoolMatrix (boolMatrix (1, 1, scalar)); } | |
169 | |
5533 | 170 charNDArray |
171 char_array_value (bool = false) const | |
172 { | |
173 charNDArray retval (dim_vector (1, 1)); | |
174 retval(0) = static_cast<char> (scalar); | |
175 return retval; | |
176 } | |
177 | |
5944 | 178 bool bool_value (bool = false) const { return scalar; } |
2871 | 179 |
5944 | 180 boolMatrix bool_matrix_value (bool = false) const |
2871 | 181 { return boolMatrix (1, 1, scalar); } |
182 | |
5944 | 183 boolNDArray bool_array_value (bool = false) const |
4847 | 184 { return boolNDArray (dim_vector (1, 1), scalar); } |
185 | |
5731 | 186 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915 | 187 |
5279 | 188 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871 | 189 |
6974 | 190 bool save_ascii (std::ostream& os); |
4687 | 191 |
192 bool load_ascii (std::istream& is); | |
193 | |
194 bool save_binary (std::ostream& os, bool& save_as_floats); | |
195 | |
196 bool load_binary (std::istream& is, bool swap, | |
10313 | 197 oct_mach_info::float_format fmt); |
4687 | 198 |
199 #if defined (HAVE_HDF5) | |
200 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); | |
201 | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9841
diff
changeset
|
202 bool load_hdf5 (hid_t loc_id, const char *name); |
4687 | 203 #endif |
204 | |
4970 | 205 int write (octave_stream& os, int block_size, |
10313 | 206 oct_data_conv::data_type output_type, int skip, |
207 oct_mach_info::float_format flt_fmt) const | |
4970 | 208 { |
209 return os.write (bool_array_value (), block_size, output_type, | |
10313 | 210 skip, flt_fmt); |
4970 | 211 } |
212 | |
5900 | 213 mxArray *as_mxArray (void) const; |
214 | |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
215 // Mapper functions are converted to double for treatment |
9812
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
216 octave_value map (unary_mapper_t umap) const |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
217 { |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
218 octave_scalar m (scalar_value ()); |
f80c566bc751
improve unary mapper system
Jaroslav Hajek <highegg@gmail.com>
parents:
9685
diff
changeset
|
219 return m.map (umap); |
7503
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
220 } |
8c32f95c2639
convert mapper functions to new format
David Bateman <dbateman@free.fr>
parents:
7017
diff
changeset
|
221 |
2871 | 222 private: |
223 | |
4612 | 224 DECLARE_OCTAVE_ALLOCATOR |
2871 | 225 |
4612 | 226 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871 | 227 }; |
228 | |
229 #endif |