annotate libinterp/octave-value/ov-base-int.cc @ 21200:fcac5dbbf9ed

maint: Indent #ifdef blocks in libinterp. * builtins.h, Cell.cc, __contourc__.cc, __dispatch__.cc, __dsearchn__.cc, __ichol__.cc, __ilu__.cc, __lin_interpn__.cc, __pchip_deriv__.cc, __qp__.cc, balance.cc, besselj.cc, betainc.cc, bitfcns.cc, bsxfun.cc, c-file-ptr-stream.cc, c-file-ptr-stream.h, cellfun.cc, colloc.cc, comment-list.cc, conv2.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, debug.cc, defaults.cc, defaults.in.h, defun-dld.h, defun.cc, defun.h, det.cc, dirfns.cc, display.cc, dlmread.cc, dot.cc, dynamic-ld.cc, eig.cc, ellipj.cc, error.cc, errwarn.cc, event-queue.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, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h, gripes.cc, hash.cc, help.cc, hess.cc, hex2num.cc, input.cc, inv.cc, jit-ir.cc, jit-typeinfo.cc, jit-util.cc, jit-util.h, kron.cc, load-path.cc, load-save.cc, lookup.cc, ls-ascii-helper.cc, ls-hdf5.cc, ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.cc, ls-oct-text.h, ls-utils.cc, ls-utils.h, lsode.cc, lu.cc, luinc.cc, mappers.cc, matrix_type.cc, max.cc, mex.h, mexproto.h, mgorth.cc, nproc.cc, oct-errno.in.cc, oct-fstrm.cc, oct-hdf5-types.cc, oct-hdf5.h, oct-hist.cc, oct-iostrm.cc, oct-lvalue.cc, oct-map.cc, oct-prcstrm.cc, oct-procbuf.cc, oct-stream.cc, oct-strstrm.cc, octave-link.cc, ordschur.cc, pager.cc, pinv.cc, pr-output.cc, procstream.cc, profiler.cc, psi.cc, pt-jit.cc, quad.cc, quadcc.cc, qz.cc, rand.cc, rcond.cc, regexp.cc, schur.cc, sighandlers.cc, sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, spparms.cc, sqrtm.cc, str2double.cc, strfind.cc, strfns.cc, sub2ind.cc, svd.cc, sylvester.cc, symtab.cc, syscalls.cc, sysdep.cc, sysdep.h, time.cc, toplev.cc, tril.cc, tsearch.cc, txt-eng-ft.cc, txt-eng.cc, typecast.cc, urlwrite.cc, utils.cc, variables.cc, xdiv.cc, xnorm.cc, xpow.cc, zfstream.cc, __delaunayn__.cc, __eigs__.cc, __fltk_uigetfile__.cc, __glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __magick_read__.cc, __osmesa_print__.cc, __voronoi__.cc, amd.cc, audiodevinfo.cc, audioread.cc, ccolamd.cc, chol.cc, colamd.cc, convhulln.cc, dmperm.cc, fftw.cc, oct-qhull.h, qr.cc, symbfact.cc, symrcm.cc, oct-conf.in.cc, ov-base-diag.cc, ov-base-int.cc, ov-base-mat.cc, ov-base-scalar.cc, ov-base-sparse.cc, ov-base.cc, ov-bool-mat.cc, ov-bool-sparse.cc, ov-bool.cc, ov-builtin.cc, ov-cell.cc, ov-ch-mat.cc, ov-class.cc, ov-classdef.cc, ov-colon.cc, ov-complex.cc, ov-cs-list.cc, ov-cx-diag.cc, ov-cx-mat.cc, ov-cx-sparse.cc, ov-dld-fcn.cc, ov-fcn-handle.cc, ov-fcn-inline.cc, ov-fcn.cc, ov-float.cc, ov-flt-complex.cc, ov-flt-cx-diag.cc, ov-flt-cx-mat.cc, ov-flt-re-diag.cc, ov-flt-re-mat.cc, ov-int16.cc, ov-int32.cc, ov-int64.cc, ov-int8.cc, ov-java.cc, ov-lazy-idx.cc, ov-mex-fcn.cc, ov-null-mat.cc, ov-oncleanup.cc, ov-perm.cc, ov-range.cc, ov-re-diag.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc, ov-struct.cc, ov-typeinfo.cc, ov-uint16.cc, ov-uint32.cc, ov-uint64.cc, ov-uint8.cc, ov-usr-fcn.cc, ov.cc, ovl.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-dm-template.cc, op-dms-template.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-pm-template.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, pt-arg-list.cc, pt-array-list.cc, pt-assign.cc, pt-binop.cc, pt-bp.cc, pt-cbinop.cc, pt-cell.cc, pt-check.cc, pt-classdef.cc, pt-cmd.cc, pt-colon.cc, pt-colon.h, pt-const.cc, pt-decl.cc, pt-eval.cc, pt-except.cc, pt-exp.cc, pt-fcn-handle.cc, pt-funcall.cc, pt-id.cc, pt-idx.cc, pt-jump.cc, pt-loop.cc, pt-mat.cc, pt-misc.cc, pt-pr-code.cc, pt-select.cc, pt-stmt.cc, pt-unop.cc, pt.cc, token.cc, Array-jit.cc, Array-os.cc, Array-sym.cc, Array-tc.cc, version.cc: Indent #ifdef blocks in libinterp.
author Rik <rik@octave.org>
date Fri, 05 Feb 2016 16:29:08 -0800
parents 538b57866b90
children 2cf8bc5c7017
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
21200
fcac5dbbf9ed maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents: 21139
diff changeset
24 # include <config.h>
4903
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"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 21022
diff changeset
38 #include "errwarn.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20893
diff changeset
39 #include "ovl.h"
4903
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
64 template <typename T, bool is_signed = true, bool can_be_too_big = true>
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
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
74 template <typename T>
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
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
80 template <typename T>
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
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
89 template <typename T>
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
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
101 template <typename T>
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
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
126 template <typename 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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
139 template <typename 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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
187 template <typename 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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
203 template <typename 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
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
209 if (! extract_keyword (is, "ndims", mdims, true))
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
210 error ("load: failed to extract number of dimensions");
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
211
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
212 if (mdims < 0)
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
213 error ("load: failed to extract number of rows and columns");
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
214
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
215 dim_vector dv;
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
216 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
217
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
218 for (int i = 0; i < mdims; i++)
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
219 is >> dv(i);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
220
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
221 T tmp(dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
222
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
223 is >> tmp;
20962
3aa293be0e8d maint: Invert simple conditionals in if/else/error paradigm.
Rik <rik@octave.org>
parents: 20955
diff changeset
224
20978
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
225 if (! is)
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
226 error ("load: failed to load matrix constant");
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
227
a5b500efca9f maint: invert if/else/error instances.
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
228 this->matrix = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
229
21124
95f8c8cdbffe maint: Eliminate 'bool success' variable where possible.
Rik <rik@octave.org>
parents: 21102
diff changeset
230 return true;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
231 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
232
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
233 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
234 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
235 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
236 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
237 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
238 if (d.length () < 1)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
239 return false;
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 // 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
242 int32_t tmp = - d.length ();
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
243 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
244 for (int i=0; i < d.length (); i++)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
245 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
246 tmp = d(i);
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
247 os.write (reinterpret_cast<char *> (&tmp), 4);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
248 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
249
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
250 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
251 this->byte_size ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
252
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
253 return true;
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
256 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
257 bool
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
258 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
259 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
260 {
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
261 int32_t mdims;
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
262 if (! is.read (reinterpret_cast<char *> (&mdims), 4))
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
263 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
264 if (swap)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
265 swap_bytes<4> (&mdims);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
266 if (mdims >= 0)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
267 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
268
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
269 mdims = - mdims;
5828
22e23bee74c8 [project @ 2006-05-23 06:05:14 by jwe]
jwe
parents: 5760
diff changeset
270 int32_t di;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
271 dim_vector dv;
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
272 dv.resize (mdims);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
273
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
274 for (int i = 0; i < mdims; i++)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
275 {
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
276 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
277 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
278 if (swap)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
279 swap_bytes<4> (&di);
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
280 dv(i) = di;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
281 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
282
5157
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
283 // 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
284 // Octave should never write files like this, other software
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
285 // might.
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
286
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
287 if (mdims == 1)
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
288 {
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
289 mdims = 2;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
290 dv.resize (mdims);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
291 dv(1) = dv(0);
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
292 dv(0) = 1;
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
293 }
8ca032643f55 [project @ 2005-02-23 00:18:58 by jwe]
jwe
parents: 5105
diff changeset
294
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
295 T m (dv);
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
296
5760
8d7162924bd3 [project @ 2006-04-14 04:01:37 by jwe]
jwe
parents: 5759
diff changeset
297 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
298 return false;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
299
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
300 if (swap)
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
301 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
302 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
303 int bytes = nel / m.byte_size ();
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
304 for (int i = 0; i < nel; i++)
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
305 switch (bytes)
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
306 {
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
307 case 8:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
308 swap_bytes<8> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
309 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
310 case 4:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
311 swap_bytes<4> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
312 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
313 case 2:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
314 swap_bytes<2> (&m(i));
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
315 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
316 case 1:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
317 default:
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
318 break;
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
319 }
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
320 }
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
321
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
322 this->matrix = m;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
323 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
324 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
325
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
326 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
327 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
328 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
329 {
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
330 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
331
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
332 #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
333
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
334 hid_t save_type_hid = HDF5_SAVE_TYPE;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
335 dim_vector dv = this->dims ();
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
336 int empty = save_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
337 if (empty)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
338 return (empty > 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
339
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
340 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
341 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
342 space_hid = data_hid = -1;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
343 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
344
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
345 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
346 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
347 hdims[i] = dv(rank-i-1);
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
348
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
349 space_hid = H5Screate_simple (rank, hdims, 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 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
352 #if HAVE_HDF5_18
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
353 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
354 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
355 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
356 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
357 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
358 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
359 if (data_hid < 0)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
360 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
361 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
362 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
363 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
364
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
365 retval = H5Dwrite (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL,
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
366 octave_H5P_DEFAULT, this->matrix.data ()) >= 0;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
367
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
368 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
369 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
370
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
371 #else
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
372 this->warn_save ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
373 #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
374
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
375 return retval;
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
378 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
379 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
380 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
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 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
383
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 #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
385
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
386 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
387 dim_vector dv;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
388 int empty = load_hdf5_empty (loc_id, name, dv);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
389 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
390 this->matrix.resize (dv);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
391 if (empty)
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
392 return (empty > 0);
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
393
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
394 #if HAVE_HDF5_18
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
395 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
396 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
397 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
398 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
399 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
400
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
401 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
402
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
403 if (rank < 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
404 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
405 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
406 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
407 return false;
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
410 OCTAVE_LOCAL_BUFFER (hsize_t, hdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
411 OCTAVE_LOCAL_BUFFER (hsize_t, maxdims, rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
412
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
413 H5Sget_simple_extent_dims (space_id, hdims, maxdims);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
414
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
415 // Octave uses column-major, while HDF5 uses row-major ordering
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
416 if (rank == 1)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
417 {
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
418 dv.resize (2);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
419 dv(0) = 1;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
420 dv(1) = hdims[0];
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
421 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
422 else
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 dv.resize (rank);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
425 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
426 dv(j) = hdims[i];
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
427 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
428
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
429 T m (dv);
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
430 if (H5Dread (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL,
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
431 octave_H5P_DEFAULT, m.fortran_vec ()) >= 0)
4903
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 retval = true;
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
434 this->matrix = m;
4903
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
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
437 H5Sclose (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
438 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
439
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
440 #else
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
441 this->warn_load ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
442 #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
443
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
444 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
445 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
446
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
447 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
448 void
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
449 octave_base_int_matrix<T>::print_raw (std::ostream& os,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
450 bool pr_as_read_syntax) const
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
451 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
452 octave_print_internal (os, this->matrix, pr_as_read_syntax,
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
453 this->current_print_indent_level ());
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
454 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
455
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
456 template <typename T>
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
457 octave_value
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
458 octave_base_int_scalar<T>::convert_to_str_internal (bool, bool, char type) const
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
459 {
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
460 octave_value retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
461
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
462 T tmp = this->scalar;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
463
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
464 typedef typename T::val_type val_type;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
465
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
466 val_type ival = tmp.value ();
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
467
7534
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
468 static const bool is_signed = std::numeric_limits<val_type>::is_signed;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
469 static const bool can_be_larger_than_uchar_max
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
470 = octave_base_int_helper_traits<val_type>::can_be_larger_than_uchar_max;
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
471
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
472 if (octave_base_int_helper<val_type, is_signed,
ef755c763b62 avoid more "comparison is always false due to limited range of data type" warnings from GCC
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
473 can_be_larger_than_uchar_max>::char_value_out_of_range (ival))
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
474 {
17787
175b392e91fe Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents: 17744
diff changeset
475 // FIXME: is there something better we could do?
5992
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
476
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
477 ival = 0;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
478
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
479 ::warning ("range error for conversion to character value");
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
480 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
481 else
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
482 retval = octave_value (std::string (1, static_cast<char> (ival)), type);
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
483
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
484 return retval;
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
485 }
4289ed95dde8 [project @ 2006-09-15 20:29:18 by jwe]
jwe
parents: 5958
diff changeset
486
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
487 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
488 bool
6974
9e32bb109980 [project @ 2007-10-08 11:06:47 by jwe]
jwe
parents: 6959
diff changeset
489 octave_base_int_scalar<T>::save_ascii (std::ostream& os)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
490 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
491 os << this->scalar << "\n";
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
492 return true;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
493 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
494
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
495 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
496 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
497 octave_base_int_scalar<T>::load_ascii (std::istream& is)
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
498 {
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
499 is >> this->scalar;
20893
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20447
diff changeset
500 if (! is)
384ff5aa9437 2015 Code Sprint: Eliminate useless return statements after error ().
Rik <rik@octave.org>
parents: 20447
diff changeset
501 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
502
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
506 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
507 bool
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
508 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
509 {
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
510 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
511 return true;
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
514 template <typename T>
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
515 bool
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
516 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
517 oct_mach_info::float_format)
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
518 {
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
519 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
520 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
521 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
522
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
523 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
524 switch (this->byte_size ())
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
525 {
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
526 case 8:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
527 swap_bytes<8> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
528 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
529 case 4:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
530 swap_bytes<4> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
531 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
532 case 2:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
533 swap_bytes<2> (&tmp);
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
534 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
535 case 1:
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
536 default:
10315
57a59eae83cc untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents: 10160
diff changeset
537 break;
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
538 }
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
539 this->scalar = tmp;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
540 return true;
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
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
543 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
544 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
545 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
546 {
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
547 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
548
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
549 #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
550
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
551 hid_t save_type_hid = HDF5_SAVE_TYPE;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
552 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
553 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
554 space_hid = data_hid = -1;
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
555
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
556 space_hid = H5Screate_simple (0, dimens, 0);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
557 if (space_hid < 0) return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
558
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 #if HAVE_HDF5_18
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,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
561 octave_H5P_DEFAULT, octave_H5P_DEFAULT, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
562 #else
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
563 data_hid = H5Dcreate (loc_id, name, save_type_hid, space_hid,
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
564 octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
565 #endif
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
566 if (data_hid < 0)
4903
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 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
569 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
570 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
571
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
572 retval = H5Dwrite (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL,
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
573 octave_H5P_DEFAULT, &(this->scalar)) >= 0;
4903
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 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
576 H5Sclose (space_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
577
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
578 #else
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
579 this->warn_save ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
580 #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
581
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
582 return retval;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
583 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
584
21139
538b57866b90 consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents: 21124
diff changeset
585 template <typename T>
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
586 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
587 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
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 #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
590
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
591 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
592 #if HAVE_HDF5_18
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
593 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
9892
ac69e6f4b33d Add HDF5-1.8 compatibility while maintaining compatibility with HDF5-1.6 versions
Kacper Kowalik <xarthisius.kk@gmail.com>
parents: 9881
diff changeset
594 #else
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
595 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
596 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
597 hid_t space_id = H5Dget_space (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
598
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
599 hsize_t rank = H5Sget_simple_extent_ndims (space_id);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
600
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
601 if (rank != 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
602 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
603 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
604 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
605 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
606
4917
f69e95587ba3 [project @ 2004-07-27 14:03:03 by jwe]
jwe
parents: 4903
diff changeset
607 T tmp;
21022
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
608 if (H5Dread (data_hid, save_type_hid, octave_H5S_ALL, octave_H5S_ALL,
ebc439187d29 avoid old-style cast warnings from HDF5 macros used in C++ sources
John W. Eaton <jwe@octave.org>
parents: 20978
diff changeset
609 octave_H5P_DEFAULT, &tmp) < 0)
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
610 {
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
611 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
612 return false;
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
613 }
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
614
4932
43f4ebd2704c [project @ 2004-08-05 13:26:10 by jwe]
jwe
parents: 4917
diff changeset
615 this->scalar = tmp;
4903
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 H5Dclose (data_hid);
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
618
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
619 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
620
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
621 #else
21102
dfcb9d74b253 Rename local gripe_XXX functions to err_XXX or warn_XXX.
Rik <rik@octave.org>
parents: 21100
diff changeset
622 this->warn_load ("hdf5");
19863
09ed6f7538dd avoid needing to include hdf5 in public header files (bug #44370, #43180)
John W. Eaton <jwe@octave.org> and Mike Miller <mtmiller@ieee.org>
parents: 19697
diff changeset
623 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
624 #endif
4903
bfe64e459ce3 [project @ 2004-06-14 19:20:26 by jwe]
jwe
parents:
diff changeset
625 }
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 4932
diff changeset
626