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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_bool_h) |
|
24 #define octave_bool_h 1 |
|
25 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2871
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2871
|
33 #include <string> |
|
34 |
|
35 #include "lo-utils.h" |
|
36 #include "mx-base.h" |
|
37 #include "oct-alloc.h" |
|
38 #include "str-vec.h" |
|
39 |
4970
|
40 #include "oct-stream.h" |
2871
|
41 #include "ov-base.h" |
3223
|
42 #include "ov-base-scalar.h" |
2871
|
43 #include "ov-typeinfo.h" |
|
44 |
|
45 class Octave_map; |
|
46 class octave_value_list; |
|
47 |
|
48 class tree_walker; |
|
49 |
|
50 // Real scalar values. |
|
51 |
|
52 class |
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 |
3933
|
68 octave_value *clone (void) const { return new octave_bool (*this); } |
|
69 octave_value *empty_clone (void) const { return new octave_bool (); } |
2871
|
70 |
|
71 type_conv_fcn numeric_conversion_function (void) const; |
|
72 |
3933
|
73 octave_value do_index_op (const octave_value_list& idx, int resize_ok); |
2871
|
74 |
|
75 idx_vector index_vector (void) const { return idx_vector (scalar); } |
|
76 |
|
77 bool is_real_scalar (void) const { return true; } |
|
78 |
3209
|
79 bool is_bool_type (void) const { return true; } |
|
80 |
2871
|
81 bool is_real_type (void) const { return true; } |
3209
|
82 |
2871
|
83 bool valid_as_scalar_index (void) const { return scalar; } |
|
84 |
|
85 bool valid_as_zero_index (void) const { return ! scalar; } |
|
86 |
|
87 bool is_true (void) const { return scalar; } |
|
88 |
|
89 double double_value (bool = false) const { return scalar; } |
|
90 |
2916
|
91 double scalar_value (bool = false) const { return scalar; } |
|
92 |
3145
|
93 Matrix matrix_value (bool = false) const |
|
94 { return Matrix (1, 1, scalar); } |
2871
|
95 |
4630
|
96 NDArray array_value (bool = false) const |
|
97 { return NDArray (dim_vector (1, 1), scalar); } |
|
98 |
2871
|
99 Complex complex_value (bool = false) const { return scalar; } |
|
100 |
|
101 ComplexMatrix complex_matrix_value (bool = false) const |
|
102 { return ComplexMatrix (1, 1, Complex (scalar)); } |
|
103 |
4630
|
104 ComplexNDArray complex_array_value (bool = false) const |
|
105 { return ComplexNDArray (dim_vector (1, 1), Complex (scalar)); } |
|
106 |
2871
|
107 bool bool_value (void) const { return scalar; } |
|
108 |
|
109 boolMatrix bool_matrix_value (void) const |
|
110 { return boolMatrix (1, 1, scalar); } |
|
111 |
4847
|
112 boolNDArray bool_array_value (void) const |
|
113 { return boolNDArray (dim_vector (1, 1), scalar); } |
|
114 |
4915
|
115 octave_value resize (const dim_vector& dv) const |
|
116 { boolNDArray retval (dv); if (dv.numel()) retval(0) = scalar; return retval; } |
|
117 |
4457
|
118 octave_value convert_to_str_internal (bool pad, bool force) const; |
2871
|
119 |
4687
|
120 bool save_ascii (std::ostream& os, bool& infnan_warned, |
|
121 bool strip_nan_and_inf); |
|
122 |
|
123 bool load_ascii (std::istream& is); |
|
124 |
|
125 bool save_binary (std::ostream& os, bool& save_as_floats); |
|
126 |
|
127 bool load_binary (std::istream& is, bool swap, |
|
128 oct_mach_info::float_format fmt); |
|
129 |
|
130 #if defined (HAVE_HDF5) |
|
131 bool save_hdf5 (hid_t loc_id, const char *name, bool save_as_floats); |
|
132 |
|
133 bool load_hdf5 (hid_t loc_id, const char *name, bool have_h5giterate_bug); |
|
134 #endif |
|
135 |
4970
|
136 int write (octave_stream& os, int block_size, |
|
137 oct_data_conv::data_type output_type, int skip, |
|
138 oct_mach_info::float_format flt_fmt) const |
|
139 { |
|
140 return os.write (bool_array_value (), block_size, output_type, |
|
141 skip, flt_fmt); |
|
142 } |
|
143 |
2871
|
144 private: |
|
145 |
4612
|
146 DECLARE_OCTAVE_ALLOCATOR |
2871
|
147 |
4612
|
148 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2871
|
149 }; |
|
150 |
|
151 #endif |
|
152 |
|
153 /* |
|
154 ;;; Local Variables: *** |
|
155 ;;; mode: C++ *** |
|
156 ;;; End: *** |
|
157 */ |