annotate libinterp/octave-value/ov-legacy-range.cc @ 30857:95725e6ad9c1 stable

restore part of the old octave_range class as octave_legacy_range This change allows old range objects to be loaded from data files and then converted to the new range type or other numeric types. * libinterp/octave-value/ov-legacy-range.h, libinterp/octave-value/ov-legacy-range.cc: New files restored from old versions of ov-range.h and ov-range.cc. Only provide enough support to load "range" objects from data files. * libinterp/octave-value/module.mk: Update. * ov.h, ov.cc: Update tests. (octave_value::is_legacy_object): New function. (octave_value::load_ascii, octave_value::load_binary, octave_value::load_hdf5): If loaded value is a legacy object, call maybe_mutate to allow conversion to a currently supported data type. (install_types): Register octave_legacy_range objects. (octave_value::make_range_rep_deprecated): Convert to Don't allow (const Range& r, bool force_range) (octave_value::make_range_rep_deprecated): Use Range constructor. Allow mutation to handle conversion to new range object or other numeric types. * ov-base.h (octave_base_value::is_legacy_object): New function * ov-range.cc: Rename ov_range<double> data type from "range" to "double_range". * Range.h (Range::Range): Always provide deprecated Range constructors. * ov-typeinfo.cc: Update test. * mk-conv-tst.sh: Update tests.
author John W. Eaton <jwe@octave.org>
date Mon, 21 Mar 2022 23:58:35 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30857
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // This file is part of Octave.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // (at your option) any later version.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // GNU General Public License for more details.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 //
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if defined (HAVE_CONFIG_H)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 # include "config.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30 #include <istream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <ostream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32 #include <sstream>
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 #include "lo-ieee.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35 #include "lo-utils.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 #include "variables.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 #include "error.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 #include "ovl.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 #include "oct-hdf5.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
41 #include "ov-legacy-range.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
42 #include "ov-range.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 #include "ov-re-mat.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
44 #include "ov-scalar.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
45 #include "pr-output.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
46
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
47 #include "byte-swap.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "ls-ascii-helper.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "ls-hdf5.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50 #include "ls-utils.h"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
53 # pragma GCC diagnostic push
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
54 # pragma GCC diagnostic ignored "-Wdeprecated-declarations"
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_legacy_range, "range", "double");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 octave_legacy_range::octave_legacy_range (void)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
60 : octave_base_value (), range () { }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62 octave_legacy_range::octave_legacy_range (const Range& r)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 : octave_base_value (), range (r)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 if (range.numel () < 0 && range.numel () != -2)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 error ("invalid range");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 static octave_base_value *
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
70 default_numeric_conversion_function (const octave_base_value& a)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72 const octave_legacy_range& v = dynamic_cast<const octave_legacy_range&> (a);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 return new octave_matrix (v.matrix_value ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 octave_base_value::type_conv_info
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78 octave_legacy_range::numeric_conversion_function (void) const
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80 return octave_base_value::type_conv_info (default_numeric_conversion_function,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
81 octave_matrix::static_type_id ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
83
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
84 octave_base_value *
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
85 octave_legacy_range::try_narrowing_conversion (void)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
86 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 octave_base_value *retval = nullptr;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 switch (range.numel ())
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
91 case 1:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92 retval = new octave_scalar (range.base ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 case 0:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 retval = new octave_matrix (Matrix (1, 0));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
98
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
99 case -2:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
100 retval = new octave_matrix (range.matrix_value ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
101 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
102
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 default:
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 if (range.increment () == 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106 retval = new octave_matrix (range.matrix_value ());
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
107 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108 retval = new octave_range
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
109 (octave::range<double> (range.base (), range.increment (),
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 range.limit (), range.numel ()));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115 return retval;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
116 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 // Skip white space and comments on stream IS.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
120 static void
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
121 skip_comments (std::istream& is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123 char c = '\0';
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
124 while (is.get (c))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
125 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 if (c == ' ' || c == '\t' || c == '\n')
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 ; // Skip whitespace on way to beginning of next line.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 break;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
132 octave::skip_until_newline (is, false);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
136 octave_legacy_range::load_ascii (std::istream& is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 // # base, limit, range comment added by save ().
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
139 skip_comments (is);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
141 double base, limit, inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
142 is >> base >> limit >> inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
144 if (! is)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
145 error ("load: failed to load range constant");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
146
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
147 if (inc != 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
148 range = Range (base, limit, inc);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
149 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
150 range = Range (base, inc, static_cast<octave_idx_type> (limit));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
151
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
152 return true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
153 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
154
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
155 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
156 octave_legacy_range::load_binary (std::istream& is, bool swap,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
157 octave::mach_info::float_format /* fmt */)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
158 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
159 char tmp;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
160 if (! is.read (reinterpret_cast<char *> (&tmp), 1))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
161 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
162 double bas, lim, inc;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
163 if (! is.read (reinterpret_cast<char *> (&bas), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
164 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
165 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
166 swap_bytes<8> (&bas);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
167 if (! is.read (reinterpret_cast<char *> (&lim), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
168 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
169 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
170 swap_bytes<8> (&lim);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
171 if (! is.read (reinterpret_cast<char *> (&inc), 8))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
172 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
173 if (swap)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
174 swap_bytes<8> (&inc);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
175 if (inc != 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
176 range = Range (bas, lim, inc);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
177 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
178 range = Range (bas, inc, static_cast<octave_idx_type> (lim));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
179
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
180 return true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
181 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
182
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
183 #if defined (HAVE_HDF5)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
184
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
185 // The following subroutines creates an HDF5 representation of the way
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
186 // we will store Octave range types (triplets of floating-point numbers).
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
187 // NUM_TYPE is the HDF5 numeric type to use for storage (e.g.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
188 // H5T_NATIVE_DOUBLE to save as 'double'). Note that any necessary
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
189 // conversions are handled automatically by HDF5.
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
190
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
191 static hid_t
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
192 hdf5_make_range_type (hid_t num_type)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
193 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
194 hid_t type_id = H5Tcreate (H5T_COMPOUND, sizeof (double) * 3);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
195
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
196 H5Tinsert (type_id, "base", 0 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
197 H5Tinsert (type_id, "limit", 1 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
198 H5Tinsert (type_id, "increment", 2 * sizeof (double), num_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
199
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
200 return type_id;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
201 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
202
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
203 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
204
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
205 bool
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
206 octave_legacy_range::load_hdf5 (octave_hdf5_id loc_id, const char *name)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
207 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
208 bool retval = false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
209
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
210 #if defined (HAVE_HDF5)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
211
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
212 #if defined (HAVE_HDF5_18)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
213 hid_t data_hid = H5Dopen (loc_id, name, octave_H5P_DEFAULT);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
214 #else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
215 hid_t data_hid = H5Dopen (loc_id, name);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
216 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
217 hid_t type_hid = H5Dget_type (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
218
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
219 hid_t range_type = hdf5_make_range_type (H5T_NATIVE_DOUBLE);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
220
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
221 if (! hdf5_types_compatible (type_hid, range_type))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
222 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
223 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
224 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
225 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
226 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
227
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
228 hid_t space_hid = H5Dget_space (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
229 hsize_t rank = H5Sget_simple_extent_ndims (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
230
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
231 if (rank != 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
232 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
233 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
234 H5Sclose (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
235 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
236 return false;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
237 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
238
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
239 double rangevals[3];
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
240 if (H5Dread (data_hid, range_type, octave_H5S_ALL, octave_H5S_ALL,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
241 octave_H5P_DEFAULT, rangevals)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
242 >= 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
243 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
244 retval = true;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
245 octave_idx_type nel;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
246 if (hdf5_get_scalar_attr (data_hid, H5T_NATIVE_IDX,
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
247 "OCTAVE_RANGE_NELEM", &nel))
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
248 range = Range (rangevals[0], rangevals[2], nel);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
249 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
250 {
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
251 if (rangevals[2] != 0)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
252 range = Range (rangevals[0], rangevals[1], rangevals[2]);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
253 else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
254 range = Range (rangevals[0], rangevals[2],
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
255 static_cast<octave_idx_type> (rangevals[1]));
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
256 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
257 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
258
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
259 H5Tclose (range_type);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
260 H5Sclose (space_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
261 H5Dclose (data_hid);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
262
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
263 #else
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
264 octave_unused_parameter (loc_id);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
265 octave_unused_parameter (name);
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
266
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
267 warn_load ("hdf5");
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
268 #endif
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
269
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
270 return retval;
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
271 }
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
272
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
273 #if defined (HAVE_PRAGMA_GCC_DIAGNOSTIC)
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
274 # pragma GCC diagnostic pop
95725e6ad9c1 restore part of the old octave_range class as octave_legacy_range
John W. Eaton <jwe@octave.org>
parents:
diff changeset
275 #endif