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 |
3933
|
65 octave_value *clone (void) const { return new octave_bool (*this); } |
|
66 octave_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 |
|
86 double double_value (bool = false) const { return scalar; } |
|
87 |
2916
|
88 double scalar_value (bool = false) const { return scalar; } |
|
89 |
3145
|
90 Matrix matrix_value (bool = false) const |
|
91 { return Matrix (1, 1, scalar); } |
2871
|
92 |
4630
|
93 NDArray array_value (bool = false) const |
|
94 { return NDArray (dim_vector (1, 1), scalar); } |
|
95 |
2871
|
96 Complex complex_value (bool = false) const { return scalar; } |
|
97 |
|
98 ComplexMatrix complex_matrix_value (bool = false) const |
|
99 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
100 |
4630
|
101 ComplexNDArray complex_array_value (bool = false) const |
|
102 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
|
103 |
2871
|
104 bool bool_value (void) const { return scalar; } |
|
105 |
|
106 boolMatrix bool_matrix_value (void) const |
|
107 { return boolMatrix (1, 1, scalar); } |
|
108 |
4847
|
109 boolNDArray bool_array_value (void) const |
|
110 { return boolNDArray (dim_vector (1, 1), scalar); } |
|
111 |
4915
|
112 octave_value resize (const dim_vector& dv) const |
|
113 { boolNDArray retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
114 |
5279
|
115 octave_value convert_to_str_internal (bool pad, bool force, char type) const; |
2871
|
116 |
4687
|
117 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
118 bool strip_nan_and_inf); |
|
119 |
|
120 bool load_ascii (std::istream& is); |
|
121 |
|
122 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
123 |
|
124 bool load_binary (std::istream& is, bool swap, |
|
125 oct_mach_info::float_format fmt); |
|
126 |
|
127 #if defined (HAVE_HDF5) |
|
128 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
129 |
|
130 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
131 #endif |
|
132 |
4970
|
133 int write (octave_stream& os, int block_size, |
|
134 oct_data_conv::data_type output_type, int skip, |
|
135 oct_mach_info::float_format flt_fmt) const |
|
136 { |
|
137 return os.write (bool_array_value (), block_size, output_type, |
|
138 skip, flt_fmt); |
|
139 } |
|
140 |
2871
|
141 private: |
|
142 |
4612
|
143 DECLARE_OCTAVE_ALLOCATOR |
2871
|
144 |
4612
|
145 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871
|
146 }; |
|
147 |
|
148 #endif |
|
149 |
|
150 /* |
|
151 ;;; Local Variables: *** |
|
152 ;;; mode: C++ *** |
|
153 ;;; End: *** |
|
154 */ |