annotate libinterp/octave-value/ov-base-int.cc @ 20940:48b2ad5ee801

maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity. * libinterp/corefcn/oct-obj.h: Replaced. Contains a #warning issued if used in compilation and includes "ovl.h" instead. Original file renamed to libinterp/octave-value/ovl.h * libinterp/corefcn/oct-obj.cc: Renamed to libinterp/octave-value/ovl.cc. * oct-obj.cc (ovl ()): Added new function to return empty octave_value_list. * libinterp/corefcn/module.mk: Remove oct-obj.cc from build system. * libinterp/octave-value/module.mk: Add ovl.h and ovl.cc to build system. * mk-opts.pl, annotation-dialog.h, Cell.cc, __contourc__.cc, __dsearchn__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, colloc.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defun.cc, det.cc, dirfns.cc, dlmread.cc, eig.cc, error.cc, fft.cc, fft2.cc, fftn.cc, file-io.cc, filter.cc, find.cc, gammainc.cc, gcd.cc, getgrent.cc, getpwent.cc, getrusage.cc, givens.cc, graphics.cc, gripes.cc, help.cc, hess.cc, hex2num.cc, hook-fcn.h, input.cc, input.h, inv.cc, kron.cc, load-save.cc, lookup.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, lsode.cc, lu.cc, luinc.cc, max.cc, mex.cc, oct-hist.cc, oct-lvalue.cc, oct-lvalue.h, oct-map.h, oct-stream.cc, oct.h, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sparse-xpow.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.h, syscalls.cc, sysdep.cc, time.cc, toplev.cc, tril.cc, tsearch.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xpow.cc, __delaunayn__.cc, __glpk__.cc, __voronoi__.cc, audiodevinfo.cc, audioread.cc, chol.cc, convhulln.cc, dmperm.cc, qr.cc, symbfact.cc, mkbuiltins, ov-base-diag.h, ov-base-int.cc, ov-base-mat.cc, ov-base-mat.h, ov-base-scalar.cc, ov-base-sparse.cc, ov-base-sparse.h, ov-base.cc, ov-bool-mat.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.h, ov-cx-mat.cc, ov-dld-fcn.cc, ov-fcn.cc, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-mat.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.h, ov-mex-fcn.cc, ov-perm.h, ov-range.cc, ov-re-mat.cc, ov-scalar.cc, ov-str-mat.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov-usr-fcn.h, ov.cc, octave.cc, op-b-b.cc, op-b-bm.cc, op-b-sbm.cc, op-bm-b.cc, op-bm-bm.cc, op-bm-sbm.cc, op-cdm-cdm.cc, op-cell.cc, op-chm.cc, op-class.cc, op-cm-cm.cc, op-cm-cs.cc, op-cm-m.cc, op-cm-s.cc, op-cm-scm.cc, op-cm-sm.cc, op-cs-cm.cc, op-cs-cs.cc, op-cs-m.cc, op-cs-s.cc, op-cs-scm.cc, op-cs-sm.cc, op-dm-dm.cc, op-dm-scm.cc, op-dm-sm.cc, op-double-conv.cc, op-fcdm-fcdm.cc, op-fcdm-fdm.cc, op-fcm-fcm.cc, op-fcm-fcs.cc, op-fcm-fm.cc, op-fcm-fs.cc, op-fcn.cc, op-fcs-fcm.cc, op-fcs-fcs.cc, op-fcs-fm.cc, op-fcs-fs.cc, op-fdm-fdm.cc, op-float-conv.cc, op-fm-fcm.cc, op-fm-fcs.cc, op-fm-fm.cc, op-fm-fs.cc, op-fs-fcm.cc, op-fs-fcs.cc, op-fs-fm.cc, op-fs-fs.cc, op-i16-i16.cc, op-i32-i32.cc, op-i64-i64.cc, op-i8-i8.cc, op-int-concat.cc, op-int-conv.cc, op-m-cm.cc, op-m-cs.cc, op-m-m.cc, op-m-s.cc, op-m-scm.cc, op-m-sm.cc, op-pm-pm.cc, op-pm-scm.cc, op-pm-sm.cc, op-range.cc, op-s-cm.cc, op-s-cs.cc, op-s-m.cc, op-s-s.cc, op-s-scm.cc, op-s-sm.cc, op-sbm-b.cc, op-sbm-bm.cc, op-sbm-sbm.cc, op-scm-cm.cc, op-scm-cs.cc, op-scm-m.cc, op-scm-s.cc, op-scm-scm.cc, op-scm-sm.cc, op-sm-cm.cc, op-sm-cs.cc, op-sm-m.cc, op-sm-s.cc, op-sm-scm.cc, op-sm-sm.cc, op-str-m.cc, op-str-s.cc, op-str-str.cc, op-struct.cc, op-ui16-ui16.cc, op-ui32-ui32.cc, op-ui64-ui64.cc, op-ui8-ui8.cc, parse.h, pt-arg-list.cc, pt-assign.cc, pt-binop.cc, pt-cbinop.cc, pt-cell.cc, pt-colon.cc, pt-const.cc, pt-eval.h, pt-fcn-handle.cc, pt-funcall.h, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-mat.cc, pt-select.cc, pt-unop.cc, token.cc, Array-sym.cc: replace '#include "oct-obj.h"' with '#include "ovl.h"'.
author Rik <rik@octave.org>
date Fri, 18 Dec 2015 16:04:56 -0800
parents 384ff5aa9437
children 072559bd31f2
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
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 18678
diff changeset
3 Copyright (C) 2004-2015 John W. Eaton
4903
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"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20893
diff changeset
39 #include "ovl.h"
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
40 #include "oct-lvalue.h"
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
41 #include "oct-hdf5.h"
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
42 #include "oct-stream.h"
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
43 #include "ops.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
44 #include "ov-base.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
45 #include "ov-base-mat.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
46 #include "ov-base-mat.cc"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
47 #include "ov-base-scalar.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
48 #include "ov-base-scalar.cc"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
49 #include "ov-base-int.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
50 #include "ov-int-traits.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
51 #include "pr-output.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
52 #include "variables.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
53
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
54 #include "byte-swap.h"
20447
c6224b4e7774 maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents: 20228
diff changeset
55 #include "ls-oct-text.h"
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
56 #include "ls-utils.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
57 #include "ls-hdf5.h"
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
58
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
59 // We have all the machinery below (octave_base_int_helper and
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
60 // octave_base_int_helper_traits) to avoid a few warnings from GCC
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
61 // about comparisons always false due to limited range of data types.
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
62 // Ugh. The cure may be worse than the disease.
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
63
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
64 template <class T, bool is_signed = true, bool can_be_too_big = true>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
65 struct octave_base_int_helper
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
66 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
67 static bool
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
68 char_value_out_of_range (T val)
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
69 {
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
70 return val < 0 || val > std::numeric_limits<unsigned char>::max ();
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
71 }
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
72 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
73
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
74 template <class T>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
75 struct octave_base_int_helper<T, false, false>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
76 {
9149
7120fbbecf97 ov-base-int.cc: correct result for template specialization
John W. Eaton <jwe@octave.org>
parents: 8920
diff changeset
77 static bool char_value_out_of_range (T) { return false; }
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
78 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
79
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
80 template <class T>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
81 struct octave_base_int_helper<T, false, true>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
82 {
15215
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
83 static bool char_value_out_of_range (T val)
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
84 {
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
85 return val > std::numeric_limits<unsigned char>::max ();
9020dddc925a use std::numeric_limits for integer max and min values
John W. Eaton <jwe@octave.org>
parents: 15195
diff changeset
86 }
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
87 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
88
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
89 template <class T>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
90 struct octave_base_int_helper<T, true, false>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
91 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
92 static bool char_value_out_of_range (T val) { return val < 0; }
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
93 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
94
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
95 // For all types other than char, signed char, and unsigned char, we
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
96 // assume that the upper limit for the range of allowable values is
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
97 // larger than the range for unsigned char. If that's not true, we
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
98 // are still OK, but will see the warnings again for any other types
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
99 // that do not meet this assumption.
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
100
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
101 template <class T>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
102 struct octave_base_int_helper_traits
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
103 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
104 static const bool can_be_larger_than_uchar_max = true;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
105 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
106
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
107 template <>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
108 struct octave_base_int_helper_traits<char>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
109 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
110 static const bool can_be_larger_than_uchar_max = false;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
111 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
112
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
113 template <>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
114 struct octave_base_int_helper_traits<signed char>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
115 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
116 static const bool can_be_larger_than_uchar_max = false;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
117 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
118
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
119 template <>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
120 struct octave_base_int_helper_traits<unsigned char>
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
121 {
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
122 static const bool can_be_larger_than_uchar_max = false;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
123 };
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
124
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
125
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
126 template <class T>
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
127 octave_base_value *
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
128 octave_base_int_matrix<T>::try_narrowing_conversion (void)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
129 {
5759
ce79d238f142 [project @ 2006-04-13 13:04:32 by jwe]
jwe
parents: 5307
diff changeset
130 octave_base_value *retval = 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
131
20228
00cf2847355d Deprecate Array::nelem() and Range::nelem() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents: 20218
diff changeset
132 if (this->matrix.numel () == 1)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
133 retval = new typename octave_value_int_traits<T>::scalar_type
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
134 (this->matrix (0));
4903
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 return retval;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
139 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
140 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
141 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
142 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
143 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
144 dim_vector dv = this->dims ();
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
145 octave_idx_type nel = dv.numel ();
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 charNDArray chm (dv);
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 bool warned = false;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
150
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
151 for (octave_idx_type i = 0; i < nel; i++)
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
152 {
10142
829e69ec3110 make OCTAVE_QUIT a function
Jaroslav Hajek <highegg@gmail.com>
parents: 9892
diff changeset
153 octave_quit ();
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 typename T::element_type tmp = this->matrix(i);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
156
8918
f5408862892f Consistently use element_type in the array classes.
Jason Riedy <jason@acm.org>
parents: 8377
diff changeset
157 typedef typename T::element_type::val_type val_type;
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
158
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
159 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
160
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
161 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
162 static const bool can_be_larger_than_uchar_max
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
163 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max;
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
164
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
165 if (octave_base_int_helper<val_type, is_signed,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
166 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
167 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
168 // FIXME: is there something better we could do?
5992
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 ival = 0;
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
171
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
172 if (! warned)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
173 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
174 ::warning ("range error for conversion to character value");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
175 warned = true;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
176 }
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
177 }
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
178 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
179 chm (i) = static_cast<char> (ival);
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
180 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
181
9689
34d6f005db4b eliminate is_string argument from octave_value character array constructors
John W. Eaton <jwe@octave.org>
parents: 9149
diff changeset
182 retval = octave_value (chm, type);
5992
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 return retval;
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
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
187 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
188 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
189 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
190 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
191 dim_vector d = this->dims ();
4903
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 os << "# ndims: " << d.length () << "\n";
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
194
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
195 for (int i = 0; i < d.length (); i++)
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19875
diff changeset
196 os << " " << d(i);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
197
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
198 os << "\n" << this->matrix;
4903
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 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
203 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
204 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
205 octave_base_int_matrix<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
206 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
207 int mdims = 0;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
208 bool success = 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 (extract_keyword (is, "ndims", mdims, true))
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
211 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
212 if (mdims >= 0)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
213 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
214 dim_vector dv;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
215 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
216
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
217 for (int i = 0; i < mdims; i++)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
218 is >> dv(i);
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 T tmp(dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
221
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
222 is >> tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
223
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
224 if (!is)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
225 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
226 error ("load: failed to load matrix constant");
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
227 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
228 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
229
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
230 this->matrix = tmp;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
231 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
232 else
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
233 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
234 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
235 success = false;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
236 }
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
237 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
238 else
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
239 error ("load: failed to extract number of dimensions");
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 return success;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
244 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
245 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
246 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
247 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
248 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
249 if (d.length () < 1)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
250 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
251
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
252 // 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
253 int32_t tmp = - d.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
254 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
255 for (int i=0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
256 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
257 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
258 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
259 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
260
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
261 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
262 this->byte_size ());
4903
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 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
267 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
268 bool
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
269 octave_base_int_matrix<T>::load_binary (std::istream& is, bool swap,
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18100
diff changeset
270 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
271 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
272 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
273 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
274 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
275 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
276 swap_bytes<4> (&mdims);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
277 if (mdims >= 0)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
278 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
279
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
280 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
281 int32_t di;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
282 dim_vector dv;
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
283 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
284
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
285 for (int i = 0; i < mdims; i++)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
286 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
287 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
288 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
289 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
290 swap_bytes<4> (&di);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
291 dv(i) = di;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
292 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
293
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
294 // 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
295 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
296 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
297
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
298 if (mdims == 1)
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
299 {
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
300 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
301 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
302 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
303 dv(0) = 1;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
304 }
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
305
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
306 T m (dv);
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
307
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
308 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
309 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
310
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
311 if (swap)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
312 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
313 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
314 int bytes = nel / m.byte_size ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
315 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 switch (bytes)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
319 swap_bytes<8> (&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 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
322 swap_bytes<4> (&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 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
325 swap_bytes<2> (&m(i));
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 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
328 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
329 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
330 }
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
331 }
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
332
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
333 this->matrix = m;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
334 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
337 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
338 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
339 octave_base_int_matrix<T>::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
340 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
341 bool retval = false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
342
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
343 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
344
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
345 hid_t save_type_hid = HDF5_SAVE_TYPE;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
346 dim_vector dv = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
347 int empty = save_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
348 if (empty)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
349 return (empty > 0);
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 int rank = dv.length ();
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
352 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
353 space_hid = data_hid = -1;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
354 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
355
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
356 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
357 for (int i = 0; i < rank; i++)
20218
b2100e1659ac maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents: 19875
diff changeset
358 hdims[i] = dv(rank-i-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
359
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
360 space_hid = H5Screate_simple (rank, hdims, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
361
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
362 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
363 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
364 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
365 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
366 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
367 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
368 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
369 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
370 if (data_hid < 0)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
371 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
372 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
373 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
374 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
375
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
376 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
377 H5P_DEFAULT, this->matrix.data ()) >= 0;
4903
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 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
380 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
381
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
382 #else
19875
2f2220bfd379 ov-base-int.cc, ov-float.cc: Fix build without HDF5
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19863
diff changeset
383 this->gripe_save ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
384 #endif
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
385
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
386 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
387 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
388
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
389 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
390 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
391 octave_base_int_matrix<T>::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
392 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
393 bool retval = false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
394
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
395 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
396
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
397 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
398 dim_vector dv;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
399 int empty = load_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
400 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
401 this->matrix.resize (dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
402 if (empty)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
403 return (empty > 0);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
404
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
405 #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
406 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
407 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
408 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
409 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
410 hid_t space_id = H5Dget_space (data_hid);
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 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
413
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
414 if (rank < 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
415 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
416 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
417 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
418 return false;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
421 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
422 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
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 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
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 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
427 if (rank == 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
428 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
429 dv.resize (2);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
430 dv(0) = 1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
431 dv(1) = hdims[0];
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
432 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
433 else
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 dv.resize (rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
436 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
437 dv(j) = hdims[i];
4903
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
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
440 T m (dv);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
441 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
442 H5P_DEFAULT, m.fortran_vec ()) >= 0)
4903
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 retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
445 this->matrix = m;
4903
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
448 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
449 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
450
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
451 #else
19875
2f2220bfd379 ov-base-int.cc, ov-float.cc: Fix build without HDF5
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19863
diff changeset
452 this->gripe_load ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
453 #endif
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
454
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
455 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
456 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
457
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
458 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
459 void
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
460 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
461 bool pr_as_read_syntax) const
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
462 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
463 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
464 this->current_print_indent_level ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
465 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
466
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
467 template <class T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
468 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
469 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
470 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
471 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
472
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
473 T tmp = this->scalar;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
474
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
475 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
476
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
477 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
478
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
479 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
480 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
481 = 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
482
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
483 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
484 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
485 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
486 // FIXME: is there something better we could do?
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
487
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
488 ival = 0;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
489
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
490 ::warning ("range error for conversion to character value");
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
491 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
492 else
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
493 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
494
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
495 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
496 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
497
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
498 template <class T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
499 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
500 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
501 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
502 os << this->scalar << "\n";
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
503 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
506 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
507 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
508 octave_base_int_scalar<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
509 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
510 is >> this->scalar;
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20447
diff changeset
511 if (! is)
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20447
diff changeset
512 error ("load: failed to load scalar constant");
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20447
diff changeset
513
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
514 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
517 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
518 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
519 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
520 {
14846
460a3c6d8bf1 maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
521 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
522 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
523 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
524
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
525 template <class T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
526 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
527 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
528 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
529 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
530 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
531 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
532 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
533
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
534 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
535 switch (this->byte_size ())
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
536 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
537 case 8:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
538 swap_bytes<8> (&tmp);
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 case 4:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
541 swap_bytes<4> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
542 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
543 case 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
544 swap_bytes<2> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
545 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
546 case 1:
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
547 default:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
548 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
549 }
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
550 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
551 return true;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
554 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
555 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
556 octave_base_int_scalar<T>::save_hdf5 (octave_hdf5_id loc_id, const char *name, bool)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
557 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
558 bool retval = false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
559
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
560 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
561
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
562 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
563 hsize_t dimens[3];
18100
6a71e5030df5 Follow coding convention of defining and initializing only 1 variable per line in liboctinterp.
Rik <rik@octave.org>
parents: 17787
diff changeset
564 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
565 space_hid = data_hid = -1;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
566
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
567 space_hid = H5Screate_simple (0, dimens, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
568 if (space_hid < 0) return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
569
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
570 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
571 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
572 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
573 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
574 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
575 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
576 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
577 if (data_hid < 0)
4903
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 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
580 return false;
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
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
583 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
584 H5P_DEFAULT, &(this->scalar)) >= 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
585
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
586 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
587 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
588
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
589 #else
19875
2f2220bfd379 ov-base-int.cc, ov-float.cc: Fix build without HDF5
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19863
diff changeset
590 this->gripe_save ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
591 #endif
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
592
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
593 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
594 }
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 template <class T>
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
597 bool
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
598 octave_base_int_scalar<T>::load_hdf5 (octave_hdf5_id loc_id, const char *name)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
599 {
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
600 #if defined (HAVE_HDF5)
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
601
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
602 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
603 #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
604 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
605 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
606 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
607 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
608 hid_t space_id = H5Dget_space (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 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
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 if (rank != 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
613 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
614 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
615 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
616 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
617
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
618 T tmp;
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
619 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
620 H5P_DEFAULT, &tmp) < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
621 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
622 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
623 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
624 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
625
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
626 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
627
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
628 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
629
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
630 return true;
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
631
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
632 #else
19875
2f2220bfd379 ov-base-int.cc, ov-float.cc: Fix build without HDF5
Andreas Weber <andy.weber.aw@gmail.com>
parents: 19863
diff changeset
633 this->gripe_load ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
634 return false;
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
635 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
636 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
637