Mercurial > octave
annotate liboctave/util/lo-utils.cc @ 30564:796f54d4ddbf stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
In all .txi and .texi files except gpl.txi and gpl.texi in the
doc/liboctave and doc/interpreter directories, change the copyright
to "Octave Project Developers", the same as used for other source
files. Update copyright notices for 2022 (not done since 2019). For
gpl.txi and gpl.texi, change the copyright notice to be "Free Software
Foundation, Inc." and leave the date at 2007 only because this file
only contains the text of the GPL, not anything created by the Octave
Project Developers.
Add Paul Thomas to contributors.in.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 28 Dec 2021 18:22:40 -0500 |
parents | f3f3e3793fb5 |
children | 6bd338605fd3 e88a07dec498 |
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 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30394
diff
changeset
|
3 // Copyright (C) 1996-2022 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 //////////////////////////////////////////////////////////////////////// |
1967 | 25 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21202
diff
changeset
|
27 # include "config.h" |
1967 | 28 #endif |
29 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
30 #include <cstdlib> |
7048 | 31 #include <cstring> |
1967 | 32 |
23443
3f1bf237908b
maint: Eliminate <cfloat.h> header from liboctave files.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
33 #include <complex> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
34 #include <istream> |
6490 | 35 #include <limits> |
25438
cb1606f78f6b
prefer <istream>, <ostream>, or <iosfwd> to <iostream> where possible
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
36 #include <ostream> |
2926 | 37 #include <string> |
38 | |
10068
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
39 #include "quit.h" |
ca93f583573d
handle interrupts octave_fgets
Jaroslav Hajek <highegg@gmail.com>
parents:
9469
diff
changeset
|
40 |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
41 #include "intprops-wrappers.h" |
2926 | 42 #include "lo-error.h" |
4130 | 43 #include "lo-ieee.h" |
1967 | 44 #include "lo-mappers.h" |
45 #include "lo-utils.h" | |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
46 #include "oct-inttypes.h" |
1967 | 47 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
48 namespace octave |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
49 { |
29937
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
50 bool is_int_or_inf_or_nan (double x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
51 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
52 return math::isnan (x) || math::x_nint (x) == x; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
53 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
54 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
55 bool too_large_for_float (double x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
56 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
57 return (math::isfinite (x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
58 && fabs (x) > std::numeric_limits<float>::max ()); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
59 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
60 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
61 bool too_large_for_float (const Complex& x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
62 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
63 return (too_large_for_float (x.real ()) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
64 || too_large_for_float (x.imag ())); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
65 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
66 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
67 bool is_int_or_inf_or_nan (float x) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
68 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
69 return math::isnan (x) || math::x_nint (x) == x; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
70 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
71 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
72 // Save a string. |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
73 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
74 char * strsave (const char *s) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
75 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
76 if (! s) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
77 return nullptr; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
78 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
79 int len = strlen (s); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
80 char *tmp = new char [len+1]; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
81 tmp = strcpy (tmp, s); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
82 return tmp; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
83 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
84 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
85 std::string fgets (FILE *f) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
86 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
87 bool eof; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
88 return fgets (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
89 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
90 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
91 std::string fgets (FILE *f, bool& eof) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
92 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
93 eof = false; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
94 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
95 std::string retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
96 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
97 int grow_size = 1024; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
98 int max_size = grow_size; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
99 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
100 char *buf = static_cast<char *> (std::malloc (max_size)); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
101 if (! buf) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
102 (*current_liboctave_error_handler) ("octave_fgets: unable to malloc %d bytes", max_size); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
103 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
104 char *bufptr = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
105 int len = 0; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
106 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
107 do |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
108 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
109 if (std::fgets (bufptr, grow_size, f)) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
110 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
111 len = strlen (bufptr); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
112 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
113 if (len == grow_size - 1) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
114 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
115 int tmp = bufptr - buf + grow_size - 1; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
116 grow_size *= 2; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
117 max_size += grow_size; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
118 auto tmpbuf = static_cast<char *> (std::realloc (buf, max_size)); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
119 if (! tmpbuf) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
120 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
121 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
122 (*current_liboctave_error_handler) ("octave_fgets: unable to realloc %d bytes", max_size); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
123 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
124 buf = tmpbuf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
125 bufptr = buf + tmp; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
126 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
127 if (*(bufptr-1) == '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
128 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
129 *bufptr = '\0'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
130 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
131 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
132 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
133 else if (bufptr[len-1] != '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
134 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
135 bufptr[len++] = '\n'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
136 bufptr[len] = '\0'; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
137 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
138 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
139 else |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
140 retval = buf; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
141 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
142 else |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
143 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
144 if (len == 0) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
145 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
146 eof = true; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
147 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
148 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
149 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
150 buf = nullptr; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
151 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
152 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
153 break; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
154 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
155 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
156 while (retval.empty ()); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
157 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
158 free (buf); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
159 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
160 octave_quit (); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
161 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
162 return retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
163 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
164 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
165 std::string fgetl (FILE *f) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
166 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
167 bool eof; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
168 return fgetl (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
169 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
170 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
171 std::string fgetl (FILE *f, bool& eof) |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
172 { |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
173 std::string retval = fgets (f, eof); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
174 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
175 if (! retval.empty () && retval.back () == '\n') |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
176 retval.pop_back (); |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
177 |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
178 return retval; |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
179 } |
da7210e30f3e
move some utility functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29445
diff
changeset
|
180 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
181 template <typename T> |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
182 T |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
183 read_value (std::istream& is) |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
184 { |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
185 T retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
186 is >> retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
187 return retval; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
188 } |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
189 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
190 template OCTAVE_API bool read_value<bool> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
191 template OCTAVE_API octave_int8 read_value<octave_int8> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
192 template OCTAVE_API octave_int16 read_value<octave_int16> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
193 template OCTAVE_API octave_int32 read_value<octave_int32> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
194 template OCTAVE_API octave_int64 read_value<octave_int64> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
195 template OCTAVE_API octave_uint8 read_value<octave_uint8> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
196 template OCTAVE_API octave_uint16 read_value<octave_uint16> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
197 template OCTAVE_API octave_uint32 read_value<octave_uint32> (std::istream& is); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
198 template OCTAVE_API octave_uint64 read_value<octave_uint64> (std::istream& is); |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
199 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
200 // Note that the caller is responsible for repositioning the stream on |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
201 // failure. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
202 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
203 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
204 T |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
205 read_inf_nan_na (std::istream& is, char c0) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
206 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
207 T val = 0.0; |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
208 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
209 switch (c0) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
210 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
211 case 'i': case 'I': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
212 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
213 char c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
214 if (c1 == 'n' || c1 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
215 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
216 char c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
217 if (c2 == 'f' || c2 == 'F') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
218 val = std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
219 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
220 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
221 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
222 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
223 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
224 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
225 break; |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
226 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
227 case 'n': case 'N': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
228 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
229 char c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
230 if (c1 == 'a' || c1 == 'A') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
231 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
232 char c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
233 if (c2 == 'n' || c2 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
234 val = std::numeric_limits<T>::quiet_NaN (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
235 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
236 { |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28849
diff
changeset
|
237 val = numeric_limits<T>::NA (); |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
238 if (c2 != std::istream::traits_type::eof ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
239 is.putback (c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
240 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
241 is.clear (is.rdstate () & ~std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
242 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
243 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
244 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
245 is.setstate (std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
246 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
247 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
248 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
249 default: |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
250 (*current_liboctave_error_handler) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
251 ("read_inf_nan_na: invalid character '%c'", c0); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
252 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
253 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
254 return val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
255 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
256 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
257 // Read a double value. Discard any sign on NaN and NA. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
258 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
259 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
260 double |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
261 read_fp_value (std::istream& is) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
262 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
263 T val = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
264 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
265 // FIXME: resetting stream position is likely to fail unless we are |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
266 // reading from a file. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
267 std::streampos pos = is.tellg (); |
4130 | 268 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
269 char c1 = ' '; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
270 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
271 while (isspace (c1)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
272 c1 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
273 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
274 bool neg = false; |
4130 | 275 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
276 switch (c1) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
277 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
278 case '-': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
279 neg = true; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
280 OCTAVE_FALLTHROUGH; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
281 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
282 case '+': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
283 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
284 char c2 = 0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
285 c2 = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
286 if (c2 == 'i' || c2 == 'I' || c2 == 'n' || c2 == 'N') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
287 val = read_inf_nan_na<T> (is, c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
288 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
289 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
290 is.putback (c2); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
291 is >> val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
292 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
293 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
294 if (neg && ! is.fail ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
295 val = -val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
296 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
297 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
298 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
299 case 'i': case 'I': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
300 case 'n': case 'N': |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
301 val = read_inf_nan_na<T> (is, c1); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
302 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
303 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
304 default: |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
305 is.putback (c1); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
306 is >> val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
307 break; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
308 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
309 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
310 std::ios::iostate status = is.rdstate (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
311 if (status & std::ios::failbit) |
4130 | 312 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
313 // Convert MAX_VAL returned by C++ streams for very large numbers to Inf |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
314 if (val == std::numeric_limits<T>::max ()) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
315 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
316 if (neg) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
317 val = -std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
318 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
319 val = std::numeric_limits<T>::infinity (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
320 is.clear (status & ~std::ios::failbit); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
321 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
322 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
323 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
324 // True error. Reset stream to original position and pass status on. |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
325 is.clear (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
326 is.seekg (pos); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
327 is.setstate (status); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
328 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
329 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
330 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
331 return val; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
332 } |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
333 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
334 template <typename T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
335 std::complex<T> |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
336 read_cx_fp_value (std::istream& is) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
337 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
338 T re = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
339 T im = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
340 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
341 std::complex<T> cx = 0.0; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
342 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
343 char ch = ' '; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
344 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
345 while (isspace (ch)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
346 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
347 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
348 if (ch == '(') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
349 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
350 re = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
351 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
352 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
353 if (ch == ',') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
354 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
355 im = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
356 ch = is.get (); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
357 |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
358 if (ch == ')') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
359 cx = std::complex<T> (re, im); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
360 else |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
361 is.setstate (std::ios::failbit); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
362 } |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
363 else if (ch == ')') |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
364 cx = re; |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
365 else |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
366 is.setstate (std::ios::failbit); |
4130 | 367 } |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
368 else |
6194 | 369 { |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
370 is.putback (ch); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
371 cx = read_value<T> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
372 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
373 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
374 return cx; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
375 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
376 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
377 // FIXME: Could we use traits and enable_if to avoid duplication in the |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
378 // following specializations? |
6194 | 379 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
380 template <> OCTAVE_API double read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
381 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
382 return read_fp_value<double> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
383 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
384 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
385 template <> OCTAVE_API Complex read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
386 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
387 return read_cx_fp_value<double> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
388 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
389 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
390 template <> OCTAVE_API float read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
391 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
392 return read_fp_value<float> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
393 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
394 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
395 template <> OCTAVE_API FloatComplex read_value (std::istream& is) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
396 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
397 return read_cx_fp_value<float> (is); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
398 } |
4130 | 399 |
29230
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
400 template <typename T> |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
401 void |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
402 write_value (std::ostream& os, const T& value) |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
403 { |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
404 os << value; |
6b3faa844395
Set API tags in files in liboctave/util (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28857
diff
changeset
|
405 } |
6194 | 406 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
407 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
408 write_value<bool> (std::ostream& os, const bool& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
409 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
410 write_value<octave_int8> (std::ostream& os, const octave_int8& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
411 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
412 write_value<octave_int16> (std::ostream& os, const octave_int16& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
413 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
414 write_value<octave_int32> (std::ostream& os, const octave_int32& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
415 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
416 write_value<octave_int64> (std::ostream& os, const octave_int64& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
417 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
418 write_value<octave_uint8> (std::ostream& os, const octave_uint8& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
419 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
420 write_value<octave_uint16> (std::ostream& os, const octave_uint16& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
421 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
422 write_value<octave_uint32> (std::ostream& os, const octave_uint32& value); |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
423 template OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
424 write_value<octave_uint64> (std::ostream& os, const octave_uint64& value); |
4130 | 425 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
426 // Note: precision is supposed to be managed outside of this function by |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
427 // setting stream parameters. |
4130 | 428 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
429 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
430 write_value (std::ostream& os, const double& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
431 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
432 if (lo_ieee_is_NA (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
433 os << "NA"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
434 else if (lo_ieee_isnan (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
435 os << "NaN"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
436 else if (lo_ieee_isinf (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
437 os << (value < 0 ? "-Inf" : "Inf"); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
438 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
439 os << value; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
440 } |
4130 | 441 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
442 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
443 write_value (std::ostream& os, const Complex& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
444 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
445 os << '('; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
446 write_value<double> (os, real (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
447 os << ','; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
448 write_value<double> (os, imag (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
449 os << ')'; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
450 } |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
451 |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
452 // Note: precision is supposed to be managed outside of this function by |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
453 // setting stream parameters. |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
454 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
455 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
456 write_value (std::ostream& os, const float& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
457 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
458 if (lo_ieee_is_NA (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
459 os << "NA"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
460 else if (lo_ieee_isnan (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
461 os << "NaN"; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
462 else if (lo_ieee_isinf (value)) |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
463 os << (value < 0 ? "-Inf" : "Inf"); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
464 else |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
465 os << value; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
466 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
467 |
29244
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
468 template <> OCTAVE_API void |
d1473e75d7d6
lo-utils: Export template instantiations (patch #8919).
Markus Mützel <markus.muetzel@gmx.de>
parents:
29230
diff
changeset
|
469 write_value (std::ostream& os, const FloatComplex& value) |
28628
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
470 { |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
471 os << '('; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
472 write_value<float> (os, real (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
473 os << ','; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
474 write_value<float> (os, imag (value)); |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
475 os << ')'; |
83172e1c77f2
refactor octave_read_* and octave_write_* functions
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
476 } |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
477 |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
478 namespace math |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
479 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
480 bool int_multiply_overflow (int a, int b, int *r) |
14806
980e2d5c83f7
avoid calling putback more than once between reads
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
481 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
482 return octave_i_multiply_overflow_wrapper (a, b, r); |
4130 | 483 } |
484 | |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
485 bool int_multiply_overflow (long int a, long int b, long int *r) |
4130 | 486 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
487 return octave_li_multiply_overflow_wrapper (a, b, r); |
4130 | 488 } |
489 | |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
490 #if defined (OCTAVE_HAVE_LONG_LONG_INT) |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
491 bool int_multiply_overflow (long long int a, long long int b, |
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
492 long long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
493 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
494 return octave_lli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
495 } |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
496 #endif |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
497 |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
498 bool int_multiply_overflow (unsigned int a, unsigned int b, |
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
499 unsigned int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
500 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
501 return octave_ui_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
502 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
503 |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
504 bool int_multiply_overflow (unsigned long int a, unsigned long int b, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
505 unsigned long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
506 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
507 return octave_uli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
508 } |
9469
c6edba80dfae
sanity checks for loading sparse matrices
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
509 |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
510 #if defined (OCTAVE_HAVE_UNSIGNED_LONG_LONG_INT) |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
511 bool int_multiply_overflow (unsigned long long int a, |
30394
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
512 unsigned long long int b, |
f3f3e3793fb5
maint: style check C++ files in liboctave/ ahead of 7.1 release.
Rik <rik@octave.org>
parents:
29937
diff
changeset
|
513 unsigned long long int *r) |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
514 { |
29445
b5f3ae7610cf
Use gnulib macros that account for the output type in integer overflow checks.
Markus Mützel <markus.muetzel@gmx.de>
parents:
29359
diff
changeset
|
515 return octave_ulli_multiply_overflow_wrapper (a, b, r); |
28849
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
516 } |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
517 #endif |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
518 |
8b0675c2cfe0
Add functions to check for integer overflow on multiplication (bug #59094).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28643
diff
changeset
|
519 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7048
diff
changeset
|
520 } |