Mercurial > octave
annotate libinterp/corefcn/oct-stream.h @ 27923:bd51beb6205e
update formatting of copyright notices
* Use <https://octave.org/copyright/> instead of
<https://octave.org/COPYRIGHT.html/>.
* For consistency with other comments in the Octave sources, use
C++-style comments for copyright blocks in C and C++ files.
* Use delimiters above and below copyright blocks that are appropriate
for the language used in the file.
* Eliminate extra spacing inside copyright blocks.
* lex.ll (looks_like_copyright): Also allow newlines and carriage
returns before the word "Copyright".
* scripts/mk-doc.pl (gethelp): Also skip empty comment lines.
* bp-table.cc, type.m: Adjust tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 08 Jan 2020 11:59:41 -0500 |
parents | 1891570abac8 |
children | 665c9ed14c97 0a5b15007766 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
3 // Copyright (C) 1996-2020 The Octave Project Developers |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2117 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20465
diff
changeset
|
26 #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
|
27 #define octave_oct_stream_h 1 |
2117 | 28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21139
diff
changeset
|
30 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
31 #include <ios> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
32 #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
|
33 #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
|
34 #include <map> |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
35 #include <memory> |
2877 | 36 #include <string> |
2117 | 37 |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
38 // 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
|
39 |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
40 template <typename T> class Array; |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
41 class Cell; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
42 class octave_value; |
21502
7a19c5678f91
move textscan class to oct-stream.cc and textscan function to file-io.cc
John W. Eaton <jwe@octave.org>
parents:
21477
diff
changeset
|
43 class octave_value_list; |
21477
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
44 class string_vector; |
4fc04d04dd9c
make printf and scanf format element and list objects private
John W. Eaton <jwe@octave.org>
parents:
21475
diff
changeset
|
45 |
2317 | 46 #include "data-conv.h" |
47 #include "mach-info.h" | |
2117 | 48 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
49 namespace octave |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
50 { |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
51 class interpreter; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
52 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
53 // These are only needed as arguments to private functions, so they |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
54 // are also treated as private. |
2117 | 55 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
56 class scanf_format_elt; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
57 class scanf_format_list; |
2117 | 58 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
59 class printf_format_elt; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
60 class printf_format_list; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
61 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
62 // Provide an interface for Octave streams. |
2117 | 63 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
64 class |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
65 OCTINTERP_API |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
66 base_stream |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
67 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
68 friend class stream; |
2117 | 69 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
70 public: |
2117 | 71 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
72 base_stream (std::ios::openmode arg_md = std::ios::in | std::ios::out, |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
73 mach_info::float_format ff = mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
74 const std::string& encoding = "utf-8") |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
75 : m_mode (arg_md), m_flt_fmt (ff), m_encoding (encoding), |
27172 | 76 m_fail (false), m_open_state (true), m_errmsg () |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
77 { } |
2117 | 78 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
79 // No copying! |
2117 | 80 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
81 base_stream (const base_stream&) = delete; |
2117 | 82 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
83 base_stream& operator = (const base_stream&) = delete; |
2117 | 84 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
85 virtual ~base_stream (void) = default; |
2117 | 86 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
87 // The remaining functions are not specific to input or output only, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
88 // and must be provided by the derived classes. |
2117 | 89 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
90 // Position a stream at OFFSET relative to ORIGIN. |
2117 | 91 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
92 virtual int seek (off_t offset, int origin) = 0; |
2117 | 93 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
94 // Return current stream position. |
2117 | 95 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
96 virtual off_t tell (void) = 0; |
2117 | 97 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
98 // Return TRUE if EOF has been reached on this stream. |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
99 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
100 virtual bool eof (void) const = 0; |
2117 | 101 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
102 // The name of the file. |
2117 | 103 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
104 virtual std::string name (void) const = 0; |
2117 | 105 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
106 // If the derived class provides this function and it returns a |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
107 // pointer to a valid istream, scanf(), read(), getl(), and gets() |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
108 // will automatically work for this stream. |
2117 | 109 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
110 virtual std::istream * input_stream (void) { return nullptr; } |
3340 | 111 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
112 // If the derived class provides this function and it returns a |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
113 // pointer to a valid ostream, flush(), write(), and printf() will |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
114 // automatically work for this stream. |
3340 | 115 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23738
diff
changeset
|
116 virtual std::ostream * output_stream (void) { return nullptr; } |
3652 | 117 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
118 // Return TRUE if this stream is open. |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
119 |
27172 | 120 bool is_open (void) const { return m_open_state; } |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
121 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
122 virtual void do_close (void) { } |
3340 | 123 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
124 void close (void) |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
125 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
126 if (is_open ()) |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
127 { |
27172 | 128 m_open_state = false; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
129 do_close (); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
130 } |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
131 } |
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
|
132 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
133 virtual int file_number (void) const |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
134 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
135 // Kluge alert! |
3145 | 136 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
137 if (name () == "stdin") |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
138 return 0; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
139 else if (name () == "stdout") |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
140 return 1; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
141 else if (name () == "stderr") |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
142 return 2; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
143 else |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
144 return -1; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
145 } |
2117 | 146 |
27172 | 147 bool ok (void) const { return ! m_fail; } |
2117 | 148 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
149 // Return current error message for this stream. |
2117 | 150 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
151 std::string error (bool clear, int& err_num); |
2117 | 152 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
153 protected: |
2117 | 154 |
27172 | 155 int mode (void) const { return m_mode; } |
2117 | 156 |
27172 | 157 mach_info::float_format float_format (void) const { return m_flt_fmt; } |
2117 | 158 |
27172 | 159 std::string encoding (void) const { return m_encoding; } |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
160 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
161 // Set current error state and set fail to TRUE. |
4889 | 162 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
163 void error (const std::string& msg); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
164 void error (const std::string& who, const std::string& msg); |
2117 | 165 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
166 // Clear any error message and set fail to FALSE. |
3340 | 167 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
168 void clear (void); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
169 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
170 // Clear stream state. |
2117 | 171 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
172 void clearerr (void); |
2117 | 173 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
174 private: |
2117 | 175 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
176 // The permission bits for the file. Should be some combination of |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
177 // std::ios::open_mode bits. |
27172 | 178 int m_mode; |
2117 | 179 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
180 // Data format. |
27172 | 181 mach_info::float_format m_flt_fmt; |
2117 | 182 |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
183 // Code page |
27172 | 184 std::string m_encoding; |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
185 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
186 // TRUE if an error has occurred. |
27172 | 187 bool m_fail; |
2117 | 188 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
189 // TRUE if this stream is open. |
27172 | 190 bool m_open_state; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
191 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
192 // Should contain error message if fail is TRUE. |
27172 | 193 std::string m_errmsg; |
2117 | 194 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
195 // Functions that are defined for all input streams (input streams |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
196 // are those that define is). |
2117 | 197 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
198 std::string do_gets (octave_idx_type max_len, bool& err, bool strip_newline, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
199 const std::string& who /* = "gets" */); |
2117 | 200 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
201 std::string getl (octave_idx_type max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
202 const std::string& who /* = "getl" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
203 std::string gets (octave_idx_type max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
204 const std::string& who /* = "gets" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
205 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
2117 | 206 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
207 octave_value do_scanf (scanf_format_list& fmt_list, octave_idx_type nr, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
208 octave_idx_type nc, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
209 bool one_elt_size_spec, octave_idx_type& count, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
210 const std::string& who /* = "scanf" */); |
2117 | 211 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
212 octave_value scanf (const std::string& fmt, const Array<double>& size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
213 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2215 | 214 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
215 bool do_oscanf (const scanf_format_elt *elt, octave_value&, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
216 const std::string& who /* = "scanf" */); |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
217 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
218 octave_value_list oscanf (const std::string& fmt, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
219 const std::string& who /* = "scanf" */); |
2117 | 220 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
221 octave_value do_textscan (const std::string& fmt, octave_idx_type ntimes, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
222 const octave_value_list& options, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
223 const std::string& who, octave_idx_type& count); |
18650
491b0adfec95
compatibility fixes for printf integer format specifiers
John W. Eaton <jwe@octave.org>
parents:
17822
diff
changeset
|
224 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
225 // Functions that are defined for all output streams (output streams |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
226 // are those that define os). |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
227 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
228 int flush (void); |
2117 | 229 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
230 int do_numeric_printf_conv (std::ostream& os, const printf_format_elt *elt, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
231 int nsa, int sa_1, int sa_2, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
232 const octave_value& val, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
233 const std::string& who); |
2117 | 234 |
27781
61cc648ab034
prevent crash if dynamic printf field widths are out of range (bug #57368)
John W. Eaton <jwe@octave.org>
parents:
27735
diff
changeset
|
235 void field_width_error (const std::string& who) const; |
61cc648ab034
prevent crash if dynamic printf field widths are out of range (bug #57368)
John W. Eaton <jwe@octave.org>
parents:
27735
diff
changeset
|
236 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
237 int do_printf (printf_format_list& fmt_list, const octave_value_list& args, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
238 const std::string& who /* = "printf" */); |
2117 | 239 |
27279
1c8b20731af4
Convert encoding just before writing to stream (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
27172
diff
changeset
|
240 int printf (const std::string& fmt, const octave_value_list& args, |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
241 const std::string& who /* = "printf" */); |
2117 | 242 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
243 int puts (const std::string& s, const std::string& who /* = "puts" */); |
2117 | 244 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
245 // We can always do this in terms of seek(), so the derived class |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
246 // only has to provide that. |
2117 | 247 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
248 void invalid_operation (const std::string& who, const char *rw); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
249 }; |
2117 | 250 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
251 class |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
252 OCTINTERP_API |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
253 stream |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
254 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
255 public: |
2117 | 256 |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
257 // BS must be allocated with new or nullptr. |
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
258 stream (base_stream *bs = nullptr) : m_rep (bs) { } |
2117 | 259 |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
260 stream (const stream&) = default; |
3340 | 261 |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
262 stream& operator = (const stream&) = default; |
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
263 |
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
264 ~stream (void) = default; |
2117 | 265 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
266 int flush (void); |
2117 | 267 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
268 std::string getl (octave_idx_type max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
269 const std::string& who /* = "getl" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
270 std::string getl (const octave_value& max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
271 const std::string& who /* = "getl" */); |
2117 | 272 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
273 std::string gets (octave_idx_type max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
274 const std::string& who /* = "gets" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
275 std::string gets (const octave_value& max_len, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
276 const std::string& who /* = "gets" */); |
2117 | 277 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
278 off_t skipl (off_t count, bool& err, const std::string& who /* = "skipl" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
279 off_t skipl (const octave_value& count, bool& err, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
280 const std::string& who /* = "skipl" */); |
9701 | 281 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
282 int seek (off_t offset, int origin); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
283 int seek (const octave_value& offset, const octave_value& origin); |
2117 | 284 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
285 off_t tell (void); |
2117 | 286 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
287 int rewind (void); |
2117 | 288 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
289 bool is_open (void) const; |
3340 | 290 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
291 void close (void); |
3340 | 292 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
293 octave_value read (const Array<double>& size, octave_idx_type block_size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
294 oct_data_conv::data_type input_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
295 oct_data_conv::data_type output_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
296 octave_idx_type skip, mach_info::float_format flt_fmt, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
297 octave_idx_type& count); |
2117 | 298 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
299 octave_idx_type write (const octave_value& data, octave_idx_type block_size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
300 oct_data_conv::data_type output_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
301 octave_idx_type skip, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
302 mach_info::float_format flt_fmt); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
303 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
304 bool write_bytes (const void *data, size_t n_elts); |
17416
6690dba6078a
improve efficiency of fwrite
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
305 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
306 bool skip_bytes (size_t n_elts); |
4944 | 307 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
308 template <typename T> |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
309 octave_idx_type write (const Array<T>& data, octave_idx_type block_size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
310 oct_data_conv::data_type output_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
311 octave_idx_type skip, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
312 mach_info::float_format flt_fmt); |
2117 | 313 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
314 octave_value scanf (const std::string& fmt, const Array<double>& size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
315 octave_idx_type& count, const std::string& who /* = "scanf" */); |
2117 | 316 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
317 octave_value scanf (const octave_value& fmt, const Array<double>& size, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
318 octave_idx_type& count, const std::string& who /* = "scanf" */); |
5279 | 319 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
320 octave_value_list oscanf (const std::string& fmt, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
321 const std::string& who /* = "scanf" */); |
2215 | 322 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
323 octave_value_list oscanf (const octave_value& fmt, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
324 const std::string& who /* = "scanf" */); |
5279 | 325 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
326 octave_value textscan (const std::string& fmt, octave_idx_type ntimes, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
327 const octave_value_list& options, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
328 const std::string& who, octave_idx_type& count); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
329 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
330 int printf (const std::string& fmt, const octave_value_list& args, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
331 const std::string& who /* = "printf" */); |
21503
20bf0ec536e2
integrate textscan more completely with octave_stream class
John W. Eaton <jwe@octave.org>
parents:
21502
diff
changeset
|
332 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
333 int printf (const octave_value& fmt, const octave_value_list& args, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
334 const std::string& who /* = "printf" */); |
5279 | 335 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
336 int puts (const std::string& s, const std::string& who /* = "puts" */); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
337 int puts (const octave_value& s, const std::string& who /* = "puts" */); |
2117 | 338 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
339 bool eof (void) const; |
2117 | 340 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
341 std::string error (bool clear, int& err_num); |
2117 | 342 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
343 std::string error (bool clear = false) |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
344 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
345 int err_num; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
346 return error (clear, err_num); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
347 } |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
348 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
349 // Set the error message and state. |
2117 | 350 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
351 void error (const std::string& msg) |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
352 { |
27172 | 353 if (m_rep) |
354 m_rep->error (msg); | |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
355 } |
4799 | 356 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
357 void error (const char *msg) { error (std::string (msg)); } |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
358 |
27172 | 359 int file_number (void) { return m_rep ? m_rep->file_number () : -1; } |
4799 | 360 |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
361 bool is_valid (void) const { return bool (m_rep); } |
4799 | 362 |
27172 | 363 bool ok (void) const { return m_rep && m_rep->ok (); } |
3145 | 364 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
365 operator bool () const { return ok (); } |
3340 | 366 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
367 std::string name (void) const; |
2117 | 368 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
369 int mode (void) const; |
2117 | 370 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
371 mach_info::float_format float_format (void) const; |
2117 | 372 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
373 static std::string mode_as_string (int mode); |
26995
ab5bfee22d18
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
26703
diff
changeset
|
374 |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
375 std::string encoding (void) |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
376 { |
27172 | 377 return m_rep ? m_rep->encoding () : std::string (); |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26377
diff
changeset
|
378 } |
2117 | 379 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
380 std::istream * input_stream (void) |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
381 { |
27172 | 382 return m_rep ? m_rep->input_stream () : nullptr; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
383 } |
2117 | 384 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
385 std::ostream * output_stream (void) |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
386 { |
27172 | 387 return m_rep ? m_rep->output_stream () : nullptr; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
388 } |
2902 | 389 |
27172 | 390 void clearerr (void) { if (m_rep) m_rep->clearerr (); } |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
391 |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
392 private: |
16099
4b6c44096862
Backout changeset 238e499c5fea (locale support in scanf)
Rik <rik@octave.org>
parents:
16011
diff
changeset
|
393 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
394 // The actual representation of this stream. |
27735
8600f5ea1ec1
use std::shared_ptr to manage stream rep
John W. Eaton <jwe@octave.org>
parents:
27447
diff
changeset
|
395 std::shared_ptr<base_stream> m_rep; |
4889 | 396 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
397 bool stream_ok (bool clear = true) const |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
398 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
399 bool retval = true; |
2117 | 400 |
27172 | 401 if (m_rep) |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
402 { |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
403 if (clear) |
27172 | 404 m_rep->clear (); |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
405 } |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
406 else |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
407 retval = false; |
2117 | 408 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
409 return retval; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
410 } |
5659 | 411 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
412 void invalid_operation (const std::string& who, const char *rw) |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
413 { |
27172 | 414 if (m_rep) |
415 m_rep->invalid_operation (who, rw); | |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
416 } |
5659 | 417 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
418 octave_value |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
419 finalize_read (std::list<void *>& input_buf_list, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
420 octave_idx_type input_buf_elts, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
421 octave_idx_type elts_read, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
422 octave_idx_type nr, octave_idx_type nc, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
423 oct_data_conv::data_type input_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
424 oct_data_conv::data_type output_type, |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
425 mach_info::float_format ffmt); |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
426 }; |
4944 | 427 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
428 class |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
429 OCTINTERP_API |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
430 stream_list |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
431 { |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
432 public: |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
433 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
434 stream_list (interpreter& interp); |
2117 | 435 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
436 stream_list (const stream_list&) = delete; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
437 stream_list& operator = (const stream_list&) = delete; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
438 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
439 ~stream_list (void); |
2117 | 440 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
441 int insert (stream& os); |
2117 | 442 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
443 stream lookup (int fid, const std::string& who = "") const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
444 stream lookup (const octave_value& fid, const std::string& who = "") const; |
2117 | 445 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
446 int remove (int fid, const std::string& who = ""); |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
447 int remove (const octave_value& fid, const std::string& who = ""); |
2117 | 448 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
449 void clear (bool flush = true); |
4468 | 450 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
451 string_vector get_info (int fid) const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
452 string_vector get_info (const octave_value& fid) const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
453 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
454 std::string list_open_files (void) const; |
2117 | 455 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
456 octave_value open_file_numbers (void) const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
457 |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
458 int get_file_number (const octave_value& fid) const; |
2117 | 459 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
460 octave_value stdin_file (void) const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
461 octave_value stdout_file (void) const; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
462 octave_value stderr_file (void) const; |
2117 | 463 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
464 private: |
2117 | 465 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
466 typedef std::map<int, stream> ostrl_map; |
2117 | 467 |
27172 | 468 ostrl_map m_list; |
2117 | 469 |
27172 | 470 mutable ostrl_map::const_iterator m_lookup_cache; |
2609 | 471 |
23738
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
472 int m_stdin_file; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
473 int m_stdout_file; |
8acd390d16c9
don't use singleton for stream_list object
John W. Eaton <jwe@octave.org>
parents:
23615
diff
changeset
|
474 int m_stderr_file; |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
475 }; |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
476 } |
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
23012
diff
changeset
|
477 |
2117 | 478 #endif |