annotate libinterp/octave-value/ov-base-int.cc @ 15879:f69530e3600d

make docstrings for __java_init__ and __java_exit__ available unconditionally * ov-java.cc (F__java_init__, F__java_exit__): Move function definitions outside of HAVE_JAVA conditional.
author John W. Eaton <jwe@octave.org>
date Wed, 02 Jan 2013 19:18:15 -0500
parents 9020dddc925a
children d63878346099
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
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 11586
diff changeset
3 Copyright (C) 2004-2012 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)
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
132 retval = new typename octave_value_int_traits<T>::scalar_type (this->matrix (0));
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
133
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
134 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
135 }
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 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
138 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
139 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
140 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
141 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
142 dim_vector dv = this->dims ();
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
143 octave_idx_type nel = dv.numel ();
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
144
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
145 charNDArray chm (dv);
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
146
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
147 bool warned = false;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
148
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
149 for (octave_idx_type i = 0; i < nel; i++)
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
150 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
151 octave_quit ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
152
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8377
diff changeset
153 typename T::element_type tmp = this->matrix(i);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
154
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8377
diff changeset
155 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
156
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 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
158
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
159 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
160 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
161 = 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
162
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 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
164 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
165 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
166 // FIXME -- is there something better we could do?
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
167
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
168 ival = 0;
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
169
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
170 if (! warned)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
171 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 ::warning ("range error for conversion to character value");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
173 warned = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 }
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
176 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 chm (i) = static_cast<char> (ival);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
178 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
179
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 9149
diff changeset
180 retval = octave_value (chm, type);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
181
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
182 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
183 }
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 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
186 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
187 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
188 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
189 dim_vector d = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
190
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
191 os << "# ndims: " << d.length () << "\n";
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
192
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
193 for (int i = 0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
194 os << " " << d (i);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
195
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
196 os << "\n" << this->matrix;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
197
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
198 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
199 }
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 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
202 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
203 octave_base_int_matrix<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
204 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
205 int mdims = 0;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
206 bool success = true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
207
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
208 if (extract_keyword (is, "ndims", mdims, true))
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
209 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
210 if (mdims >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
211 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
212 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
213 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
214
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
215 for (int i = 0; i < mdims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
216 is >> dv(i);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
217
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
218 T tmp(dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
219
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
220 is >> tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
221
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
222 if (!is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
223 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
224 error ("load: failed to load matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
225 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
226 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
227
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
228 this->matrix = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
229 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
230 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
231 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
232 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
233 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
235 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
236 else
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
237 error ("load: failed to extract number of dimensions");
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
238
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
239 return success;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
240 }
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 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
243 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
244 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
245 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
246 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
247 if (d.length () < 1)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
248 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
249
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
250 // 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
251 int32_t tmp = - d.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
252 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
253 for (int i=0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
254 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
255 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
256 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
257 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
258
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
259 os.write (reinterpret_cast<const char *> (this->matrix.data ()), this->byte_size ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
260
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
261 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
264 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
265 bool
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
266 octave_base_int_matrix<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
267 oct_mach_info::float_format )
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
268 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
269 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
270 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
271 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
272 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
273 swap_bytes<4> (&mdims);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
274 if (mdims >= 0)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
275 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
276
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
277 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
278 int32_t di;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
279 dim_vector dv;
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
280 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
281
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
282 for (int i = 0; i < mdims; i++)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
283 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
284 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
285 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
286 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
287 swap_bytes<4> (&di);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
288 dv(i) = di;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
289 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
290
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
291 // 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
292 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
293 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
294
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
295 if (mdims == 1)
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 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
298 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
299 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
300 dv(0) = 1;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
301 }
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
302
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
303 T m (dv);
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
304
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
305 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
306 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
307
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
308 if (swap)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
309 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
310 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
311 int bytes = nel / m.byte_size ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
312 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 switch (bytes)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 swap_bytes<8> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
319 swap_bytes<4> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
320 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
321 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
322 swap_bytes<2> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
323 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
324 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
325 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
326 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
327 }
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
328 }
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
329
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
330 this->matrix = m;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
331 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
332 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
333
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
334 #if defined (HAVE_HDF5)
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 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
337 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
338 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
339 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
340 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
341 bool retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
342 dim_vector dv = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
343 int empty = save_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
344 if (empty)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
345 return (empty > 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
346
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
347 int rank = dv.length ();
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
348 hid_t space_hid = -1, data_hid = -1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
349 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
350
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
351 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
352 for (int i = 0; i < rank; i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
353 hdims[i] = dv (rank-i-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
354
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
355 space_hid = H5Screate_simple (rank, hdims, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
356
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
357 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
358 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
359 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
360 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
361 #else
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);
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 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
365 if (data_hid < 0)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
366 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
367 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
368 return false;
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
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
371 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
372 H5P_DEFAULT, this->matrix.data ()) >= 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
373
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
374 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
375 H5Sclose (space_hid);
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 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
378 }
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 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
381 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9689
diff changeset
382 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
383 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
384 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
385 bool retval = false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
386 dim_vector dv;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
387 int empty = load_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
388 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
389 this->matrix.resize (dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
390 if (empty)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
391 return (empty > 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
392
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
393 #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
394 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
395 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
396 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
397 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
398 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
399
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
400 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
401
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
402 if (rank < 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
403 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
404 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
405 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
406 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
407 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
408
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
409 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
410 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
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 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
413
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
414 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
415 if (rank == 1)
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 dv.resize (2);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
418 dv(0) = 1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
419 dv(1) = hdims[0];
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
420 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
421 else
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
422 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
423 dv.resize (rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
424 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
425 dv(j) = hdims[i];
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
426 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
427
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
428 T m (dv);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
429 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
430 H5P_DEFAULT, m.fortran_vec ()) >= 0)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
431 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
432 retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
433 this->matrix = m;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
436 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
437 H5Dclose (data_hid);
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 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
440 }
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 #endif
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 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
445 void
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
446 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
447 bool pr_as_read_syntax) const
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
448 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
449 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
450 this->current_print_indent_level ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
451 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
452
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
453 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
454 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
455 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
456 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
457 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
458
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
459 T tmp = this->scalar;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
460
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
461 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
462
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
463 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
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 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
466 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
467 = 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
468
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 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
470 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
471 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
472 // FIXME -- is there something better we could do?
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
473
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
474 ival = 0;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
475
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
476 ::warning ("range error for conversion to character value");
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
477 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
478 else
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
479 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
480
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
481 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
482 }
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 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
485 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
486 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
487 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
488 os << this->scalar << "\n";
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
489 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
490 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
491
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
492 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
493 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
494 octave_base_int_scalar<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
495 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
496 is >> this->scalar;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
497 if (!is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
498 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
499 error ("load: failed to load scalar constant");
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
500 return false;
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 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
503 }
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 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
506 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
507 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
508 {
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
509 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
510 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
511 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
512
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
513 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
514 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
515 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
516 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
517 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
518 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
519 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
520 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
521
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
522 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
523 switch (this->byte_size ())
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
524 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
525 case 8:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
526 swap_bytes<8> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
527 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
528 case 4:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
529 swap_bytes<4> (&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 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
532 swap_bytes<2> (&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 1:
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
535 default:
10315
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 }
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
538 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
539 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
540 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
541
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
542 #if defined (HAVE_HDF5)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
543
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
544 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
545 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
546 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
547 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
548 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
549 bool retval = true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
550 hsize_t dimens[3];
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
551 hid_t space_hid = -1, data_hid = -1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
552
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
553 space_hid = H5Screate_simple (0, dimens, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
554 if (space_hid < 0) return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
555
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
556 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
557 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
558 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
559 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
560 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
561 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
562 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
563 if (data_hid < 0)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
564 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
565 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
566 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
567 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
568
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
569 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
570 H5P_DEFAULT, &(this->scalar)) >= 0;
4903
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 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
573 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
574
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
575 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
576 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
577
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
578 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
579 bool
9881
b3089dba88bf Remove HDF5 cruft for older versions of HDF5
Kacper Kowalik
parents: 9689
diff changeset
580 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
581 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
582 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
583 #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
584 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
585 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
586 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
587 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
588 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
589
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
590 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
591
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
592 if (rank != 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
593 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
594 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
595 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
596 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
597
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
598 T tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
599 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
600 H5P_DEFAULT, &tmp) < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
601 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
602 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
603 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
604 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
605
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
606 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
607
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
608 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
609
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
610 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
611 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
612
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
613 #endif