comparison libinterp/octave-value/ov-legacy-range.h @ 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
comparison
equal deleted inserted replaced
30855:82c1554c4a64 30857:95725e6ad9c1
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-2022 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25
26 #if ! defined (octave_ov_legacy_range_h)
27 #define octave_ov_legacy_range_h 1
28
29 #include "octave-config.h"
30
31 #include <cstdlib>
32
33 #include <iosfwd>
34 #include <string>
35
36 #include "Range.h"
37
38 #include "lo-mappers.h"
39 #include "lo-utils.h"
40 #include "mx-base.h"
41
42 #include "error.h"
43 #include "oct-stream.h"
44 #include "ov-base.h"
45 #include "ov-re-mat.h"
46 #include "ov-typeinfo.h"
47
48 class octave_value_list;
49
50 // Legacy Range values.
51
52 // Provide enough of the old octave_range class to allow Range objects
53 // to be loaded from files. After loading, they are converted to some
54 // other type by a call to octave_value::maybe_mutate in
55 // load_save_system::load_vars so there should no longer be any values
56 // of this type used by the interpreter. The action of maybe_mutate is
57 // performed by octave_legacy_range::try_narrowing_conversion.
58
59 class
60 octave_legacy_range : public octave_base_value
61 {
62 public:
63
64 octave_legacy_range (void);
65
66 octave_legacy_range (const Range& r);
67
68 octave_legacy_range (const octave_legacy_range& r) = default;
69
70 // No assignment.
71
72 octave_legacy_range& operator = (const octave_legacy_range&) = delete;
73
74 ~octave_legacy_range (void) { }
75
76 octave_base_value * clone (void) const
77 {
78 return new octave_legacy_range (*this);
79 }
80
81 // A range is really just a special kind of real matrix object. In
82 // the places where we need to call empty_clone, it makes more sense
83 // to create an empty matrix (0x0) instead of an empty range (1x0).
84 octave_base_value * empty_clone (void) const { return new octave_matrix (); }
85
86 type_conv_info numeric_conversion_function (void) const;
87
88 octave_base_value * try_narrowing_conversion (void);
89
90 bool is_defined (void) const { return true; }
91
92 bool is_legacy_object (void) const { return true; }
93
94 bool is_constant (void) const { return true; }
95
96 bool load_ascii (std::istream& is);
97
98 bool load_binary (std::istream& is, bool swap,
99 octave::mach_info::float_format fmt);
100
101 bool load_hdf5 (octave_hdf5_id loc_id, const char *name);
102
103 private:
104
105 Range range;
106
107 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
108 };
109
110 #endif