Mercurial > octave
annotate libinterp/corefcn/oct-stream.h @ 21477:4fc04d04dd9c
make printf and scanf format element and list objects private
* oct-stream.cc (scanf_format_elt, scanf_format_list,
printf_format_elt, printf_format_list): Move class declarations and
definitions here.
* oct-stream.h: From here.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 18 Mar 2016 13:10:19 -0400 |
parents | 4f3e63d75f33 |
children | 7a19c5678f91 |
rev | line source |
---|---|
2117 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19269
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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20465
diff
changeset
|
23 #if ! defined (octave_oct_stream_h) |
17822
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 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
27 |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
28 #include <deque> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 #include <iosfwd> |
21475
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
30 #include <list> |
4f3e63d75f33
use std::deque instead of Array to hold scanf and printf format elements
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
31 #include <map> |
5765 | 32 #include <sstream> |
2877 | 33 #include <string> |
2117 | 34 |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
35 // These are only needed as arguments to private functions, so they |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
36 // are also treated as private. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
37 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
38 class scanf_format_elt; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
39 class scanf_format_list; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
40 class printf_format_elt; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
41 class printf_format_list; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
42 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
43 // These only appear as reference arguments or return values. |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
44 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
45 template <typename T> class Array; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
46 class string_vector; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
47 class octave_value; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
48 class octave_value_list; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
49 |
2317 | 50 #include "data-conv.h" |
51 #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
|
52 #include "oct-refcount.h" |
2117 | 53 |
54 // Provide an interface for Octave streams. | |
55 | |
56 class | |
6109 | 57 OCTINTERP_API |
2117 | 58 octave_base_stream |
59 { | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
60 friend class octave_stream; |
2117 | 61 |
62 public: | |
63 | |
3544 | 64 octave_base_stream (std::ios::openmode arg_md = std::ios::in|std::ios::out, |
10313 | 65 oct_mach_info::float_format ff |
66 = 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
|
67 : 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
|
68 errmsg () |
3340 | 69 { } |
2117 | 70 |
71 virtual ~octave_base_stream (void) { } | |
72 | |
73 // The remaining functions are not specific to input or output only, | |
74 // and must be provided by the derived classes. | |
75 | |
76 // Position a stream at OFFSET relative to ORIGIN. | |
77 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
78 virtual int seek (off_t offset, int origin) = 0; |
2117 | 79 |
80 // Return current stream position. | |
81 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
82 virtual off_t tell (void) = 0; |
2117 | 83 |
3340 | 84 // Return TRUE if EOF has been reached on this stream. |
2117 | 85 |
86 virtual bool eof (void) const = 0; | |
87 | |
88 // The name of the file. | |
89 | |
3523 | 90 virtual std::string name (void) const = 0; |
2117 | 91 |
92 // If the derived class provides this function and it returns a | |
93 // pointer to a valid istream, scanf(), read(), getl(), and gets() | |
94 // will automatically work for this stream. | |
95 | |
3523 | 96 virtual std::istream *input_stream (void) { return 0; } |
2117 | 97 |
98 // If the derived class provides this function and it returns a | |
99 // pointer to a valid ostream, flush(), write(), and printf() will | |
100 // automatically work for this stream. | |
101 | |
3523 | 102 virtual std::ostream *output_stream (void) { return 0; } |
2117 | 103 |
3340 | 104 // Return TRUE if this stream is open. |
105 | |
106 bool is_open (void) const { return open_state; } | |
107 | |
3652 | 108 virtual void do_close (void) { } |
109 | |
110 void close (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
111 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
112 if (is_open ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
113 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
114 open_state = false; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
115 do_close (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
116 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
117 } |
3340 | 118 |
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
|
119 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
|
120 { |
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
|
121 // 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
|
122 |
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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 } |
3145 | 132 |
2117 | 133 bool ok (void) const { return ! fail; } |
134 | |
135 // Return current error message for this stream. | |
136 | |
3523 | 137 std::string error (bool clear, int& err_num); |
2117 | 138 |
139 protected: | |
140 | |
3340 | 141 int mode (void) const { return md; } |
2117 | 142 |
3340 | 143 oct_mach_info::float_format float_format (void) const { return flt_fmt; } |
2117 | 144 |
145 // Set current error state and set fail to TRUE. | |
146 | |
3523 | 147 void error (const std::string& msg); |
4468 | 148 void error (const std::string& who, const std::string& msg); |
2117 | 149 |
150 // Clear any error message and set fail to FALSE. | |
151 | |
152 void clear (void); | |
153 | |
4889 | 154 // Clear stream state. |
155 | |
156 void clearerr (void); | |
157 | |
2117 | 158 private: |
159 | |
3340 | 160 // A reference count. |
13985
43cc49c7abd1
Use thread-safe atomic reference counting (GCC and MSVC).
Michael Goffioul <michael.goffioul@gmail.com>
parents:
13983
diff
changeset
|
161 octave_refcount<octave_idx_type> count; |
3340 | 162 |
2117 | 163 // The permission bits for the file. Should be some combination of |
3544 | 164 // std::ios::open_mode bits. |
2117 | 165 int md; |
166 | |
167 // Data format. | |
2317 | 168 oct_mach_info::float_format flt_fmt; |
2117 | 169 |
170 // TRUE if an error has occurred. | |
171 bool fail; | |
172 | |
3340 | 173 // TRUE if this stream is open. |
174 bool open_state; | |
175 | |
2117 | 176 // Should contain error message if fail is TRUE. |
3523 | 177 std::string errmsg; |
2117 | 178 |
179 // Functions that are defined for all input streams (input streams | |
180 // are those that define is). | |
181 | |
5275 | 182 std::string do_gets (octave_idx_type max_len, bool& err, bool strip_newline, |
10313 | 183 const std::string& who /* = "gets" */); |
2117 | 184 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
185 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
|
186 const std::string& who /* = "getl" */); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
187 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
|
188 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
|
189 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
2117 | 190 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
191 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
|
192 octave_idx_type nc, |
10313 | 193 bool one_elt_size_spec, octave_idx_type& count, |
194 const std::string& who /* = "scanf" */); | |
2117 | 195 |
4468 | 196 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 197 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 198 |
4468 | 199 bool do_oscanf (const scanf_format_elt *elt, octave_value&, |
10313 | 200 const std::string& who /* = "scanf" */); |
2117 | 201 |
4468 | 202 octave_value_list oscanf (const std::string& fmt, |
10313 | 203 const std::string& who /* = "scanf" */); |
2215 | 204 |
2117 | 205 // Functions that are defined for all output streams (output streams |
206 // are those that define os). | |
207 | |
208 int flush (void); | |
209 | |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
210 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
|
211 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
|
212 const octave_value& val, |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
213 const std::string& who); |
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
214 |
4468 | 215 int do_printf (printf_format_list& fmt_list, const octave_value_list& args, |
10313 | 216 const std::string& who /* = "printf" */); |
2117 | 217 |
4468 | 218 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 219 const std::string& who /* = "printf" */); |
2117 | 220 |
4468 | 221 int puts (const std::string& s, const std::string& who /* = "puts" */); |
2117 | 222 |
223 // We can always do this in terms of seek(), so the derived class | |
224 // only has to provide that. | |
225 | |
4468 | 226 void invalid_operation (const std::string& who, const char *rw); |
2117 | 227 |
228 // No copying! | |
229 | |
230 octave_base_stream (const octave_base_stream&); | |
231 | |
232 octave_base_stream& operator = (const octave_base_stream&); | |
233 }; | |
234 | |
235 class | |
6109 | 236 OCTINTERP_API |
2117 | 237 octave_stream |
238 { | |
239 public: | |
240 | |
3340 | 241 octave_stream (octave_base_stream *bs = 0); |
242 | |
243 ~octave_stream (void); | |
2117 | 244 |
3340 | 245 octave_stream (const octave_stream&); |
246 | |
247 octave_stream& operator = (const octave_stream&); | |
2117 | 248 |
249 int flush (void); | |
250 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
251 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
|
252 const std::string& who /* = "getl" */); |
4468 | 253 std::string getl (const octave_value& max_len, bool& err, |
10313 | 254 const std::string& who /* = "getl" */); |
2117 | 255 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
256 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
|
257 const std::string& who /* = "gets" */); |
4468 | 258 std::string gets (const octave_value& max_len, bool& err, |
10313 | 259 const std::string& who /* = "gets" */); |
2117 | 260 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
261 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
|
262 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
|
263 const std::string& who /* = "skipl" */); |
9701 | 264 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
265 int seek (off_t offset, int origin); |
2117 | 266 int seek (const octave_value& offset, const octave_value& origin); |
267 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
268 off_t tell (void); |
2117 | 269 |
270 int rewind (void); | |
271 | |
3340 | 272 bool is_open (void) const; |
273 | |
274 void close (void); | |
275 | |
5275 | 276 octave_value read (const Array<double>& size, octave_idx_type block_size, |
10313 | 277 oct_data_conv::data_type input_type, |
278 oct_data_conv::data_type output_type, | |
279 octave_idx_type skip, oct_mach_info::float_format flt_fmt, | |
280 octave_idx_type& count); | |
2117 | 281 |
5275 | 282 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
|
283 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
284 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
285 oct_mach_info::float_format flt_fmt); |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
286 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
287 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
|
288 |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
289 bool skip_bytes (size_t n_elts); |
4944 | 290 |
21139
538b57866b90
consistently use "typename" intead of "class" in template declarations
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
291 template <typename T> |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
292 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
|
293 oct_data_conv::data_type output_type, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
294 octave_idx_type skip, |
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
295 oct_mach_info::float_format flt_fmt); |
2117 | 296 |
4468 | 297 octave_value scanf (const std::string& fmt, const Array<double>& size, |
10313 | 298 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 299 |
5279 | 300 octave_value scanf (const octave_value& fmt, const Array<double>& size, |
10313 | 301 octave_idx_type& count, const std::string& who /* = "scanf" */); |
5279 | 302 |
4468 | 303 octave_value_list oscanf (const std::string& fmt, |
10313 | 304 const std::string& who /* = "scanf" */); |
2215 | 305 |
5279 | 306 octave_value_list oscanf (const octave_value& fmt, |
10313 | 307 const std::string& who /* = "scanf" */); |
5279 | 308 |
4468 | 309 int printf (const std::string& fmt, const octave_value_list& args, |
10313 | 310 const std::string& who /* = "printf" */); |
2117 | 311 |
5279 | 312 int printf (const octave_value& fmt, const octave_value_list& args, |
10313 | 313 const std::string& who /* = "printf" */); |
5279 | 314 |
4468 | 315 int puts (const std::string& s, const std::string& who /* = "puts" */); |
316 int puts (const octave_value& s, const std::string& who /* = "puts" */); | |
2117 | 317 |
318 bool eof (void) const; | |
319 | |
3523 | 320 std::string error (bool clear, int& err_num); |
2117 | 321 |
3523 | 322 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
|
323 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
324 int err_num; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
325 return error (clear, err_num); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
326 } |
2117 | 327 |
4799 | 328 // Set the error message and state. |
329 | |
330 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
|
331 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
332 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
333 rep->error (msg); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
334 } |
4799 | 335 |
336 void error (const char *msg) { error (std::string (msg)); } | |
337 | |
3148 | 338 int file_number (void) { return rep ? rep->file_number () : -1; } |
3145 | 339 |
3340 | 340 bool is_valid (void) const { return (rep != 0); } |
341 | |
2117 | 342 bool ok (void) const { return rep && rep->ok (); } |
343 | |
3145 | 344 operator bool () const { return ok (); } |
2117 | 345 |
3523 | 346 std::string name (void) const; |
2117 | 347 |
3340 | 348 int mode (void) const; |
2117 | 349 |
3340 | 350 oct_mach_info::float_format float_format (void) const; |
2117 | 351 |
3523 | 352 static std::string mode_as_string (int mode); |
2117 | 353 |
6757 | 354 std::istream *input_stream (void) |
355 { | |
356 return rep ? rep->input_stream () : 0; | |
357 } | |
2902 | 358 |
6757 | 359 std::ostream *output_stream (void) |
360 { | |
361 return rep ? rep->output_stream () : 0; | |
362 } | |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16011
diff
changeset
|
363 |
4889 | 364 void clearerr (void) { if (rep) rep->clearerr (); } |
365 | |
2117 | 366 private: |
367 | |
368 // The actual representation of this stream. | |
369 octave_base_stream *rep; | |
370 | |
5659 | 371 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
|
372 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
373 bool retval = true; |
5659 | 374 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
375 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
376 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
377 if (clear) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
378 rep->clear (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
379 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
380 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
381 retval = false; |
5659 | 382 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
383 return retval; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
384 } |
4944 | 385 |
386 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
|
387 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
388 if (rep) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
389 rep->invalid_operation (who, rw); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
390 } |
17453
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
391 |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
392 octave_value |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
393 finalize_read (std::list<void *>& input_buf_list, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
394 octave_idx_type input_buf_elts, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
395 octave_idx_type elts_read, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
396 octave_idx_type nr, octave_idx_type nc, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
397 oct_data_conv::data_type input_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
398 oct_data_conv::data_type output_type, |
669ad11f282d
improve efficiency of fread
John W. Eaton <jwe@octave.org>
parents:
17416
diff
changeset
|
399 oct_mach_info::float_format ffmt); |
2117 | 400 }; |
401 | |
402 class | |
6109 | 403 OCTINTERP_API |
2117 | 404 octave_stream_list |
405 { | |
406 protected: | |
407 | |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
408 octave_stream_list (void) : list (), lookup_cache (list.end ()) { } |
2117 | 409 |
410 public: | |
411 | |
412 ~octave_stream_list (void) { } | |
413 | |
2926 | 414 static bool instance_ok (void); |
415 | |
6757 | 416 static int insert (octave_stream& os); |
2117 | 417 |
4468 | 418 static octave_stream |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
419 lookup (int fid, const std::string& who = ""); |
4468 | 420 |
421 static octave_stream | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
422 lookup (const octave_value& fid, const std::string& who = ""); |
2117 | 423 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
424 static int remove (int fid, const std::string& who = ""); |
3341 | 425 static int remove (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
426 const std::string& who = ""); |
2117 | 427 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
428 static void clear (bool flush = true); |
2117 | 429 |
430 static string_vector get_info (int fid); | |
431 static string_vector get_info (const octave_value& fid); | |
432 | |
3523 | 433 static std::string list_open_files (void); |
2117 | 434 |
435 static octave_value open_file_numbers (void); | |
436 | |
2609 | 437 static int get_file_number (const octave_value& fid); |
438 | |
2117 | 439 private: |
440 | |
6757 | 441 typedef std::map<int, octave_stream> ostrl_map; |
2117 | 442 |
6757 | 443 ostrl_map list; |
2117 | 444 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
445 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
|
446 |
2117 | 447 static octave_stream_list *instance; |
448 | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
449 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
|
450 |
6757 | 451 int do_insert (octave_stream& os); |
2117 | 452 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
453 octave_stream do_lookup (int fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
454 const std::string& who = "") const; |
3341 | 455 octave_stream do_lookup (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
456 const std::string& who = "") const; |
2117 | 457 |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
458 int do_remove (int fid, const std::string& who = ""); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
459 int do_remove (const octave_value& fid, |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
460 const std::string& who = ""); |
2117 | 461 |
8902
5d5db7a347c6
erase closed files from file list & cache lookup
Jaroslav Hajek <highegg@gmail.com>
parents:
7017
diff
changeset
|
462 void do_clear (bool flush = true); |
2117 | 463 |
464 string_vector do_get_info (int fid) const; | |
465 string_vector do_get_info (const octave_value& fid) const; | |
466 | |
3523 | 467 std::string do_list_open_files (void) const; |
2117 | 468 |
469 octave_value do_open_file_numbers (void) const; | |
470 | |
2609 | 471 int do_get_file_number (const octave_value& fid) const; |
2117 | 472 }; |
473 | |
474 #endif |