Mercurial > octave
annotate libinterp/corefcn/ls-oct-text.h @ 23455:73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
* __contourc__.cc, __qp__.cc, data.cc, graphics.cc, load-save.cc, ls-hdf5.cc,
ls-mat-ascii.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-binary.cc, ls-oct-text.h,
mappers.cc, mex.cc, pr-output.cc, sysdep.cc, variables.h, xnorm.cc, __glpk__.cc:
Remove "#include <cfloat>". Add "#include <limits>" if necessary. Remove
redundant #includes. Alphabetize #includes.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 28 Apr 2017 11:38:39 -0700 |
parents | 53f5f8231c37 |
children | a41fdb801db6 |
rev | line source |
---|---|
4634 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2003-2017 John W. Eaton |
4634 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
4634 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
4634 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
4634 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20447
diff
changeset
|
23 #if ! defined (octave_ls_oct_text_h) |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
24 #define octave_ls_oct_text_h 1 |
4634 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
27 |
23455
73ff72d3d603
maint: Eliminate <cfloat.h> header from libinterp files
Rik <rik@octave.org>
parents:
23442
diff
changeset
|
28 #include <limits> |
5765 | 29 #include <sstream> |
5099 | 30 #include <string> |
31 | |
32 #include "str-vec.h" | |
33 | |
8946
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
34 #include "ls-ascii-helper.h" |
e7e928088e90
fix CRLF issues with text-mode reading in windows when loading ascii data
Benjamin Lindner <lindnerb@users.sourceforge.net>
parents:
8920
diff
changeset
|
35 |
23442
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
36 class octave_value; |
53f5f8231c37
allow most header files to be compiled separately
John W. Eaton <jwe@octave.org>
parents:
23220
diff
changeset
|
37 |
4687 | 38 // Flag for cell elements |
39 #define CELL_ELT_TAG "<cell-element>" | |
40 | |
41 // Used when converting Inf to something that gnuplot can read. | |
42 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
43 #if ! defined (OCT_RBV) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21139
diff
changeset
|
44 # define OCT_RBV (std::numeric_limits<double>::max () / 100.0) |
4687 | 45 #endif |
46 | |
6109 | 47 extern OCTINTERP_API std::string |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
48 extract_keyword (std::istream& is, const char *keyword, |
10313 | 49 const bool next_only = false); |
4687 | 50 |
6109 | 51 extern OCTINTERP_API std::string |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
52 read_text_data (std::istream& is, const std::string& filename, bool& global, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
53 octave_value& tc, octave_idx_type count); |
4634 | 54 |
6109 | 55 extern OCTINTERP_API bool |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
56 save_text_data (std::ostream& os, const octave_value& val_arg, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
57 const std::string& name, bool mark_as_global, int precision); |
4634 | 58 |
6109 | 59 extern OCTINTERP_API bool |
20447
c6224b4e7774
maint: Rename instances of LS_ASCII to LS_TEXT for clarity.
Rik <rik@octave.org>
parents:
20232
diff
changeset
|
60 save_text_data_for_plotting (std::ostream& os, const octave_value& t, |
22407
34ce5be04942
maint: Style check C++ code in libinterp/.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
61 const std::string& name); |
4634 | 62 |
6109 | 63 extern OCTINTERP_API bool |
5958 | 64 save_three_d (std::ostream& os, const octave_value& t, |
10313 | 65 bool parametric = false); |
5958 | 66 |
5275 | 67 // Match KEYWORD on stream IS, placing the associated value in VALUE, |
68 // returning TRUE if successful and FALSE otherwise. | |
69 // | |
70 // Input should look something like: | |
71 // | |
72 // [%#][ \t]*keyword[ \t]*int-value.*\n | |
73 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21021
diff
changeset
|
74 template <typename T> |
5275 | 75 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
76 extract_keyword (std::istream& is, const char *keyword, T& value, |
10313 | 77 const bool next_only = false) |
5275 | 78 { |
79 bool status = false; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
80 value = T (); |
5275 | 81 |
82 char c; | |
83 while (is.get (c)) | |
84 { | |
85 if (c == '%' || c == '#') | |
10313 | 86 { |
87 std::ostringstream buf; | |
5275 | 88 |
10313 | 89 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) |
90 ; // Skip whitespace and comment characters. | |
5275 | 91 |
10313 | 92 if (isalpha (c)) |
93 buf << c; | |
5275 | 94 |
10313 | 95 while (is.get (c) && isalpha (c)) |
96 buf << c; | |
5275 | 97 |
10313 | 98 std::string tmp = buf.str (); |
21021
a5b99b09f8fd
maint: Use comparison operators rather than compare() for strings.
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
99 bool match = (tmp.substr (0, strlen (keyword)) == keyword); |
5275 | 100 |
10313 | 101 if (match) |
102 { | |
103 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) | |
104 ; // Skip whitespace and the colon. | |
5275 | 105 |
10313 | 106 is.putback (c); |
107 if (c != '\n' && c != '\r') | |
108 is >> value; | |
109 if (is) | |
110 status = true; | |
111 skip_until_newline (is, false); | |
112 break; | |
113 } | |
114 else if (next_only) | |
115 break; | |
116 } | |
5275 | 117 } |
118 return status; | |
119 } | |
120 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21021
diff
changeset
|
121 template <typename T> |
9852
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
122 bool |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
123 extract_keyword (std::istream& is, const std::string& kw, T& value, |
10313 | 124 const bool next_only = false) |
9852
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
125 { |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
126 return extract_keyword (is, kw.c_str (), value, next_only); |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
127 } |
aabf7a8c2e57
implement sparse logical conversion
Jaroslav Hajek <highegg@gmail.com>
parents:
8946
diff
changeset
|
128 |
5275 | 129 // Match one of the elements in KEYWORDS on stream IS, placing the |
130 // matched keyword in KW and the associated value in VALUE, | |
131 // returning TRUE if successful and FALSE otherwise. | |
132 // | |
133 // Input should look something like: | |
134 // | |
135 // [%#][ \t]*keyword[ \t]*int-value.*\n | |
136 | |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21021
diff
changeset
|
137 template <typename T> |
5275 | 138 bool |
139 extract_keyword (std::istream& is, const string_vector& keywords, | |
10313 | 140 std::string& kw, T& value, const bool next_only = false) |
5275 | 141 { |
142 bool status = false; | |
143 kw = ""; | |
144 value = 0; | |
145 | |
146 char c; | |
147 while (is.get (c)) | |
148 { | |
149 if (c == '%' || c == '#') | |
10313 | 150 { |
151 std::ostringstream buf; | |
5275 | 152 |
10313 | 153 while (is.get (c) && (c == ' ' || c == '\t' || c == '%' || c == '#')) |
154 ; // Skip whitespace and comment characters. | |
5275 | 155 |
10313 | 156 if (isalpha (c)) |
157 buf << c; | |
5275 | 158 |
10313 | 159 while (is.get (c) && isalpha (c)) |
160 buf << c; | |
5275 | 161 |
10313 | 162 std::string tmp = buf.str (); |
5275 | 163 |
20232
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19697
diff
changeset
|
164 for (int i = 0; i < keywords.numel (); i++) |
10313 | 165 { |
166 int match = (tmp == keywords[i]); | |
5275 | 167 |
10313 | 168 if (match) |
169 { | |
170 kw = keywords[i]; | |
5275 | 171 |
10313 | 172 while (is.get (c) && (c == ' ' || c == '\t' || c == ':')) |
173 ; // Skip whitespace and the colon. | |
5275 | 174 |
10313 | 175 is.putback (c); |
176 if (c != '\n' && c != '\r') | |
177 is >> value; | |
178 if (is) | |
179 status = true; | |
180 skip_until_newline (is, false); | |
181 return status; | |
182 } | |
183 } | |
5275 | 184 |
10313 | 185 if (next_only) |
186 break; | |
187 } | |
5275 | 188 } |
189 return status; | |
190 } | |
191 | |
4634 | 192 #endif |