annotate libinterp/octave-value/ov-base-int.cc @ 19696:4197fc428c7d

maint: Update copyright notices for 2015.
author John W. Eaton <jwe@octave.org>
date Wed, 11 Feb 2015 14:19:08 -0500
parents 6113e0c6920b
children 09ed6f7538dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
1 /*
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
2
19696
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18677
diff changeset
3 Copyright (C) 2004-2015 John W. Eaton
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
4
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
6
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
10 option) any later version.
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
11
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
15 for more details.
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
16
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6974
diff changeset
19 <http://www.gnu.org/licenses/>.
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
20
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
21 */
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
22
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
24 #include <config.h>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
25 #endif
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
26
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
29 #include <vector>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
30
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
31 #include "lo-ieee.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
32 #include "lo-utils.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
33 #include "mx-base.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
36
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
37 #include "defun.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
38 #include "gripes.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
39 #include "oct-obj.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
40 #include "oct-lvalue.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
41 #include "oct-stream.h"
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
42 #include "ops.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
43 #include "ov-base.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
44 #include "ov-base-mat.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
45 #include "ov-base-mat.cc"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
46 #include "ov-base-scalar.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
47 #include "ov-base-scalar.cc"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
48 #include "ov-base-int.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
49 #include "ov-int-traits.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
50 #include "pr-output.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
51 #include "variables.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
52
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
53 #include "byte-swap.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
54 #include "ls-oct-ascii.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
55 #include "ls-utils.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
56 #include "ls-hdf5.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
57
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
58 // 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
59 // 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
60 // 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
61 // 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
62
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 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
64 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
65 {
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 static bool
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
67 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
68 {
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
69 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
70 }
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
71 };
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 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
74 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
75 {
9149
7120fbbecf97 ov-base-int.cc: correct result for template specialization
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
76 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
77 };
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 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
80 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
81 {
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
82 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
83 {
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
84 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
85 }
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
86 };
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 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
89 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
90 {
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 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
92 };
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 // 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
95 // 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
96 // 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
97 // 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
98 // 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
99
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 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
101 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
102 {
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 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
104 };
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 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
107 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
108 {
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 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
110 };
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 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
113 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
114 {
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 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
116 };
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 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
119 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
120 {
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 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
122 };
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
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
125 template <class T>
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
126 octave_base_value *
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
127 octave_base_int_matrix<T>::try_narrowing_conversion (void)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
128 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
129 octave_base_value *retval = 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
130
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
131 if (this->matrix.nelem () == 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
132 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
133 (this->matrix (0));
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
134
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
135 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
136 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
137
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
138 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
139 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
140 octave_base_int_matrix<T>::convert_to_str_internal (bool, bool, char type) const
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
141 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
142 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
143 dim_vector dv = this->dims ();
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
144 octave_idx_type nel = dv.numel ();
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
145
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
146 charNDArray chm (dv);
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
147
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
148 bool warned = false;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
149
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
150 for (octave_idx_type i = 0; i < nel; i++)
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
151 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
152 octave_quit ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
153
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8377
diff changeset
154 typename T::element_type tmp = this->matrix(i);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
155
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8377
diff changeset
156 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
157
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 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
159
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
160 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
161 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
162 = 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
163
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 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
165 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
166 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
167 // FIXME: is there something better we could do?
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
168
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
169 ival = 0;
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
170
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
171 if (! warned)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
173 ::warning ("range error for conversion to character value");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 warned = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 }
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
177 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
178 chm (i) = static_cast<char> (ival);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
179 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
180
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 9149
diff changeset
181 retval = octave_value (chm, type);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
182
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
183 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
184 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
185
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
186 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
187 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
188 octave_base_int_matrix<T>::save_ascii (std::ostream& os)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
189 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
190 dim_vector d = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
191
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
192 os << "# ndims: " << d.length () << "\n";
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
193
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
194 for (int i = 0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
195 os << " " << d (i);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
196
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
197 os << "\n" << this->matrix;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
198
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
199 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
200 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
201
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
202 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
203 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
204 octave_base_int_matrix<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
205 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
206 int mdims = 0;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
207 bool success = true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
208
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
209 if (extract_keyword (is, "ndims", mdims, true))
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
210 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
211 if (mdims >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
212 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
213 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
214 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
215
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
216 for (int i = 0; i < mdims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
217 is >> dv(i);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
218
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
219 T tmp(dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
220
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
221 is >> tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
222
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
223 if (!is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
224 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
225 error ("load: failed to load matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
226 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
227 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
228
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
229 this->matrix = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
230 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
231 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
232 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
233 error ("load: failed to extract number of rows and columns");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
235 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
236 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
237 else
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
238 error ("load: failed to extract number of dimensions");
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
239
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
240 return success;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
241 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
242
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
243 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
244 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
245 octave_base_int_matrix<T>::save_binary (std::ostream& os, bool&)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
246 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
247 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
248 if (d.length () < 1)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
249 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
250
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
251 // 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
252 int32_t tmp = - d.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
253 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
254 for (int i=0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
255 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
256 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
257 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
258 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
259
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
260 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
261 this->byte_size ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
262
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
263 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
264 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
265
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
266 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
267 bool
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
268 octave_base_int_matrix<T>::load_binary (std::istream& is, bool swap,
18677
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18099
diff changeset
269 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
270 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
271 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
272 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
273 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
274 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
275 swap_bytes<4> (&mdims);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
276 if (mdims >= 0)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
277 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
278
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
279 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
280 int32_t di;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
281 dim_vector dv;
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
282 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
283
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
284 for (int i = 0; i < mdims; i++)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
285 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
286 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
287 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
288 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
289 swap_bytes<4> (&di);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
290 dv(i) = di;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
291 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
292
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
293 // Convert an array with a single dimension to be a row vector.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
294 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
295 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
296
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
297 if (mdims == 1)
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
298 {
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
299 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
300 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
301 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
302 dv(0) = 1;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
303 }
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
304
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
305 T m (dv);
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
306
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
307 if (! is.read (reinterpret_cast<char *> (m.fortran_vec ()), m.byte_size ()))
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
308 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
309
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
310 if (swap)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
311 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
312 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
313 int bytes = nel / m.byte_size ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
314 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 switch (bytes)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318 swap_bytes<8> (&m(i));
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 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
321 swap_bytes<4> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
322 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
323 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
324 swap_bytes<2> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
325 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
326 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
327 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
328 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
329 }
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
330 }
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
331
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
332 this->matrix = m;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
333 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
334 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
335
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
336 #if defined (HAVE_HDF5)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
337
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
338 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
339 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
340 octave_base_int_matrix<T>::save_hdf5 (hid_t loc_id, const char *name, bool)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
341 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
342 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
343 bool retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
344 dim_vector dv = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
345 int empty = save_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
346 if (empty)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
347 return (empty > 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
348
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
349 int rank = dv.length ();
18099
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
350 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
351 space_hid = data_hid = -1;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
352 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
353
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
354 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
355 for (int i = 0; i < rank; i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
356 hdims[i] = dv (rank-i-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
357
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
358 space_hid = H5Screate_simple (rank, hdims, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
359
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
360 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
361 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
362 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
363 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
364 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
365 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
366 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
367 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
368 if (data_hid < 0)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
369 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
370 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
371 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
372 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
373
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
374 retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
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
375 H5P_DEFAULT, this->matrix.data ()) >= 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
376
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
377 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
378 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
379
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
380 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
381 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
382
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
383 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
384 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9689
diff changeset
385 octave_base_int_matrix<T>::load_hdf5 (hid_t loc_id, const char *name)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
386 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
387 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
388 bool retval = false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
389 dim_vector dv;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
390 int empty = load_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
391 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
392 this->matrix.resize (dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
393 if (empty)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
394 return (empty > 0);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
395
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
396 #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
397 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
398 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
399 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
400 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
401 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
402
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
403 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
404
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
405 if (rank < 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
406 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
407 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
408 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
409 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
410 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
411
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
412 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
413 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
414
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
415 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
416
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
417 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
418 if (rank == 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
419 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
420 dv.resize (2);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
421 dv(0) = 1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
422 dv(1) = hdims[0];
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
423 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
424 else
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
425 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
426 dv.resize (rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
427 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
428 dv(j) = hdims[i];
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
429 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
430
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
431 T m (dv);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
432 if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
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
433 H5P_DEFAULT, m.fortran_vec ()) >= 0)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
434 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
435 retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
436 this->matrix = m;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
437 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
438
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
439 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
440 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
441
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
442 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
443 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
444
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
445 #endif
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
446
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
447 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
448 void
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
449 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
450 bool pr_as_read_syntax) const
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
451 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
452 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
453 this->current_print_indent_level ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
454 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
455
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
456 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
457 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
458 octave_base_int_scalar<T>::convert_to_str_internal (bool, bool, char type) const
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
459 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
460 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
461
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
462 T tmp = this->scalar;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
463
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
464 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
465
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 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
467
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
468 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
469 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
470 = 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
471
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 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
473 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
474 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
475 // FIXME: is there something better we could do?
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
476
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
477 ival = 0;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
478
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
479 ::warning ("range error for conversion to character value");
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
480 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
481 else
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
482 retval = octave_value (std::string (1, static_cast<char> (ival)), type);
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
483
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
484 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
485 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
486
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
487 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
488 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
489 octave_base_int_scalar<T>::save_ascii (std::ostream& os)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
490 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
491 os << this->scalar << "\n";
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
492 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
493 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
494
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
495 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
496 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
497 octave_base_int_scalar<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
498 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
499 is >> this->scalar;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
500 if (!is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
501 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
502 error ("load: failed to load scalar constant");
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
503 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
504 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
505 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
506 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
507
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
508 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
509 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
510 octave_base_int_scalar<T>::save_binary (std::ostream& os, bool&)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
511 {
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
512 os.write (reinterpret_cast<char *> (&(this->scalar)), this->byte_size ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
513 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
514 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
515
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
516 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
517 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
518 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
519 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
520 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
521 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
522 if (! is.read (reinterpret_cast<char *> (&tmp), this->byte_size ()))
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
523 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
524
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
525 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
526 switch (this->byte_size ())
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
527 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
528 case 8:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 swap_bytes<8> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
531 case 4:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
532 swap_bytes<4> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
533 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
534 case 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
535 swap_bytes<2> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
536 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
537 case 1:
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
538 default:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
539 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
540 }
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
541 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
542 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
543 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
544
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
545 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
546
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
547 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
548 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
549 octave_base_int_scalar<T>::save_hdf5 (hid_t loc_id, const char *name, bool)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
550 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
551 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
552 bool retval = true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
553 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
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
556
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
557 space_hid = H5Screate_simple (0, dimens, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
558 if (space_hid < 0) return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
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,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
562 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
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,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
565 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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
568 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
569 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
570 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
571 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
572
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
573 retval = H5Dwrite (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
574 H5P_DEFAULT, &(this->scalar)) >= 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
575
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
576 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
577 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
578
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
579 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
580 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
581
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
582 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
583 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9689
diff changeset
584 octave_base_int_scalar<T>::load_hdf5 (hid_t loc_id, const char *name)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
585 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
586 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
587 #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
588 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
589 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
590 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
591 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
592 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
593
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
594 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
595
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
596 if (rank != 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
597 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
598 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
599 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
600 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
601
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
602 T tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
603 if (H5Dread (data_hid, save_type_hid, H5S_ALL, H5S_ALL,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
604 H5P_DEFAULT, &tmp) < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
605 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
606 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
607 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
608 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
609
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
610 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
611
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
612 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
613
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
614 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
615 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
616
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
617 #endif