2871
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 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 2, or (at your option) any |
|
10 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2871
|
21 |
|
22 */ |
|
23 |
|
24 #if !defined (octave_bool_h) |
|
25 #define octave_bool_h 1 |
|
26 |
|
27 #include <cstdlib> |
|
28 |
3503
|
29 #include <iostream> |
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" |
2871
|
40 #include "ov-typeinfo.h" |
|
41 |
|
42 class Octave_map; |
|
43 class octave_value_list; |
|
44 |
|
45 class tree_walker; |
|
46 |
|
47 // Real scalar values. |
|
48 |
|
49 class |
3223
|
50 octave_bool : public octave_base_scalar<bool> |
2871
|
51 { |
|
52 public: |
|
53 |
|
54 octave_bool (void) |
3223
|
55 : octave_base_scalar<bool> (false) { } |
2871
|
56 |
|
57 octave_bool (bool b) |
3223
|
58 : octave_base_scalar<bool> (b) { } |
2871
|
59 |
|
60 octave_bool (const octave_bool& s) |
3223
|
61 : octave_base_scalar<bool> (s) { } |
2871
|
62 |
|
63 ~octave_bool (void) { } |
|
64 |
5759
|
65 octave_base_value *clone (void) const { return new octave_bool (*this); } |
|
66 octave_base_value *empty_clone (void) const { return new octave_bool (); } |
2871
|
67 |
|
68 type_conv_fcn numeric_conversion_function (void) const; |
|
69 |
3933
|
70 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2871
|
71 |
|
72 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
73 |
|
74 bool is_real_scalar (void) const { return true; } |
|
75 |
3209
|
76 bool is_bool_type (void) const { return true; } |
|
77 |
2871
|
78 bool is_real_type (void) const { return true; } |
3209
|
79 |
2871
|
80 bool valid_as_scalar_index (void) const { return scalar; } |
|
81 |
|
82 bool valid_as_zero_index (void) const { return ! scalar; } |
|
83 |
|
84 bool is_true (void) const { return scalar; } |
|
85 |
5533
|
86 int8NDArray |
|
87 int8_array_value (void) const |
|
88 { return int8NDArray (dim_vector (1, 1), scalar); } |
|
89 |
|
90 int16NDArray |
|
91 int16_array_value (void) const |
|
92 { return int16NDArray (dim_vector (1, 1), scalar); } |
|
93 |
|
94 int32NDArray |
|
95 int32_array_value (void) const |
|
96 { return int32NDArray (dim_vector (1, 1), scalar); } |
|
97 |
|
98 int64NDArray |
|
99 int64_array_value (void) const |
|
100 { return int64NDArray (dim_vector (1, 1), scalar); } |
|
101 |
|
102 uint8NDArray |
|
103 uint8_array_value (void) const |
|
104 { return uint8NDArray (dim_vector (1, 1), scalar); } |
|
105 |
|
106 uint16NDArray |
|
107 uint16_array_value (void) const |
|
108 { return uint16NDArray (dim_vector (1, 1), scalar); } |
|
109 |
|
110 uint32NDArray |
|
111 uint32_array_value (void) const |
|
112 { return uint32NDArray (dim_vector (1, 1), scalar); } |
|
113 |
|
114 uint64NDArray |
|
115 uint64_array_value (void) const |
|
116 { return uint64NDArray (dim_vector (1, 1), scalar); } |
|
117 |
2871
|
118 double double_value (bool = false) const { return scalar; } |
|
119 |
2916
|
120 double scalar_value (bool = false) const { return scalar; } |
|
121 |
3145
|
122 Matrix matrix_value (bool = false) const |
|
123 { return Matrix (1, 1, scalar); } |
2871
|
124 |
4630
|
125 NDArray array_value (bool = false) const |
|
126 { return NDArray (dim_vector (1, 1), scalar); } |
|
127 |
2871
|
128 Complex complex_value (bool = false) const { return scalar; } |
|
129 |
|
130 ComplexMatrix complex_matrix_value (bool = false) const |
|
131 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
132 |
4630
|
133 ComplexNDArray complex_array_value (bool = false) const |
|
134 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
|
135 |
5533
|
136 charNDArray |
|
137 char_array_value (bool = false) const |
|
138 { |
|
139 charNDArray retval (dim_vector (1, 1)); |
|
140 retval(0) = static_cast<char> (scalar); |
|
141 return retval; |
|
142 } |
|
143 |
2871
|
144 bool bool_value (void) const { return scalar; } |
|
145 |
|
146 boolMatrix bool_matrix_value (void) const |
|
147 { return boolMatrix (1, 1, scalar); } |
|
148 |
4847
|
149 boolNDArray bool_array_value (void) const |
|
150 { return boolNDArray (dim_vector (1, 1), scalar); } |
|
151 |
5731
|
152 octave_value resize (const dim_vector& dv, bool fill = false) const; |
4915
|
153 |
5279
|
154 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871
|
155 |
4687
|
156 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
157 bool strip_nan_and_inf); |
|
158 |
|
159 bool load_ascii (std::istream& is); |
|
160 |
|
161 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
162 |
|
163 bool load_binary (std::istream& is, bool swap, |
|
164 oct_mach_info::float_format fmt); |
|
165 |
|
166 #if defined (HAVE_HDF5) |
|
167 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
168 |
|
169 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
170 #endif |
|
171 |
4970
|
172 int write (octave_stream& os, int block_size, |
|
173 oct_data_conv::data_type output_type, int skip, |
|
174 oct_mach_info::float_format flt_fmt) const |
|
175 { |
|
176 return os.write (bool_array_value (), block_size, output_type, |
|
177 skip, flt_fmt); |
|
178 } |
|
179 |
2871
|
180 private: |
|
181 |
4612
|
182 DECLARE_OCTAVE_ALLOCATOR |
2871
|
183 |
4612
|
184 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871
|
185 }; |
|
186 |
|
187 #endif |
|
188 |
|
189 /* |
|
190 ;;; Local Variables: *** |
|
191 ;;; mode: C++ *** |
|
192 ;;; End: *** |
|
193 */ |