Mercurial > hg > octave-nkf
annotate libinterp/octave-value/ov-bool.cc @ 19795:76478d2da117
unconditionally disable the octave_allocator class
* configure.ac: Delete the --enable-octave-allocator option.
* oct-alloc.h: Delete octave_allocator class. Warn if file is
included. Unconditionally define macros to be empty.
* NEWS: Make note of these changes.
* oct-alloc.cc: Delete.
* liboctave/util/module.mk (UTIL_SRC): Remove it from the list.
* make_int.cc, Cell.h, oct-obj.cc, oct-obj.h, audiodevinfo.cc,
ov-base-int.h, ov-base-scalar.h, ov-bool-mat.cc, ov-bool-mat.h,
ov-bool-sparse.cc, ov-bool-sparse.h, ov-bool.cc, ov-bool.h,
ov-builtin.cc, ov-builtin.h, ov-cell.cc, ov-cell.h, ov-ch-mat.h,
ov-class.cc, ov-class.h, ov-classdef.cc, ov-classdef.h, ov-complex.cc,
ov-complex.h, ov-cs-list.cc, ov-cs-list.h, ov-cx-diag.cc,
ov-cx-diag.h, ov-cx-mat.cc, ov-cx-mat.h, ov-cx-sparse.cc,
ov-cx-sparse.h, ov-dld-fcn.cc, ov-dld-fcn.h, ov-fcn-handle.cc,
ov-fcn-handle.h, ov-fcn-inline.cc, ov-fcn-inline.h, ov-fcn.cc,
ov-fcn.h, ov-float.cc, ov-float.h, ov-flt-complex.cc,
ov-flt-complex.h, ov-flt-cx-diag.cc, ov-flt-cx-diag.h,
ov-flt-cx-mat.cc, ov-flt-cx-mat.h, ov-flt-re-diag.cc,
ov-flt-re-diag.h, ov-flt-re-mat.cc, ov-flt-re-mat.h, ov-int16.cc,
ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-intx.h, ov-java.cc,
ov-java.h, ov-mex-fcn.cc, ov-mex-fcn.h, ov-perm.cc, ov-perm.h,
ov-range.cc, ov-range.h, ov-re-diag.cc, ov-re-diag.h, ov-re-mat.cc,
ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.cc,
ov-scalar.h, ov-str-mat.cc, ov-str-mat.h, ov-struct.cc, ov-struct.h,
ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc,
ov-usr-fcn.h, ov.cc, ov.h, pt-const.cc, pt-const.h, idx-vector.cc,
idx-vector.h: Delete uses of oct-alloc.h and OCTAVE_ALLOCATOR macros.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 13:43:29 -0500 |
parents | 6a71e5030df5 |
children | 4197fc428c7d |
rev | line source |
---|---|
2871 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
3 Copyright (C) 1996-2013 John W. Eaton |
2871 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2871 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2871 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3503 | 27 #include <iostream> |
2901 | 28 |
2871 | 29 #include "mx-base.h" |
30 | |
31 #include "gripes.h" | |
15149
62a35ae7d6a2
use forward decls for mxArray in ov.h and ov-base.h
John W. Eaton <jwe@octave.org>
parents:
15057
diff
changeset
|
32 #include "mxarray.h" |
2871 | 33 #include "oct-obj.h" |
34 #include "ops.h" | |
35 #include "ov-bool.h" | |
4964 | 36 #include "ov-bool-mat.h" |
3223 | 37 #include "ov-base.h" |
38 #include "ov-base-scalar.h" | |
39 #include "ov-base-scalar.cc" | |
2871 | 40 #include "ov-re-mat.h" |
41 #include "ov-scalar.h" | |
42 #include "pr-output.h" | |
43 | |
4687 | 44 #include "ls-oct-ascii.h" |
45 #include "ls-hdf5.h" | |
46 | |
3223 | 47 template class octave_base_scalar<bool>; |
48 | |
2871 | 49 |
4612 | 50 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_bool, "bool", "logical"); |
2871 | 51 |
5759 | 52 static octave_base_value * |
53 default_numeric_conversion_function (const octave_base_value& a) | |
2871 | 54 { |
55 CAST_CONV_ARG (const octave_bool&); | |
56 | |
57 return new octave_scalar (v.bool_value ()); | |
58 } | |
59 | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
60 octave_base_value::type_conv_info |
2871 | 61 octave_bool::numeric_conversion_function (void) const |
62 { | |
8345
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
63 return octave_base_value::type_conv_info (default_numeric_conversion_function, |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
64 octave_scalar::static_type_id ()); |
c777f3ce02d8
smarter conversion lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
65 |
2871 | 66 } |
67 | |
68 octave_value | |
5885 | 69 octave_bool::do_index_op (const octave_value_list& idx, bool resize_ok) |
2871 | 70 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 // FIXME: this doesn't solve the problem of |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
72 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
73 // a = 1; a([1,1], [1,1], [1,1]) |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
74 // |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
75 // and similar constructions. Hmm... |
2871 | 76 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
77 // FIXME: using this constructor avoids narrowing the |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
78 // 1x1 matrix back to a scalar value. Need a better solution |
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
79 // to this problem. |
2871 | 80 |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
81 octave_value tmp (new octave_bool_matrix (bool_matrix_value ())); |
2871 | 82 |
8437
f00578b495e9
remove valid_as_scalar_index
Jaroslav Hajek <highegg@gmail.com>
parents:
8345
diff
changeset
|
83 return tmp.do_index_op (idx, resize_ok); |
2871 | 84 } |
85 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
86 octave_value |
5731 | 87 octave_bool::resize (const dim_vector& dv, bool fill) const |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
88 { |
5731 | 89 if (fill) |
90 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
91 boolNDArray retval (dv, false); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
92 if (dv.numel ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
93 retval(0) = scalar; |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
94 return retval; |
5731 | 95 } |
96 else | |
97 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
98 boolNDArray retval (dv); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
99 if (dv.numel ()) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
100 retval(0) = scalar; |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
101 return retval; |
5731 | 102 } |
103 } | |
104 | |
2871 | 105 octave_value |
5279 | 106 octave_bool::convert_to_str_internal (bool, bool, char type) const |
2871 | 107 { |
108 char s[2]; | |
4358 | 109 s[0] = static_cast<char> (scalar); |
2871 | 110 s[1] = '\0'; |
111 | |
5279 | 112 return octave_value (s, type); |
2871 | 113 } |
114 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
115 bool |
6974 | 116 octave_bool::save_ascii (std::ostream& os) |
4687 | 117 { |
118 double d = double_value (); | |
119 | |
120 octave_write_double (os, d); | |
121 os << "\n"; | |
122 | |
123 return true; | |
124 } | |
125 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
126 bool |
4687 | 127 octave_bool::load_ascii (std::istream& is) |
128 { | |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
129 scalar = (octave_read_value<double> (is) != 0.); |
4687 | 130 |
131 if (!is) | |
132 { | |
133 error ("load: failed to load scalar constant"); | |
134 return false; | |
135 } | |
136 | |
137 return true; | |
138 } | |
139 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
140 bool |
4687 | 141 octave_bool::save_binary (std::ostream& os, bool& /* save_as_floats */) |
142 { | |
143 char tmp = (scalar ? 1 : 0); | |
5760 | 144 os.write (reinterpret_cast<char *> (&tmp), 1); |
4687 | 145 |
146 return true; | |
147 } | |
148 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
149 bool |
4687 | 150 octave_bool::load_binary (std::istream& is, bool /* swap */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
151 oct_mach_info::float_format /* fmt */) |
4687 | 152 { |
153 char tmp; | |
5760 | 154 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
4687 | 155 return false; |
156 scalar = (tmp ? 1 : 0); | |
157 return true; | |
158 } | |
159 | |
160 #if defined (HAVE_HDF5) | |
4944 | 161 |
4687 | 162 bool |
163 octave_bool::save_hdf5 (hid_t loc_id, const char *name, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
164 bool /* save_as_floats */) |
4687 | 165 { |
166 hsize_t dimens[3]; | |
18099
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
167 hid_t space_hid, data_hid; |
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
168 space_hid = data_hid = -1; |
4687 | 169 bool retval = true; |
170 | |
4815 | 171 space_hid = H5Screate_simple (0, dimens, 0); |
4687 | 172 if (space_hid < 0) return false; |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
173 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
174 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
176 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
177 data_hid = H5Dcreate (loc_id, name, H5T_NATIVE_DOUBLE, space_hid, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
178 H5P_DEFAULT); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
179 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
180 if (data_hid < 0) |
4687 | 181 { |
182 H5Sclose (space_hid); | |
183 return false; | |
184 } | |
185 | |
186 double tmp = double_value (); | |
187 retval = H5Dwrite (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
188 H5P_DEFAULT, &tmp) >= 0; |
4687 | 189 |
190 H5Dclose (data_hid); | |
191 H5Sclose (space_hid); | |
4837 | 192 |
4687 | 193 return retval; |
194 } | |
195 | |
196 bool | |
9881
b3089dba88bf
Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents:
9469
diff
changeset
|
197 octave_bool::load_hdf5 (hid_t loc_id, const char *name) |
4687 | 198 { |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
199 #if HAVE_HDF5_18 |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
200 hid_t data_hid = H5Dopen (loc_id, name, H5P_DEFAULT); |
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
201 #else |
4687 | 202 hid_t data_hid = H5Dopen (loc_id, name); |
9892
ac69e6f4b33d
Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents:
9881
diff
changeset
|
203 #endif |
4687 | 204 hid_t space_id = H5Dget_space (data_hid); |
205 | |
206 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
207 | |
208 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
209 { |
4687 | 210 H5Dclose (data_hid); |
211 return false; | |
212 } | |
213 | |
214 double dtmp; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
215 if (H5Dread (data_hid, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
216 H5P_DEFAULT, &dtmp) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
217 { |
4687 | 218 H5Dclose (data_hid); |
219 return false; | |
220 } | |
221 | |
222 scalar = (dtmp != 0.); | |
4837 | 223 |
4687 | 224 H5Dclose (data_hid); |
4837 | 225 |
4687 | 226 return true; |
227 } | |
4944 | 228 |
4687 | 229 #endif |
230 | |
5900 | 231 mxArray * |
232 octave_bool::as_mxArray (void) const | |
233 { | |
234 mxArray *retval = new mxArray (mxLOGICAL_CLASS, 1, 1, mxREAL); | |
235 | |
236 bool *pr = static_cast<bool *> (retval->get_data ()); | |
237 | |
238 pr[0] = scalar; | |
239 | |
240 return retval; | |
241 } |