Mercurial > octave
annotate libinterp/corefcn/oct-iostrm.h @ 31707:5f11de0e7440
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Jan 2023 13:12:14 -0500 |
parents | dfa5d9c3ae72 597f3ee61a48 |
children | 21f9b34eb893 |
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 // |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
31605
diff
changeset
|
3 // Copyright (C) 1996-2023 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2081 | 25 |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 #if ! defined (octave_oct_iostrm_h) |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
27 #define octave_oct_iostrm_h 1 |
2081 | 28 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
29 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
30 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
31 #include <iosfwd> |
2877 | 32 |
2081 | 33 #include "oct-stream.h" |
34 | |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
35 OCTAVE_BEGIN_NAMESPACE(octave) |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
36 |
2081 | 37 class |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
38 base_iostream : public base_stream |
2081 | 39 { |
40 public: | |
41 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
42 base_iostream (const std::string& n = "", |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
43 std::ios::openmode m = std::ios::in | std::ios::out, |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
44 mach_info::float_format ff = mach_info::native_float_format ()) |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
45 : base_stream (m, ff), m_name (n) { } |
2081 | 46 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
47 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
48 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
49 base_iostream (const base_iostream&) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
50 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
51 base_iostream& operator = (const base_iostream&) = delete; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
52 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
53 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
54 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
55 ~base_iostream (void) = default; |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
56 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
57 public: |
2081 | 58 |
59 // Position a stream at OFFSET relative to ORIGIN. | |
60 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
61 int seek (off_t offset, int origin); |
2081 | 62 |
63 // Return current stream position. | |
64 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
65 off_t tell (void); |
2081 | 66 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
67 // Return nonzero if EOF has been reached on this stream. |
2081 | 68 |
69 bool eof (void) const; | |
70 | |
71 // The name of the file. | |
72 | |
27172 | 73 std::string name (void) const { return m_name; } |
2081 | 74 |
75 protected: | |
76 | |
77 void invalid_operation (void) const; | |
78 | |
79 private: | |
80 | |
27172 | 81 std::string m_name; |
2081 | 82 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
83 virtual const char * stream_type (void) const = 0; |
2081 | 84 }; |
85 | |
86 class | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
87 istream : public base_iostream |
2081 | 88 { |
89 public: | |
90 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
91 istream (std::istream *arg = nullptr, const std::string& n = "") |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
92 : base_iostream (n, std::ios::in, mach_info::native_float_format ()), |
27172 | 93 m_istream (arg) |
5015 | 94 { } |
2081 | 95 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
96 static stream |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
97 create (std::istream *arg = nullptr, const std::string& n = ""); |
2081 | 98 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
99 // Return nonzero if EOF has been reached on this stream. |
3342 | 100 |
101 bool eof (void) const; | |
102 | |
27172 | 103 std::istream * input_stream (void) { return m_istream; } |
2081 | 104 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
105 std::ostream * output_stream (void) { return nullptr; } |
2081 | 106 |
3340 | 107 protected: |
108 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
109 ~istream (void) = default; |
3340 | 110 |
2081 | 111 private: |
112 | |
27172 | 113 std::istream *m_istream; |
2081 | 114 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
115 const char * stream_type (void) const { return "istream"; } |
2081 | 116 |
117 // No copying! | |
118 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
119 istream (const istream&) = delete; |
2081 | 120 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
121 istream& operator = (const istream&) = delete; |
2081 | 122 }; |
123 | |
124 class | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
125 ostream : public base_iostream |
2081 | 126 { |
127 public: | |
128 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
129 ostream (std::ostream *arg, const std::string& n = "") |
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
130 : base_iostream (n, std::ios::out, mach_info::native_float_format ()), |
27172 | 131 m_ostream (arg) |
5015 | 132 { } |
2081 | 133 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
134 static stream |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
135 create (std::ostream *arg, const std::string& n = ""); |
2081 | 136 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
137 // Return nonzero if EOF has been reached on this stream. |
3342 | 138 |
139 bool eof (void) const; | |
140 | |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
141 std::istream * input_stream (void) { return nullptr; } |
2081 | 142 |
27172 | 143 std::ostream * output_stream (void) { return m_ostream; } |
2081 | 144 |
3340 | 145 protected: |
146 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
147 ~ostream (void) = default; |
3340 | 148 |
2081 | 149 private: |
150 | |
27172 | 151 std::ostream *m_ostream; |
2081 | 152 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
153 const char * stream_type (void) const { return "ostream"; } |
2081 | 154 |
155 // No copying! | |
156 | |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
157 ostream (const ostream&) = delete; |
2081 | 158 |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
159 ostream& operator = (const ostream&) = delete; |
2081 | 160 }; |
161 | |
31605
e88a07dec498
maint: Use macros to begin/end C++ namespaces.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
162 OCTAVE_END_NAMESPACE(octave) |
29991
3988112c7116
move i/o stream classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
29358
diff
changeset
|
163 |
2081 | 164 #endif |