Mercurial > octave
annotate libinterp/corefcn/oct-strstrm.h @ 29358:0a5b15007766 stable
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2021.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 10 Feb 2021 09:52:15 -0500 |
parents | bd51beb6205e |
children | 3988112c7116 |
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 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27923
diff
changeset
|
3 // Copyright (C) 1996-2021 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_strstrm_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_strstrm_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 |
2445 | 31 #include <string> |
5765 | 32 #include <sstream> |
4051 | 33 |
2081 | 34 #include "oct-stream.h" |
35 | |
36 class | |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
37 octave_base_strstream : public octave::base_stream |
2081 | 38 { |
39 public: | |
40 | |
4587 | 41 octave_base_strstream (std::ios::openmode m = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
42 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
43 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
44 const std::string& encoding = "utf-8") |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
45 : octave::base_stream (m, ff, encoding) { } |
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 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
49 octave_base_strstream (const octave_base_strstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
50 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
51 octave_base_strstream& operator = (const octave_base_strstream&) = delete; |
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 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
55 ~octave_base_strstream (void) = default; |
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, int); |
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 virtual off_t tell (void); |
2081 | 66 |
67 // The name of the file. | |
68 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
69 std::string name (void) const { return ""; } |
2081 | 70 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
71 virtual std::streambuf * rdbuf (void) = 0; |
2081 | 72 |
73 virtual bool bad (void) const = 0; | |
74 | |
75 virtual void clear (void) = 0; | |
76 }; | |
77 | |
78 class | |
79 octave_istrstream : public octave_base_strstream | |
80 { | |
81 public: | |
82 | |
83 octave_istrstream (const char *data, | |
10313 | 84 std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
85 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
86 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
87 const std::string& encoding = "utf-8") |
27172 | 88 : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { } |
2081 | 89 |
3523 | 90 octave_istrstream (const std::string& data, |
10313 | 91 std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
92 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
93 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
94 const std::string& encoding = "utf-8") |
27172 | 95 : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { } |
2081 | 96 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
97 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
98 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
99 octave_istrstream (const octave_istrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
100 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
101 octave_istrstream& operator = (const octave_istrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
102 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
103 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
104 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
105 ~octave_istrstream (void) = default; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
106 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
107 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
108 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
109 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
110 static octave::stream |
3538 | 111 create (const char *data, std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
112 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
113 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
114 const std::string& encoding = "utf-8"); |
3340 | 115 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
116 static octave::stream |
3538 | 117 create (const std::string& data, std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
118 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
119 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
120 const std::string& encoding = "utf-8"); |
2081 | 121 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
122 // Return nonzero if EOF has been reached on this stream. |
2081 | 123 |
27172 | 124 bool eof (void) const { return m_istream.eof (); } |
2081 | 125 |
27172 | 126 std::istream * input_stream (void) { return &m_istream; } |
2081 | 127 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
128 std::ostream * output_stream (void) { return nullptr; } |
2081 | 129 |
27172 | 130 off_t tell (void) { return m_istream.tellg (); } |
2081 | 131 |
27172 | 132 std::streambuf * rdbuf (void) |
133 { | |
134 return m_istream ? m_istream.rdbuf () : nullptr; | |
135 } | |
2081 | 136 |
27172 | 137 bool bad (void) const { return m_istream.bad (); } |
138 | |
139 void clear (void) { m_istream.clear (); } | |
2081 | 140 |
141 private: | |
142 | |
27172 | 143 std::istringstream m_istream; |
2081 | 144 }; |
145 | |
146 class | |
147 octave_ostrstream : public octave_base_strstream | |
148 { | |
149 public: | |
150 | |
3538 | 151 octave_ostrstream (std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
152 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
153 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
154 const std::string& encoding = "utf-8") |
27172 | 155 : octave_base_strstream (arg_md, ff, encoding), m_ostream () { } |
2081 | 156 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
157 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
158 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
159 octave_ostrstream (const octave_ostrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
160 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
161 octave_ostrstream& operator = (const octave_ostrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
162 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
163 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
164 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
165 ~octave_ostrstream (void) = default; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
166 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
167 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
168 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
169 static octave::stream |
3538 | 170 create (std::ios::openmode arg_md = std::ios::out, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
171 octave::mach_info::float_format ff |
26703
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
172 = octave::mach_info::native_float_format (), |
29ea2369971d
Add basic backend for encodings in file streams (bug #55452).
Markus Mützel <markus.muetzel@gmx.de>
parents:
26376
diff
changeset
|
173 const std::string& encoding = "utf-8"); |
2081 | 174 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
175 // Return nonzero if EOF has been reached on this stream. |
2081 | 176 |
27172 | 177 bool eof (void) const { return m_ostream.eof (); } |
2081 | 178 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
179 std::istream * input_stream (void) { return nullptr; } |
2081 | 180 |
27172 | 181 std::ostream * output_stream (void) { return &m_ostream; } |
2081 | 182 |
27172 | 183 std::string str (void) { return m_ostream.str (); } |
2081 | 184 |
27172 | 185 std::streambuf * rdbuf (void) |
186 { | |
187 return m_ostream ? m_ostream.rdbuf () : nullptr; | |
188 } | |
2081 | 189 |
27172 | 190 bool bad (void) const { return m_ostream.bad (); } |
2081 | 191 |
27172 | 192 void clear (void) { m_ostream.clear (); } |
2081 | 193 |
194 private: | |
195 | |
27172 | 196 std::ostringstream m_ostream; |
2081 | 197 }; |
198 | |
199 #endif |