Mercurial > hg > octave-nkf
annotate libinterp/corefcn/oct-stream.h @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 44eb1102f8a8 |
children |
rev | line source |
---|---|
2117 | 1 /* |
2 | |
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19461
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2117 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2117 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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/>. | |
2117 | 20 |
21 */ | |
22 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
23 #if !defined (octave_oct_stream_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_oct_stream_h 1 |
2117 | 25 |
2877 | 26 class Matrix; |
27 class string_vector; | |
28 class octave_value; | |
29 class octave_value_list; | |
2117 | 30 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
31 #include <iosfwd> |
5765 | 32 #include <sstream> |
2877 | 33 #include <string> |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
34 #include <list> |
6757 | 35 #include <map> |
2117 | 36 |
37 #include "Array.h" | |
2317 | 38 #include "data-conv.h" |
3640 | 39 #include "lo-utils.h" |
2317 | 40 #include "mach-info.h" |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13983
diff
changeset
|
41 #include "oct-refcount.h" |
2117 | 42 |
3640 | 43 class |
6109 | 44 OCTINTERP_API |
2117 | 45 scanf_format_elt |
46 { | |
3640 | 47 public: |
48 | |
3483 | 49 enum special_conversion |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
50 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
51 whitespace_conversion = 1, |
20675
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
52 literal_conversion = 2, |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
53 null = 3 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
54 }; |
3483 | 55 |
2215 | 56 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false, |
10313 | 57 char typ = '\0', char mod = '\0', |
58 const std::string& ch_class = std::string ()) | |
3640 | 59 : text (strsave (txt)), width (w), discard (d), type (typ), |
60 modifier (mod), char_class (ch_class) { } | |
61 | |
62 scanf_format_elt (const scanf_format_elt& e) | |
63 : text (strsave (e.text)), width (e.width), discard (e.discard), | |
64 type (e.type), modifier (e.modifier), char_class (e.char_class) { } | |
2117 | 65 |
3640 | 66 scanf_format_elt& operator = (const scanf_format_elt& e) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
67 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
68 if (this != &e) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
69 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
70 text = strsave (e.text); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 width = e.width; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 discard = e.discard; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
73 type = e.type; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 modifier = e.modifier; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
75 char_class = e.char_class; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
76 } |
2117 | 77 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
78 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
79 } |
3640 | 80 |
81 ~scanf_format_elt (void) { delete [] text; } | |
82 | |
83 // The C-style format string. | |
2117 | 84 const char *text; |
3640 | 85 |
86 // The maximum field width. | |
2215 | 87 int width; |
3640 | 88 |
89 // TRUE if we are not storing the result of this conversion. | |
2117 | 90 bool discard; |
3640 | 91 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
92 // Type of conversion -- 'd', 'i', 'o', 'u', 'x', 'e', 'f', 'g', |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
93 // 'c', 's', 'p', '%', or '['. |
2117 | 94 char type; |
3640 | 95 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
96 // A length modifier -- 'h', 'l', or 'L'. |
2117 | 97 char modifier; |
3640 | 98 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
99 // The class of characters in a '[' format. |
3523 | 100 std::string char_class; |
2117 | 101 }; |
102 | |
103 class | |
6109 | 104 OCTINTERP_API |
2117 | 105 scanf_format_list |
106 { | |
107 public: | |
108 | |
3523 | 109 scanf_format_list (const std::string& fmt = std::string ()); |
2117 | 110 |
111 ~scanf_format_list (void); | |
112 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 octave_idx_type num_conversions (void) { return nconv; } |
2117 | 114 |
2215 | 115 // The length can be different than the number of conversions. |
116 // For example, "x %d y %d z" has 2 conversions but the length of | |
117 // the list is 3 because of the characters that appear after the | |
118 // last conversion. | |
119 | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
120 octave_idx_type length (void) { return list.numel (); } |
2215 | 121 |
2117 | 122 const scanf_format_elt *first (void) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
124 curr_idx = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 return current (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 } |
2117 | 127 |
128 const scanf_format_elt *current (void) const | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
129 { return list.numel () > 0 ? list.elem (curr_idx) : 0; } |
2117 | 130 |
3640 | 131 const scanf_format_elt *next (bool cycle = true) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
132 { |
20675
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
133 static scanf_format_elt dummy |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
134 (0, 0, false, scanf_format_elt::null, '\0', ""); |
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
135 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
136 curr_idx++; |
3640 | 137 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
138 if (curr_idx >= list.numel ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
140 if (cycle) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
141 curr_idx = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
142 else |
20675
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
143 return &dummy; |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 } |
20675
44eb1102f8a8
don't recycle scanf format string if all conversions are done (bug #45808)
John W. Eaton <jwe@octave.org>
parents:
20442
diff
changeset
|
145 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 return current (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 } |
2117 | 148 |
149 void printme (void) const; | |
150 | |
151 bool ok (void) const { return (nconv >= 0); } | |
152 | |
3145 | 153 operator bool () const { return ok (); } |
2117 | 154 |
155 bool all_character_conversions (void); | |
156 | |
157 bool all_numeric_conversions (void); | |
158 | |
159 private: | |
160 | |
3642 | 161 // Number of conversions specified by this format string, or -1 if |
2117 | 162 // invalid conversions have been found. |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 octave_idx_type nconv; |
2117 | 164 |
165 // Index to current element; | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
166 octave_idx_type curr_idx; |
2117 | 167 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
168 // FIXME: maybe LIST should be a std::list object? |
2117 | 169 // List of format elements. |
170 Array<scanf_format_elt*> list; | |
171 | |
172 // Temporary buffer. | |
5765 | 173 std::ostringstream *buf; |
2117 | 174 |
2215 | 175 void add_elt_to_list (int width, bool discard, char type, char modifier, |
10313 | 176 octave_idx_type& num_elts, |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
177 const std::string& char_class = std::string ()); |
2117 | 178 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
179 void process_conversion (const std::string& s, size_t& i, size_t n, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
180 int& width, bool& discard, char& type, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 char& modifier, octave_idx_type& num_elts); |
2117 | 182 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
183 int finish_conversion (const std::string& s, size_t& i, size_t n, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
184 int& width, bool discard, char& type, |
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 char modifier, octave_idx_type& num_elts); |
2117 | 186 // No copying! |
187 | |
188 scanf_format_list (const scanf_format_list&); | |
189 | |
190 scanf_format_list& operator = (const scanf_format_list&); | |
191 }; | |
192 | |
3640 | 193 class |
2117 | 194 printf_format_elt |
195 { | |
3640 | 196 public: |
197 | |
19934
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
198 printf_format_elt (const char *txt = 0, int n = 0, int w = -1, |
17a7e9f26e50
improve compatibility of printf functions
John W. Eaton <jwe@octave.org>
parents:
19898
diff
changeset
|
199 int p = -1, const std::string& f = std::string (), |
10313 | 200 char typ = '\0', char mod = '\0') |
3640 | 201 : text (strsave (txt)), args (n), fw (w), prec (p), flags (f), |
202 type (typ), modifier (mod) { } | |
203 | |
204 printf_format_elt (const printf_format_elt& e) | |
205 : text (strsave (e.text)), args (e.args), fw (e.fw), prec (e.prec), | |
206 flags (e.flags), type (e.type), modifier (e.modifier) { } | |
207 | |
208 printf_format_elt& operator = (const printf_format_elt& e) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
209 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
210 if (this != &e) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
211 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
212 text = strsave (e.text); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
213 args = e.args; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
214 fw = e.fw; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 prec = e.prec; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
216 flags = e.flags; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
217 type = e.type; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
218 modifier = e.modifier; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
219 } |
2117 | 220 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 return *this; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
222 } |
2117 | 223 |
3640 | 224 ~printf_format_elt (void) { delete [] text; } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
225 |
3640 | 226 // The C-style format string. |
2117 | 227 const char *text; |
3640 | 228 |
229 // How many args do we expect to consume? | |
2117 | 230 int args; |
3640 | 231 |
232 // Field width. | |
233 int fw; | |
234 | |
235 // Precision. | |
236 int prec; | |
237 | |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
238 // Flags -- '-', '+', ' ', '0', or '#'. |
3642 | 239 std::string flags; |
3640 | 240 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
241 // Type of conversion -- 'd', 'i', 'o', 'x', 'X', 'u', 'c', 's', |
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
242 // 'f', 'e', 'E', 'g', 'G', 'p', or '%' |
2117 | 243 char type; |
3640 | 244 |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
245 // A length modifier -- 'h', 'l', or 'L'. |
2117 | 246 char modifier; |
247 }; | |
248 | |
249 class | |
6109 | 250 OCTINTERP_API |
2117 | 251 printf_format_list |
252 { | |
253 public: | |
254 | |
3523 | 255 printf_format_list (const std::string& fmt = std::string ()); |
2117 | 256 |
257 ~printf_format_list (void); | |
258 | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
259 octave_idx_type num_conversions (void) { return nconv; } |
2117 | 260 |
261 const printf_format_elt *first (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
262 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
263 curr_idx = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
264 return current (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
265 } |
2117 | 266 |
267 const printf_format_elt *current (void) const | |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
268 { return list.numel () > 0 ? list.elem (curr_idx) : 0; } |
2117 | 269 |
3640 | 270 const printf_format_elt *next (bool cycle = true) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
271 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
272 curr_idx++; |
3640 | 273 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
274 if (curr_idx >= list.numel ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
275 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
276 if (cycle) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
277 curr_idx = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
278 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
279 return 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
280 } |
3640 | 281 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
282 return current (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
283 } |
2117 | 284 |
20442
a9574e3c6e9e
Deprecate Array::length() and Sparse::length() in favour of ::numel().
Carnë Draug <carandraug@octave.org>
parents:
19934
diff
changeset
|
285 bool last_elt_p (void) { return (curr_idx + 1 == list.numel ()); } |
3640 | 286 |
2117 | 287 void printme (void) const; |
288 | |
289 bool ok (void) const { return (nconv >= 0); } | |
290 | |
3145 | 291 operator bool () const { return ok (); } |
2117 | 292 |
293 private: | |
294 | |
3642 | 295 // Number of conversions specified by this format string, or -1 if |
2117 | 296 // invalid conversions have been found. |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
297 octave_idx_type nconv; |
2117 | 298 |
299 // Index to current element; | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
300 octave_idx_type curr_idx; |
2117 | 301 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
302 // FIXME: maybe LIST should be a std::list object? |
2117 | 303 // List of format elements. |
304 Array<printf_format_elt*> list; | |
305 | |
306 // Temporary buffer. | |
5765 | 307 std::ostringstream *buf; |
2117 | 308 |
3640 | 309 void add_elt_to_list (int args, const std::string& flags, int fw, |
10313 | 310 int prec, char type, char modifier, |
311 octave_idx_type& num_elts); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
312 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
313 void process_conversion (const std::string& s, size_t& i, size_t n, |
10313 | 314 int& args, std::string& flags, int& fw, |
315 int& prec, char& modifier, char& type, | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
316 octave_idx_type& num_elts); |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11584
diff
changeset
|
317 |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
318 void finish_conversion (const std::string& s, size_t& i, int args, |
10313 | 319 const std::string& flags, int fw, int prec, |
320 char modifier, char& type, | |
10187
a44d15813a39
don't skip literal text elements in scanf formats
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
321 octave_idx_type& num_elts); |
2117 | 322 |
323 // No copying! | |
324 | |
325 printf_format_list (const printf_format_list&); | |
326 | |
327 printf_format_list& operator = (const printf_format_list&); | |
328 }; | |
329 | |
330 // Provide an interface for Octave streams. | |
331 | |
332 class | |
6109 | 333 OCTINTERP_API |
2117 | 334 octave_base_stream |
335 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
336 friend class octave_stream; |
2117 | 337 |
338 public: | |
339 | |
3544 | 340 octave_base_stream (std::ios::openmode arg_md = std::ios::in|std::ios::out, |
10313 | 341 oct_mach_info::float_format ff |
342 = oct_mach_info::native_float_format ()) | |
11584
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11570
diff
changeset
|
343 : count (0), md (arg_md), flt_fmt (ff), fail (false), open_state (true), |
cda4aa780d58
Another round of initialising members in the constructor initialisation list
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11570
diff
changeset
|
344 errmsg () |
3340 | 345 { } |
2117 | 346 |
347 virtual ~octave_base_stream (void) { } | |
348 | |
349 // The remaining functions are not specific to input or output only, | |
350 // and must be provided by the derived classes. | |
351 | |
352 // Position a stream at OFFSET relative to ORIGIN. | |
353 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
354 virtual int seek (off_t offset, int origin) = 0; |
2117 | 355 |
356 // Return current stream position. | |
357 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
358 virtual off_t tell (void) = 0; |
2117 | 359 |
3340 | 360 // Return TRUE if EOF has been reached on this stream. |
2117 | 361 |
362 virtual bool eof (void) const = 0; | |
363 | |
364 // The name of the file. | |
365 | |
3523 | 366 virtual std::string name (void) const = 0; |
2117 | 367 |
368 // If the derived class provides this function and it returns a | |
369 // pointer to a valid istream, scanf(), read(), getl(), and gets() | |
370 // will automatically work for this stream. | |
371 | |
3523 | 372 virtual std::istream *input_stream (void) { return 0; } |
2117 | 373 |
374 // If the derived class provides this function and it returns a | |
375 // pointer to a valid ostream, flush(), write(), and printf() will | |
376 // automatically work for this stream. | |
377 | |
3523 | 378 virtual std::ostream *output_stream (void) { return 0; } |
2117 | 379 |
3340 | 380 // Return TRUE if this stream is open. |
381 | |
382 bool is_open (void) const { return open_state; } | |
383 | |
3652 | 384 virtual void do_close (void) { } |
385 | |
386 void close (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
387 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
388 if (is_open ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
389 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
390 open_state = false; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
391 do_close (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
392 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
393 } |
3340 | 394 |
11007
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
395 virtual int file_number (void) const |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
396 { |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
397 // Kluge alert! |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
398 |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
399 if (name () == "stdin") |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
400 return 0; |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
401 else if (name () == "stdout") |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
402 return 1; |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
403 else if (name () == "stderr") |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
404 return 2; |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
405 else |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
406 return -1; |
ffe58182db89
src/oct-stream.h (octave_base_stream::file_number): return 0, 1, and 2 for stdin, stdout, and stderr, -1 otherwise
John W. Eaton <jwe@octave.org>
parents:
11004
diff
changeset
|
407 } |
3145 | 408 |
2117 | 409 bool ok (void) const { return ! fail; } |
410 | |
411 // Return current error message for this stream. | |
412 | |
3523 | 413 std::string error (bool clear, int& err_num); |
2117 | 414 |
415 protected: | |
416 | |
3340 | 417 int mode (void) const { return md; } |
2117 | 418 |
3340 | 419 oct_mach_info::float_format float_format (void) const { return flt_fmt; } |
2117 | 420 |
421 // Set current error state and set fail to TRUE. | |
422 | |
3523 | 423 void error (const std::string& msg); |
4468 | 424 void error (const std::string& who, const std::string& msg); |
2117 | 425 |
426 // Clear any error message and set fail to FALSE. | |
427 | |
428 void clear (void); | |
429 | |
4889 | 430 // Clear stream state. |
431 | |
432 void clearerr (void); | |
433 | |
2117 | 434 private: |
435 | |
3340 | 436 // A reference count. |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13983
diff
changeset
|
437 octave_refcount<octave_idx_type> count; |
3340 | 438 |
2117 | 439 // The permission bits for the file. Should be some combination of |
3544 | 440 // std::ios::open_mode bits. |
2117 | 441 int md; |
442 | |
443 // Data format. | |
2317 | 444 oct_mach_info::float_format flt_fmt; |
2117 | 445 |
446 // TRUE if an error has occurred. | |
447 bool fail; | |
448 | |
3340 | 449 // TRUE if this stream is open. |
450 bool open_state; | |
451 | |
2117 | 452 // Should contain error message if fail is TRUE. |
3523 | 453 std::string errmsg; |
2117 | 454 |
455 // Functions that are defined for all input streams (input streams | |
456 // are those that define is). | |
457 | |
5275 | 458 std::string do_gets (octave_idx_type max_len, bool& err, bool strip_newline, |
10313 | 459 const std::string& who /* = "gets" */); |
2117 | 460 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
461 std::string getl (octave_idx_type max_len, bool& err, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
462 const std::string& who /* = "getl" */); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
463 std::string gets (octave_idx_type max_len, bool& err, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
464 const std::string& who /* = "gets" */); |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
465 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
2117 | 466 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
467 octave_value do_scanf (scanf_format_list& fmt_list, octave_idx_type nr, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
468 octave_idx_type nc, |
10313 | 469 bool one_elt_size_spec, octave_idx_type& count, |
470 const std::string& who /* = "scanf" */); | |
2117 | 471 |
4468 | 472 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 473 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 474 |
4468 | 475 bool do_oscanf (const scanf_format_elt *elt, octave_value&, |
10313 | 476 const std::string& who /* = "scanf" */); |
2117 | 477 |
4468 | 478 octave_value_list oscanf (const std::string& fmt, |
10313 | 479 const std::string& who /* = "scanf" */); |
2215 | 480 |
2117 | 481 // Functions that are defined for all output streams (output streams |
482 // are those that define os). | |
483 | |
484 int flush (void); | |
485 | |
18805
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
486 int do_numeric_printf_conv (std::ostream& os, const printf_format_elt *elt, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
487 int nsa, int sa_1, int sa_2, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
488 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
489 const std::string& who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
490 |
4468 | 491 int do_printf (printf_format_list& fmt_list, const octave_value_list& args, |
10313 | 492 const std::string& who /* = "printf" */); |
2117 | 493 |
4468 | 494 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 495 const std::string& who /* = "printf" */); |
2117 | 496 |
4468 | 497 int puts (const std::string& s, const std::string& who /* = "puts" */); |
2117 | 498 |
499 // We can always do this in terms of seek(), so the derived class | |
500 // only has to provide that. | |
501 | |
4468 | 502 void invalid_operation (const std::string& who, const char *rw); |
2117 | 503 |
504 // No copying! | |
505 | |
506 octave_base_stream (const octave_base_stream&); | |
507 | |
508 octave_base_stream& operator = (const octave_base_stream&); | |
509 }; | |
510 | |
511 class | |
6109 | 512 OCTINTERP_API |
2117 | 513 octave_stream |
514 { | |
515 public: | |
516 | |
3340 | 517 octave_stream (octave_base_stream *bs = 0); |
518 | |
519 ~octave_stream (void); | |
2117 | 520 |
3340 | 521 octave_stream (const octave_stream&); |
522 | |
523 octave_stream& operator = (const octave_stream&); | |
2117 | 524 |
525 int flush (void); | |
526 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
527 std::string getl (octave_idx_type max_len, bool& err, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
528 const std::string& who /* = "getl" */); |
4468 | 529 std::string getl (const octave_value& max_len, bool& err, |
10313 | 530 const std::string& who /* = "getl" */); |
2117 | 531 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
532 std::string gets (octave_idx_type max_len, bool& err, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
533 const std::string& who /* = "gets" */); |
4468 | 534 std::string gets (const octave_value& max_len, bool& err, |
10313 | 535 const std::string& who /* = "gets" */); |
2117 | 536 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
537 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
538 off_t skipl (const octave_value& count, bool& err, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
539 const std::string& who /* = "skipl" */); |
9701 | 540 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
541 int seek (off_t offset, int origin); |
2117 | 542 int seek (const octave_value& offset, const octave_value& origin); |
543 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
544 off_t tell (void); |
2117 | 545 |
546 int rewind (void); | |
547 | |
3340 | 548 bool is_open (void) const; |
549 | |
550 void close (void); | |
551 | |
5275 | 552 octave_value read (const Array<double>& size, octave_idx_type block_size, |
10313 | 553 oct_data_conv::data_type input_type, |
554 oct_data_conv::data_type output_type, | |
555 octave_idx_type skip, oct_mach_info::float_format flt_fmt, | |
556 octave_idx_type& count); | |
2117 | 557 |
5275 | 558 octave_idx_type write (const octave_value& data, octave_idx_type block_size, |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
559 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
560 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
561 oct_mach_info::float_format flt_fmt); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
562 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
563 bool write_bytes (const void *data, size_t n_elts); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
564 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
565 bool skip_bytes (size_t n_elts); |
4944 | 566 |
567 template <class T> | |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
568 octave_idx_type write (const Array<T>& data, octave_idx_type block_size, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
569 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
570 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
571 oct_mach_info::float_format flt_fmt); |
2117 | 572 |
4468 | 573 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 574 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 575 |
5279 | 576 octave_value scanf (const octave_value& fmt, const Array<double>& size, |
10313 | 577 octave_idx_type& count, const std::string& who /* = "scanf" */); |
5279 | 578 |
4468 | 579 octave_value_list oscanf (const std::string& fmt, |
10313 | 580 const std::string& who /* = "scanf" */); |
2215 | 581 |
5279 | 582 octave_value_list oscanf (const octave_value& fmt, |
10313 | 583 const std::string& who /* = "scanf" */); |
5279 | 584 |
4468 | 585 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 586 const std::string& who /* = "printf" */); |
2117 | 587 |
5279 | 588 int printf (const octave_value& fmt, const octave_value_list& args, |
10313 | 589 const std::string& who /* = "printf" */); |
5279 | 590 |
4468 | 591 int puts (const std::string& s, const std::string& who /* = "puts" */); |
592 int puts (const octave_value& s, const std::string& who /* = "puts" */); | |
2117 | 593 |
594 bool eof (void) const; | |
595 | |
3523 | 596 std::string error (bool clear, int& err_num); |
2117 | 597 |
3523 | 598 std::string error (bool clear = false) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
599 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
600 int err_num; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
601 return error (clear, err_num); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
602 } |
2117 | 603 |
4799 | 604 // Set the error message and state. |
605 | |
606 void error (const std::string& msg) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
607 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
608 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
609 rep->error (msg); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
610 } |
4799 | 611 |
612 void error (const char *msg) { error (std::string (msg)); } | |
613 | |
3148 | 614 int file_number (void) { return rep ? rep->file_number () : -1; } |
3145 | 615 |
3340 | 616 bool is_valid (void) const { return (rep != 0); } |
617 | |
2117 | 618 bool ok (void) const { return rep && rep->ok (); } |
619 | |
3145 | 620 operator bool () const { return ok (); } |
2117 | 621 |
3523 | 622 std::string name (void) const; |
2117 | 623 |
3340 | 624 int mode (void) const; |
2117 | 625 |
3340 | 626 oct_mach_info::float_format float_format (void) const; |
2117 | 627 |
3523 | 628 static std::string mode_as_string (int mode); |
2117 | 629 |
6757 | 630 std::istream *input_stream (void) |
631 { | |
632 return rep ? rep->input_stream () : 0; | |
633 } | |
2902 | 634 |
6757 | 635 std::ostream *output_stream (void) |
636 { | |
637 return rep ? rep->output_stream () : 0; | |
638 } | |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16011
diff
changeset
|
639 |
4889 | 640 void clearerr (void) { if (rep) rep->clearerr (); } |
641 | |
2117 | 642 private: |
643 | |
644 // The actual representation of this stream. | |
645 octave_base_stream *rep; | |
646 | |
5659 | 647 bool stream_ok (bool clear = true) const |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
648 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
649 bool retval = true; |
5659 | 650 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
651 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
652 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
653 if (clear) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
654 rep->clear (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
655 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
656 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
657 retval = false; |
5659 | 658 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
659 return retval; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
660 } |
4944 | 661 |
662 void invalid_operation (const std::string& who, const char *rw) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
663 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
664 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
665 rep->invalid_operation (who, rw); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
666 } |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
667 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
668 octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
669 finalize_read (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
670 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
671 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
672 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
673 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
674 oct_data_conv::data_type output_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
675 oct_mach_info::float_format ffmt); |
2117 | 676 }; |
677 | |
678 class | |
6109 | 679 OCTINTERP_API |
2117 | 680 octave_stream_list |
681 { | |
682 protected: | |
683 | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
684 octave_stream_list (void) : list (), lookup_cache (list.end ()) { } |
2117 | 685 |
686 public: | |
687 | |
688 ~octave_stream_list (void) { } | |
689 | |
2926 | 690 static bool instance_ok (void); |
691 | |
6757 | 692 static int insert (octave_stream& os); |
2117 | 693 |
4468 | 694 static octave_stream |
695 lookup (int fid, const std::string& who = std::string ()); | |
696 | |
697 static octave_stream | |
698 lookup (const octave_value& fid, const std::string& who = std::string ()); | |
2117 | 699 |
3523 | 700 static int remove (int fid, const std::string& who = std::string ()); |
3341 | 701 static int remove (const octave_value& fid, |
10313 | 702 const std::string& who = std::string ()); |
2117 | 703 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
704 static void clear (bool flush = true); |
2117 | 705 |
706 static string_vector get_info (int fid); | |
707 static string_vector get_info (const octave_value& fid); | |
708 | |
3523 | 709 static std::string list_open_files (void); |
2117 | 710 |
711 static octave_value open_file_numbers (void); | |
712 | |
2609 | 713 static int get_file_number (const octave_value& fid); |
714 | |
2117 | 715 private: |
716 | |
6757 | 717 typedef std::map<int, octave_stream> ostrl_map; |
2117 | 718 |
6757 | 719 ostrl_map list; |
2117 | 720 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
721 mutable ostrl_map::const_iterator lookup_cache; |
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
722 |
2117 | 723 static octave_stream_list *instance; |
724 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
725 static void cleanup_instance (void) { delete instance; instance = 0; } |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
726 |
6757 | 727 int do_insert (octave_stream& os); |
2117 | 728 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
729 octave_stream do_lookup (int fid, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
730 const std::string& who = std::string ()) const; |
3341 | 731 octave_stream do_lookup (const octave_value& fid, |
10313 | 732 const std::string& who = std::string ()) const; |
2117 | 733 |
3523 | 734 int do_remove (int fid, const std::string& who = std::string ()); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
735 int do_remove (const octave_value& fid, |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
736 const std::string& who = std::string ()); |
2117 | 737 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
738 void do_clear (bool flush = true); |
2117 | 739 |
740 string_vector do_get_info (int fid) const; | |
741 string_vector do_get_info (const octave_value& fid) const; | |
742 | |
3523 | 743 std::string do_list_open_files (void) const; |
2117 | 744 |
745 octave_value do_open_file_numbers (void) const; | |
746 | |
2609 | 747 int do_get_file_number (const octave_value& fid) const; |
2117 | 748 }; |
749 | |
750 #endif |