Mercurial > octave
annotate libinterp/octave-value/ov-base-int.cc @ 21102:dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
* graphics.cc (err_set_invalid): Add OCTAVE_NORETURN attribute.
* graphisc.cc: Rename gripe_set_invalid to err_set_invalid.
* jit-typeinfo.cc (err_bad_result): Rename from gripe_bad_result.
* load-save.cc (err_file_open): Rename from gripe_file_open.
* ls-mat5.cc (warn_dim_too_large): Rename from gripe_dim_too_large.
* oct-stream.cc (err_invalid_file_id): Rename from gripe_invalid_file_id.
* txt-eng-ft.cc (warn_missing_glyph, warn_glyph_render): Rename from
gripe_missing_glyph, gripe_glyph_render.
* xpow.cc: Add FIXME about strange gripe_failed_diagonalization function.
* ov-base-int.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-cell.cc,
ov-class.cc, ov-complex.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc,
ov-fcn-inline.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-range.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc,
ov-str-mat.cc, ov-struct.cc
(warn_load, warn_save):
ov-base.cc (warn_load, warn_save, err_indexed_assignment,
err_assign_conversion_failed, err_no_conversion): Rename from gripe_XXX
version.
* ov-base.h (warn_load, warn_save): Rename from gripe_load, gripe_save.
* ov-classdef.cc (err_method_access, err_property_access): Rename from
gripe_method_access, gripe_property_access.
* ov-classdef.h (err_invalid_object): Rename from gripe_invalid_object.
* ov-oncleanup.h (gripe_internal): Delete function. Place single calling
instance directly in code.
* ov.cc (err_binary_op, err_binary_op_conv, err_unary_op, err_unary_op_conv,
err_unary_op_conversion_failed): Add OCTAVE_NORETURN attribute. Rename from
gripe_XXX.
* ov.cc (err_cat_op, err_cat_op_conv, ): Rename from gripe_XXX.
* lex.h (warn_single_quote_string, warn_language_extension,
maybe_warn_language_extension_comment, warn_language_extension_continuation,
warn_language_extension_operator): Rename from gripe_XXX.
* lex.ll (warn_single_quote_string, warn_language_extension,
maybe_warn_language_extension_comment, warn_language_extension_continuation,
warn_language_extension_operator): Rename from gripe_XXX.
* pt-check.cc (errmsg): Rename from gripe.
* pt-check.h (errmsg): Add OCTAVE_NORETURN attribute. Rename from gripe.
* PermMatrix.cc (err_invalid_permutation): Add OCTAVE_NORETURN attribute.
Rename from gripe_invalid_permutation.
* idx-vector.cc (err_invalid_range): Add OCTAVE_NORETURN attribute.
Rename from gripe_invalid_range.
liboctave/numeric/lo-specfun.cc (err_betainc_nonconformant): Add
OCTAVE_NORETURN attribute. Rename from gripe_betainc_nonconformant.
* oct-group.cc (err_invalid): New static function.
* oct-group.h (gripe_invalid): Delete private function.
* oct-passwd.cc (err_invalid): New static function.
* oct-passwd.h (gripe_invalid): Delete private function.
* data-conv.cc (err_unrecognized_float_fmt): Add OCTAVE_NORETURN attribute.
Rename from gripe_unrecognized_float_fmt.
* lo-cutils.c (warn_missing_wait_macro): Rename from gripe_missing_wait_macro.
* unwind-prot.cc (err_unhandled_exception): Rename from gripe_exception.
* unwind-prot.h (err_unhandled_exception): Rename from gripe_exception.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 18 Jan 2016 21:06:26 -0800 |
parents | e39e05d90788 |
children | 95f8c8cdbffe |
rev | line source |
---|---|
4903 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
18678
diff
changeset
|
3 Copyright (C) 2004-2015 John W. Eaton |
4903 | 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. | |
4903 | 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/>. | |
4903 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <iostream> | |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
28 #include <limits> |
4903 | 29 #include <vector> |
30 | |
31 #include "lo-ieee.h" | |
32 #include "lo-utils.h" | |
33 #include "mx-base.h" | |
34 #include "quit.h" | |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7534
diff
changeset
|
35 #include "oct-locbuf.h" |
4903 | 36 |
37 #include "defun.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21022
diff
changeset
|
38 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20893
diff
changeset
|
39 #include "ovl.h" |
4903 | 40 #include "oct-lvalue.h" |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
41 #include "oct-hdf5.h" |
4944 | 42 #include "oct-stream.h" |
4903 | 43 #include "ops.h" |
44 #include "ov-base.h" | |
45 #include "ov-base-mat.h" | |
46 #include "ov-base-mat.cc" | |
47 #include "ov-base-scalar.h" | |
48 #include "ov-base-scalar.cc" | |
49 #include "ov-base-int.h" | |
50 #include "ov-int-traits.h" | |
51 #include "pr-output.h" | |
52 #include "variables.h" | |
53 | |
54 #include "byte-swap.h" | |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20228
diff
changeset
|
55 #include "ls-oct-text.h" |
4903 | 56 #include "ls-utils.h" |
57 #include "ls-hdf5.h" | |
58 | |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
59 // We have all the machinery below (octave_base_int_helper and |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
60 // octave_base_int_helper_traits) to avoid a few warnings from GCC |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
61 // about comparisons always false due to limited range of data types. |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 // Ugh. The cure may be worse than the disease. |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
63 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
64 template <class T, bool is_signed = true, bool can_be_too_big = true> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
65 struct octave_base_int_helper |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
66 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
67 static bool |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
68 char_value_out_of_range (T val) |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
69 { |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
70 return val < 0 || val > std::numeric_limits<unsigned char>::max (); |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
71 } |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
72 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
73 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
74 template <class T> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
75 struct octave_base_int_helper<T, false, false> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
76 { |
9149
7120fbbecf97
ov-base-int.cc: correct result for template specialization
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
77 static bool char_value_out_of_range (T) { return false; } |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
78 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
79 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
80 template <class T> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
81 struct octave_base_int_helper<T, false, true> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
82 { |
15215
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
83 static bool char_value_out_of_range (T val) |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
84 { |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
85 return val > std::numeric_limits<unsigned char>::max (); |
9020dddc925a
use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
86 } |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
87 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
88 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
89 template <class T> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
90 struct octave_base_int_helper<T, true, false> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
91 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
92 static bool char_value_out_of_range (T val) { return val < 0; } |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
93 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
94 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
95 // For all types other than char, signed char, and unsigned char, we |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
96 // assume that the upper limit for the range of allowable values is |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
97 // larger than the range for unsigned char. If that's not true, we |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
98 // are still OK, but will see the warnings again for any other types |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
99 // that do not meet this assumption. |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
100 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
101 template <class T> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
102 struct octave_base_int_helper_traits |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
103 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
104 static const bool can_be_larger_than_uchar_max = true; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
105 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
106 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
107 template <> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
108 struct octave_base_int_helper_traits<char> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
109 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
110 static const bool can_be_larger_than_uchar_max = false; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
111 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
112 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
113 template <> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
114 struct octave_base_int_helper_traits<signed char> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
115 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
116 static const bool can_be_larger_than_uchar_max = false; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
117 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
118 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
119 template <> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
120 struct octave_base_int_helper_traits<unsigned char> |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
121 { |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
122 static const bool can_be_larger_than_uchar_max = false; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
123 }; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
124 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
125 |
4903 | 126 template <class T> |
5759 | 127 octave_base_value * |
4903 | 128 octave_base_int_matrix<T>::try_narrowing_conversion (void) |
129 { | |
5759 | 130 octave_base_value *retval = 0; |
4903 | 131 |
20228
00cf2847355d
Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
20218
diff
changeset
|
132 if (this->matrix.numel () == 1) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 retval = new typename octave_value_int_traits<T>::scalar_type |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
134 (this->matrix (0)); |
4903 | 135 |
136 return retval; | |
137 } | |
138 | |
139 template <class T> | |
5992 | 140 octave_value |
141 octave_base_int_matrix<T>::convert_to_str_internal (bool, bool, char type) const | |
142 { | |
143 octave_value retval; | |
144 dim_vector dv = this->dims (); | |
145 octave_idx_type nel = dv.numel (); | |
146 | |
147 charNDArray chm (dv); | |
148 | |
149 bool warned = false; | |
150 | |
151 for (octave_idx_type i = 0; i < nel; i++) | |
152 { | |
10142
829e69ec3110
make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents:
9892
diff
changeset
|
153 octave_quit (); |
5992 | 154 |
8918
f5408862892f
Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents:
8377
diff
changeset
|
155 typename T::element_type tmp = this->matrix(i); |
5992 | 156 |
8918
f5408862892f
Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents:
8377
diff
changeset
|
157 typedef typename T::element_type::val_type val_type; |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
158 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
159 val_type ival = tmp.value (); |
5992 | 160 |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
161 static const bool is_signed = std::numeric_limits<val_type>::is_signed; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
162 static const bool can_be_larger_than_uchar_max |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max; |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
164 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
165 if (octave_base_int_helper<val_type, is_signed, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 can_be_larger_than_uchar_max>::char_value_out_of_range (ival)) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
167 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 // FIXME: is there something better we could do? |
5992 | 169 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
170 ival = 0; |
5992 | 171 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
172 if (! warned) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 ::warning ("range error for conversion to character value"); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 warned = true; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
176 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
177 } |
5992 | 178 else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 chm (i) = static_cast<char> (ival); |
5992 | 180 } |
181 | |
9689
34d6f005db4b
eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents:
9149
diff
changeset
|
182 retval = octave_value (chm, type); |
5992 | 183 |
184 return retval; | |
185 } | |
186 | |
187 template <class T> | |
4903 | 188 bool |
6974 | 189 octave_base_int_matrix<T>::save_ascii (std::ostream& os) |
4903 | 190 { |
4932 | 191 dim_vector d = this->dims (); |
4903 | 192 |
193 os << "# ndims: " << d.length () << "\n"; | |
194 | |
195 for (int i = 0; i < d.length (); i++) | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19875
diff
changeset
|
196 os << " " << d(i); |
4903 | 197 |
4932 | 198 os << "\n" << this->matrix; |
4903 | 199 |
200 return true; | |
201 } | |
202 | |
203 template <class T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
204 bool |
4903 | 205 octave_base_int_matrix<T>::load_ascii (std::istream& is) |
206 { | |
207 int mdims = 0; | |
208 bool success = true; | |
209 | |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
210 if (! extract_keyword (is, "ndims", mdims, true)) |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
211 error ("load: failed to extract number of dimensions"); |
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
212 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
213 if (mdims < 0) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
214 error ("load: failed to extract number of rows and columns"); |
4903 | 215 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
216 dim_vector dv; |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
217 dv.resize (mdims); |
4903 | 218 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
219 for (int i = 0; i < mdims; i++) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
220 is >> dv(i); |
4903 | 221 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
222 T tmp(dv); |
4903 | 223 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
224 is >> tmp; |
20962
3aa293be0e8d
maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
225 |
20978
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
226 if (! is) |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
227 error ("load: failed to load matrix constant"); |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
228 |
a5b500efca9f
maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
229 this->matrix = tmp; |
4903 | 230 |
231 return success; | |
232 } | |
233 | |
234 template <class T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
235 bool |
4917 | 236 octave_base_int_matrix<T>::save_binary (std::ostream& os, bool&) |
4903 | 237 { |
4932 | 238 dim_vector d = this->dims (); |
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
|
239 if (d.length () < 1) |
4903 | 240 return false; |
241 | |
242 // Use negative value for ndims to differentiate with old format!! | |
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
|
243 int32_t tmp = - d.length (); |
5760 | 244 os.write (reinterpret_cast<char *> (&tmp), 4); |
4903 | 245 for (int i=0; i < d.length (); i++) |
246 { | |
247 tmp = d(i); | |
5760 | 248 os.write (reinterpret_cast<char *> (&tmp), 4); |
4903 | 249 } |
250 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
251 os.write (reinterpret_cast<const char *> (this->matrix.data ()), |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
252 this->byte_size ()); |
4903 | 253 |
254 return true; | |
255 } | |
256 | |
257 template <class T> | |
258 bool | |
259 octave_base_int_matrix<T>::load_binary (std::istream& is, bool swap, | |
18678
6113e0c6920b
maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents:
18100
diff
changeset
|
260 oct_mach_info::float_format) |
4903 | 261 { |
5828 | 262 int32_t mdims; |
5760 | 263 if (! is.read (reinterpret_cast<char *> (&mdims), 4)) |
4903 | 264 return false; |
265 if (swap) | |
4944 | 266 swap_bytes<4> (&mdims); |
4917 | 267 if (mdims >= 0) |
268 return false; | |
4903 | 269 |
4917 | 270 mdims = - mdims; |
5828 | 271 int32_t di; |
4917 | 272 dim_vector dv; |
273 dv.resize (mdims); | |
4903 | 274 |
4917 | 275 for (int i = 0; i < mdims; i++) |
4903 | 276 { |
5760 | 277 if (! is.read (reinterpret_cast<char *> (&di), 4)) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 return false; |
4903 | 279 if (swap) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 swap_bytes<4> (&di); |
4917 | 281 dv(i) = di; |
4903 | 282 } |
283 | |
5157 | 284 // Convert an array with a single dimension to be a row vector. |
285 // Octave should never write files like this, other software | |
286 // might. | |
287 | |
288 if (mdims == 1) | |
289 { | |
290 mdims = 2; | |
291 dv.resize (mdims); | |
292 dv(1) = dv(0); | |
293 dv(0) = 1; | |
294 } | |
295 | |
4917 | 296 T m (dv); |
297 | |
5760 | 298 if (! is.read (reinterpret_cast<char *> (m.fortran_vec ()), m.byte_size ())) |
4917 | 299 return false; |
4903 | 300 |
4917 | 301 if (swap) |
302 { | |
303 int nel = dv.numel (); | |
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
|
304 int bytes = nel / m.byte_size (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
305 for (int i = 0; i < nel; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 switch (bytes) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 case 8: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
309 swap_bytes<8> (&m(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 case 4: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
312 swap_bytes<4> (&m(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
314 case 2: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
315 swap_bytes<2> (&m(i)); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
316 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
317 case 1: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 default: |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
319 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
320 } |
4917 | 321 } |
322 | |
4932 | 323 this->matrix = m; |
4903 | 324 return true; |
325 } | |
326 | |
327 template <class T> | |
328 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
329 octave_base_int_matrix<T>::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) |
4903 | 330 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
331 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
332 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
333 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
334 |
4917 | 335 hid_t save_type_hid = HDF5_SAVE_TYPE; |
4932 | 336 dim_vector dv = this->dims (); |
4903 | 337 int empty = save_hdf5_empty (loc_id, name, dv); |
338 if (empty) | |
339 return (empty > 0); | |
340 | |
341 int rank = dv.length (); | |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
342 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
|
343 space_hid = data_hid = -1; |
4903 | 344 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); |
345 | |
346 // Octave uses column-major, while HDF5 uses row-major ordering | |
347 for (int i = 0; i < rank; i++) | |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19875
diff
changeset
|
348 hdims[i] = dv(rank-i-1); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
349 |
4903 | 350 space_hid = H5Screate_simple (rank, hdims, 0); |
351 | |
352 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
|
353 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
354 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
355 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
356 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
357 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
358 octave_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
|
359 #endif |
4903 | 360 if (data_hid < 0) |
361 { | |
362 H5Sclose (space_hid); | |
363 return false; | |
364 } | |
365 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
366 retval = H5Dwrite (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
367 octave_H5P_DEFAULT, this->matrix.data ()) >= 0; |
4903 | 368 |
369 H5Dclose (data_hid); | |
370 H5Sclose (space_hid); | |
371 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
372 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
373 this->warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
374 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
375 |
4903 | 376 return retval; |
377 } | |
378 | |
379 template <class T> | |
380 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
381 octave_base_int_matrix<T>::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4903 | 382 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
383 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
384 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
385 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
386 |
4917 | 387 hid_t save_type_hid = HDF5_SAVE_TYPE; |
4903 | 388 dim_vector dv; |
389 int empty = load_hdf5_empty (loc_id, name, dv); | |
390 if (empty > 0) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
391 this->matrix.resize (dv); |
4903 | 392 if (empty) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
393 return (empty > 0); |
4903 | 394 |
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
|
395 #if HAVE_HDF5_18 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
396 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
397 #else |
4903 | 398 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
|
399 #endif |
4903 | 400 hid_t space_id = H5Dget_space (data_hid); |
401 | |
402 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
403 |
4903 | 404 if (rank < 1) |
405 { | |
406 H5Sclose (space_id); | |
407 H5Dclose (data_hid); | |
408 return false; | |
409 } | |
410 | |
411 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank); | |
412 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank); | |
413 | |
414 H5Sget_simple_extent_dims (space_id, hdims, maxdims); | |
415 | |
416 // Octave uses column-major, while HDF5 uses row-major ordering | |
417 if (rank == 1) | |
418 { | |
419 dv.resize (2); | |
420 dv(0) = 1; | |
421 dv(1) = hdims[0]; | |
422 } | |
423 else | |
424 { | |
425 dv.resize (rank); | |
426 for (hsize_t i = 0, j = rank - 1; i < rank; i++, j--) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
427 dv(j) = hdims[i]; |
4903 | 428 } |
429 | |
4917 | 430 T m (dv); |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
431 if (H5Dread (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
432 octave_H5P_DEFAULT, m.fortran_vec ()) >= 0) |
4903 | 433 { |
434 retval = true; | |
4932 | 435 this->matrix = m; |
4903 | 436 } |
437 | |
438 H5Sclose (space_id); | |
439 H5Dclose (data_hid); | |
440 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
441 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
442 this->warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
443 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
444 |
4903 | 445 return retval; |
446 } | |
447 | |
448 template <class T> | |
449 void | |
450 octave_base_int_matrix<T>::print_raw (std::ostream& os, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
451 bool pr_as_read_syntax) const |
4903 | 452 { |
4932 | 453 octave_print_internal (os, this->matrix, pr_as_read_syntax, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
454 this->current_print_indent_level ()); |
4903 | 455 } |
456 | |
457 template <class T> | |
5992 | 458 octave_value |
459 octave_base_int_scalar<T>::convert_to_str_internal (bool, bool, char type) const | |
460 { | |
461 octave_value retval; | |
462 | |
463 T tmp = this->scalar; | |
464 | |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
465 typedef typename T::val_type val_type; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
466 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
467 val_type ival = tmp.value (); |
5992 | 468 |
7534
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
469 static const bool is_signed = std::numeric_limits<val_type>::is_signed; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
470 static const bool can_be_larger_than_uchar_max |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
471 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max; |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
472 |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
473 if (octave_base_int_helper<val_type, is_signed, |
ef755c763b62
avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
474 can_be_larger_than_uchar_max>::char_value_out_of_range (ival)) |
5992 | 475 { |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
476 // FIXME: is there something better we could do? |
5992 | 477 |
478 ival = 0; | |
479 | |
480 ::warning ("range error for conversion to character value"); | |
481 } | |
482 else | |
483 retval = octave_value (std::string (1, static_cast<char> (ival)), type); | |
484 | |
485 return retval; | |
486 } | |
487 | |
488 template <class T> | |
4903 | 489 bool |
6974 | 490 octave_base_int_scalar<T>::save_ascii (std::ostream& os) |
4903 | 491 { |
4932 | 492 os << this->scalar << "\n"; |
4903 | 493 return true; |
494 } | |
495 | |
496 template <class T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
497 bool |
4903 | 498 octave_base_int_scalar<T>::load_ascii (std::istream& is) |
499 { | |
4932 | 500 is >> this->scalar; |
20893
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
501 if (! is) |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
502 error ("load: failed to load scalar constant"); |
384ff5aa9437
2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
503 |
4903 | 504 return true; |
505 } | |
506 | |
507 template <class T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
508 bool |
4917 | 509 octave_base_int_scalar<T>::save_binary (std::ostream& os, bool&) |
4903 | 510 { |
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
|
511 os.write (reinterpret_cast<char *> (&(this->scalar)), this->byte_size ()); |
4903 | 512 return true; |
513 } | |
514 | |
515 template <class T> | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
516 bool |
4903 | 517 octave_base_int_scalar<T>::load_binary (std::istream& is, bool swap, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
518 oct_mach_info::float_format) |
4903 | 519 { |
4917 | 520 T tmp; |
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
|
521 if (! is.read (reinterpret_cast<char *> (&tmp), this->byte_size ())) |
4903 | 522 return false; |
523 | |
4917 | 524 if (swap) |
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
|
525 switch (this->byte_size ()) |
4917 | 526 { |
527 case 8: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
528 swap_bytes<8> (&tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
529 break; |
4917 | 530 case 4: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
531 swap_bytes<4> (&tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
532 break; |
4917 | 533 case 2: |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
534 swap_bytes<2> (&tmp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
535 break; |
4917 | 536 case 1: |
537 default: | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
538 break; |
4917 | 539 } |
4932 | 540 this->scalar = tmp; |
4903 | 541 return true; |
542 } | |
543 | |
544 template <class T> | |
545 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
546 octave_base_int_scalar<T>::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool) |
4903 | 547 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
548 bool retval = false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
549 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
550 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
551 |
4917 | 552 hid_t save_type_hid = HDF5_SAVE_TYPE; |
4903 | 553 hsize_t dimens[3]; |
18100
6a71e5030df5
Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
554 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
|
555 space_hid = data_hid = -1; |
4903 | 556 |
557 space_hid = H5Screate_simple (0, dimens, 0); | |
558 if (space_hid < 0) return false; | |
559 | |
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
|
560 #if HAVE_HDF5_18 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
561 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
562 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_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
|
563 #else |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
564 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid, |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
565 octave_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
|
566 #endif |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
567 if (data_hid < 0) |
4903 | 568 { |
569 H5Sclose (space_hid); | |
570 return false; | |
571 } | |
572 | |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
573 retval = H5Dwrite (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
574 octave_H5P_DEFAULT, &(this->scalar)) >= 0; |
4903 | 575 |
576 H5Dclose (data_hid); | |
577 H5Sclose (space_hid); | |
578 | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
579 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
580 this->warn_save ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
581 #endif |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
582 |
4903 | 583 return retval; |
584 } | |
585 | |
586 template <class T> | |
587 bool | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
588 octave_base_int_scalar<T>::load_hdf5 (octave_hdf5_id loc_id, const char *name) |
4903 | 589 { |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
590 #if defined (HAVE_HDF5) |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
591 |
4917 | 592 hid_t save_type_hid = HDF5_SAVE_TYPE; |
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
|
593 #if HAVE_HDF5_18 |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
594 hid_t data_hid = H5Dopen (loc_id, name, octave_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
|
595 #else |
4903 | 596 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
|
597 #endif |
4903 | 598 hid_t space_id = H5Dget_space (data_hid); |
599 | |
600 hsize_t rank = H5Sget_simple_extent_ndims (space_id); | |
601 | |
602 if (rank != 0) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
603 { |
4903 | 604 H5Dclose (data_hid); |
605 return false; | |
606 } | |
607 | |
4917 | 608 T tmp; |
21022
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
609 if (H5Dread (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL, |
ebc439187d29
avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents:
20978
diff
changeset
|
610 octave_H5P_DEFAULT, &tmp) < 0) |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
611 { |
4903 | 612 H5Dclose (data_hid); |
613 return false; | |
614 } | |
615 | |
4932 | 616 this->scalar = tmp; |
4903 | 617 |
618 H5Dclose (data_hid); | |
619 | |
620 return true; | |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
621 |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
622 #else |
21102
dfcb9d74b253
Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
623 this->warn_load ("hdf5"); |
19863
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
624 return false; |
09ed6f7538dd
avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents:
19697
diff
changeset
|
625 #endif |
4903 | 626 } |
4944 | 627 |