Mercurial > octave
annotate libinterp/corefcn/ls-oct-binary.cc @ 32632:2e484f9f1f18 stable
maint: update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 22 Dec 2023 12:08:17 -0500 |
parents | 597f3ee61a48 |
children |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
32632
2e484f9f1f18
maint: update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31706
diff
changeset
|
3 // Copyright (C) 1996-2024 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
4634 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
27 # include "config.h" |
4634 | 28 #endif |
29 | |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
30 #include <istream> |
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25392
diff
changeset
|
31 #include <ostream> |
4634 | 32 #include <string> |
33 | |
34 #include "byte-swap.h" | |
35 #include "data-conv.h" | |
36 #include "file-ops.h" | |
37 #include "glob-match.h" | |
38 #include "lo-mappers.h" | |
39 #include "mach-info.h" | |
40 #include "oct-env.h" | |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
41 #include "oct-locbuf.h" |
4634 | 42 #include "oct-time.h" |
43 | |
44 #include "defun.h" | |
45 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20955
diff
changeset
|
46 #include "errwarn.h" |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
47 #include "interpreter.h" |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
48 #include "interpreter-private.h" |
4634 | 49 #include "load-save.h" |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
50 #include "ls-oct-binary.h" |
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
51 #include "ls-utils.h" |
4634 | 52 #include "ov-cell.h" |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23450
diff
changeset
|
53 #include "ov.h" |
4634 | 54 #include "pager.h" |
55 #include "sysdep.h" | |
56 #include "utils.h" | |
57 #include "variables.h" | |
58 #include "version.h" | |
59 | |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
60 static bool |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
61 load_inline_fcn (std::istream& is, bool swap, octave::mach_info::float_format, |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
62 octave_value& retval) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
63 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
64 int32_t nargs; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
65 if (! is.read (reinterpret_cast<char *> (&nargs), 4)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
66 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
67 if (swap) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
68 swap_bytes<4> (&nargs); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
69 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
70 if (nargs < 1) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
71 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
72 else |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
73 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
74 int32_t tmp; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
75 octave_value_list args (nargs+1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
76 for (int i = 0; i < nargs; i++) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
77 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
78 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
79 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
80 if (swap) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
81 swap_bytes<4> (&tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
82 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
83 OCTAVE_LOCAL_BUFFER (char, ctmp, tmp+1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
84 is.read (ctmp, tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
85 args(i+1) = std::string (ctmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
86 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
87 if (! is) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
88 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
89 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
90 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
91 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
92 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
93 if (swap) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
94 swap_bytes<4> (&tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
95 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
96 OCTAVE_LOCAL_BUFFER (char, ctmp1, tmp+1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
97 is.read (ctmp1, tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
98 // NAME is obsolete and unused. |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
99 // std::string name (ctmp1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
100 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
101 if (! is) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
102 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
103 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
104 if (! is.read (reinterpret_cast<char *> (&tmp), 4)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
105 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
106 if (swap) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
107 swap_bytes<4> (&tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
108 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
109 OCTAVE_LOCAL_BUFFER (char, ctmp2, tmp+1); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
110 is.read (ctmp2, tmp); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
111 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
112 if (is) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
113 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
114 args(0) = std::string (ctmp2); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
115 |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
116 octave::interpreter& interp = octave::__get_interpreter__ (); |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
117 |
28448
97a8ec57c33e
Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28427
diff
changeset
|
118 octave_value_list tmp_inl = interp.feval ("inline", args, 1); |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
119 |
28448
97a8ec57c33e
Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28427
diff
changeset
|
120 if (tmp_inl.length () > 0) |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
121 { |
28448
97a8ec57c33e
Avoid shadowing warnings.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28427
diff
changeset
|
122 retval = tmp_inl(0); |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
123 return true; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
124 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
125 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
126 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
127 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
128 return false; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
129 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
130 |
4634 | 131 // Extract one value (scalar, matrix, string, etc.) from stream IS and |
132 // place it in TC, returning the name of the variable. If the value | |
133 // is tagged as global in the file, return TRUE in GLOBAL. If SWAP | |
134 // is TRUE, swap bytes after reading. | |
135 // | |
136 // The data is expected to be in the following format: | |
137 // | |
138 // Header (one per file): | |
139 // ===================== | |
140 // | |
141 // object type bytes | |
142 // ------ ---- ----- | |
143 // magic number string 10 | |
144 // | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
145 // float format integer 1 |
4634 | 146 // |
147 // | |
148 // Data (one set for each item): | |
149 // ============================ | |
150 // | |
151 // object type bytes | |
152 // ------ ---- ----- | |
153 // name_length integer 4 | |
154 // | |
155 // name string name_length | |
156 // | |
157 // doc_length integer 4 | |
158 // | |
159 // doc string doc_length | |
160 // | |
161 // global flag integer 1 | |
162 // | |
4687 | 163 // data type char 1 |
4634 | 164 // |
4687 | 165 // In general "data type" is 255, and in that case the next arguments |
166 // in the data set are | |
4634 | 167 // |
4687 | 168 // object type bytes |
169 // ------ ---- ----- | |
170 // type_length integer 4 | |
4634 | 171 // |
4687 | 172 // type string type_length |
173 // | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
174 // The string "type" is then used with octave::type_info::lookup_type |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
175 // to create an octave_value of the correct type. The specific load/save |
4687 | 176 // function is then called. |
4634 | 177 // |
20837 | 178 // For backward compatibility "data type" can also be a value between 1 |
4687 | 179 // and 7, where this defines a hardcoded octave_value of the type |
4634 | 180 // |
4687 | 181 // data type octave_value |
182 // --------- ------------ | |
183 // 1 scalar | |
184 // 2 matrix | |
185 // 3 complex scalar | |
186 // 4 complex matrix | |
187 // 5 string (old style storage) | |
188 // 6 range | |
189 // 7 string | |
4634 | 190 // |
4687 | 191 // Except for "data type" equal 5 that requires special treatment, these |
192 // old style "data type" value also cause the specific load/save functions | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
193 // to be called. FILENAME is used for error messages. |
4634 | 194 |
195 std::string | |
196 read_binary_data (std::istream& is, bool swap, | |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
197 octave::mach_info::float_format fmt, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
198 const std::string& filename, bool& global, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
199 octave_value& tc, std::string& doc) |
4634 | 200 { |
201 std::string retval; | |
202 | |
6240 | 203 unsigned char tmp = 0; |
4634 | 204 |
5828 | 205 int32_t name_len = 0; |
206 int32_t doc_len = 0; | |
4634 | 207 |
23812
057a894914df
Use C++11 string fcns back() and pop_back() to simplify code.
Rik <rik@octave.org>
parents:
23470
diff
changeset
|
208 doc.clear (); |
4634 | 209 |
210 // We expect to fail here, at the beginning of a record, so not | |
211 // being able to read another name should not result in an error. | |
212 | |
5760 | 213 is.read (reinterpret_cast<char *> (&name_len), 4); |
4634 | 214 if (! is) |
215 return retval; | |
216 if (swap) | |
4944 | 217 swap_bytes<4> (&name_len); |
4634 | 218 |
219 { | |
220 OCTAVE_LOCAL_BUFFER (char, name, name_len+1); | |
221 name[name_len] = '\0'; | |
5760 | 222 if (! is.read (reinterpret_cast<char *> (name), name_len)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
223 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 224 retval = name; |
225 } | |
226 | |
5760 | 227 is.read (reinterpret_cast<char *> (&doc_len), 4); |
4634 | 228 if (! is) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
229 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 230 if (swap) |
4944 | 231 swap_bytes<4> (&doc_len); |
4634 | 232 |
233 { | |
234 OCTAVE_LOCAL_BUFFER (char, tdoc, doc_len+1); | |
235 tdoc[doc_len] = '\0'; | |
5760 | 236 if (! is.read (reinterpret_cast<char *> (tdoc), doc_len)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
237 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 238 doc = tdoc; |
239 } | |
240 | |
5760 | 241 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
242 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
23450
855122b993da
maint: Wrap tertiary operator in parentheses "(COND ? x : y)".
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
243 global = (tmp ? 1 : 0); |
4634 | 244 |
245 tmp = 0; | |
5760 | 246 if (! is.read (reinterpret_cast<char *> (&tmp), 1)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
247 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 248 |
31105
670a0d878af1
eliminate WHO arguments from interpreter-private functions
John W. Eaton <jwe@octave.org>
parents:
30564
diff
changeset
|
249 octave::type_info& type_info = octave::__get_type_info__ (); |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
250 |
4687 | 251 // All cases except 255 kept for backwards compatibility |
4634 | 252 switch (tmp) |
253 { | |
254 case 1: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
255 tc = type_info.lookup_type ("scalar"); |
4634 | 256 break; |
257 | |
258 case 2: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
259 tc = type_info.lookup_type ("matrix"); |
4634 | 260 break; |
261 | |
262 case 3: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
263 tc = type_info.lookup_type ("complex scalar"); |
4634 | 264 break; |
265 | |
266 case 4: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
267 tc = type_info.lookup_type ("complex matrix"); |
4634 | 268 break; |
269 | |
270 case 5: | |
271 { | |
17861
870f3e12e163
maint: Use phrase "FIXME:" for problem areas in code.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 // FIXME: |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
273 // This is cruft, since its for a save type that is old. |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
274 // Maybe this is taking backward compatibility too far! |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
275 int32_t len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
276 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
277 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
278 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 swap_bytes<4> (&len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 OCTAVE_LOCAL_BUFFER (char, s, len+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
281 if (! is.read (reinterpret_cast<char *> (s), len)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
282 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
283 s[len] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
284 tc = s; |
4687 | 285 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
286 // Early return, since don't want rest of this function |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
287 return retval; |
4634 | 288 } |
289 break; | |
290 | |
291 case 6: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
292 tc = type_info.lookup_type ("range"); |
4634 | 293 break; |
294 | |
295 case 7: | |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
296 tc = type_info.lookup_type ("string"); |
4687 | 297 break; |
298 | |
299 case 255: | |
4634 | 300 { |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
301 // Read the saved variable type |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
302 int32_t len; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
303 if (! is.read (reinterpret_cast<char *> (&len), 4)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
304 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
305 if (swap) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
306 swap_bytes<4> (&len); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
307 OCTAVE_LOCAL_BUFFER (char, s, len+1); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
308 if (! is.read (s, len)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
309 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
310 s[len] = '\0'; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
311 std::string typ = s; |
28427
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
312 |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
313 if (typ == "inline function") |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
314 { |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
315 // Special case for loading old octave_inline_fcn objects. |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
316 if (! load_inline_fcn (is, swap, fmt, tc)) |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
317 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
318 return retval; |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
319 } |
7a8c69c4eb55
convert obsolete octave_fcn_inline object to @inline class
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
320 |
24540
46440078d73b
don't use singleton for octave_value_typeinfo
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
321 tc = type_info.lookup_type (typ); |
4634 | 322 } |
323 break; | |
324 default: | |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
325 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4687 | 326 break; |
327 } | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
328 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
329 if (! tc.load_binary (is, swap, fmt)) |
21170
1edaf1ee65eb
maint: Replace some uses of goto in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
330 error ("load: trouble reading binary file '%s'", filename.c_str ()); |
4634 | 331 |
332 return retval; | |
333 } | |
334 | |
335 // Save the data from TC along with the corresponding NAME, help | |
336 // string DOC, and global flag MARK_AS_GLOBAL on stream OS in the | |
337 // binary format described above for read_binary_data. | |
338 | |
339 bool | |
340 save_binary_data (std::ostream& os, const octave_value& tc, | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
341 const std::string& name, const std::string& doc, |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23455
diff
changeset
|
342 bool mark_global, bool save_as_floats) |
4634 | 343 { |
5828 | 344 int32_t name_len = name.length (); |
4634 | 345 |
5760 | 346 os.write (reinterpret_cast<char *> (&name_len), 4); |
4634 | 347 os << name; |
348 | |
5828 | 349 int32_t doc_len = doc.length (); |
4634 | 350 |
5760 | 351 os.write (reinterpret_cast<char *> (&doc_len), 4); |
4634 | 352 os << doc; |
353 | |
4730 | 354 unsigned char tmp; |
4634 | 355 |
23470
a41fdb801db6
use mark_global and mark_persistent consistently
John W. Eaton <jwe@octave.org>
parents:
23455
diff
changeset
|
356 tmp = mark_global; |
5760 | 357 os.write (reinterpret_cast<char *> (&tmp), 1); |
4634 | 358 |
4687 | 359 // 255 flags the new binary format |
360 tmp = 255; | |
5760 | 361 os.write (reinterpret_cast<char *> (&tmp), 1); |
4634 | 362 |
4687 | 363 // Write the string corresponding to the octave_value type |
364 std::string typ = tc.type_name (); | |
5828 | 365 int32_t len = typ.length (); |
5760 | 366 os.write (reinterpret_cast<char *> (&len), 4); |
4687 | 367 const char *btmp = typ.data (); |
5760 | 368 os.write (btmp, len); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
369 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21739
diff
changeset
|
370 // The octave_value of tc is const. Make a copy... |
4687 | 371 octave_value val = tc; |
372 | |
373 // Call specific save function | |
374 bool success = val.save_binary (os, save_as_floats); | |
375 | |
376 return (os && success); | |
4634 | 377 } |