Mercurial > octave
annotate libinterp/corefcn/oct-strstrm.h @ 27172:b0abae0bd94b
style fixes
* oct-fstrm.cc, oct-fstrm.h, oct-iostrm.cc, oct-iostrm.h,
oct-stream.cc, oct-stream.h, oct-strstrm.h, procstream.cc,
procstream.h: Use m_ prefix for member variable names and other minor
style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 11 Jun 2019 12:53:55 -0500 |
parents | 29ea2369971d |
children | b442ec6dda5c |
rev | line source |
---|---|
2081 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2081 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2081 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2081 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23795
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2081 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #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
|
24 #define octave_oct_strstrm_h 1 |
2081 | 25 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21017
diff
changeset
|
27 |
2445 | 28 #include <string> |
5765 | 29 #include <sstream> |
4051 | 30 |
2081 | 31 #include "oct-stream.h" |
32 | |
33 class | |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
34 octave_base_strstream : public octave::base_stream |
2081 | 35 { |
36 public: | |
37 | |
4587 | 38 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
|
39 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
|
40 = 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
|
41 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
|
42 : octave::base_stream (m, ff, encoding) { } |
2081 | 43 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
44 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
45 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
46 octave_base_strstream (const octave_base_strstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
47 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
48 octave_base_strstream& operator = (const octave_base_strstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
49 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
50 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
51 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
52 ~octave_base_strstream (void) = default; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
53 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
54 public: |
2081 | 55 |
56 // Position a stream at OFFSET relative to ORIGIN. | |
57 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
58 int seek (off_t, int); |
2081 | 59 |
60 // Return current stream position. | |
61 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
62 virtual off_t tell (void); |
2081 | 63 |
64 // The name of the file. | |
65 | |
21017
93748bcaec17
maint: Replace emtpy 'std::string ()' calls with "".
Rik <rik@octave.org>
parents:
20791
diff
changeset
|
66 std::string name (void) const { return ""; } |
2081 | 67 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
68 virtual std::streambuf * rdbuf (void) = 0; |
2081 | 69 |
70 virtual bool bad (void) const = 0; | |
71 | |
72 virtual void clear (void) = 0; | |
73 }; | |
74 | |
75 class | |
76 octave_istrstream : public octave_base_strstream | |
77 { | |
78 public: | |
79 | |
80 octave_istrstream (const char *data, | |
10313 | 81 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
|
82 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
|
83 = 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
|
84 const std::string& encoding = "utf-8") |
27172 | 85 : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { } |
2081 | 86 |
3523 | 87 octave_istrstream (const std::string& data, |
10313 | 88 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
|
89 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
|
90 = 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
|
91 const std::string& encoding = "utf-8") |
27172 | 92 : octave_base_strstream (arg_md, ff, encoding), m_istream (data) { } |
2081 | 93 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
94 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
95 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
96 octave_istrstream (const octave_istrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
97 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
98 octave_istrstream& operator = (const octave_istrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
99 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
100 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
101 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
102 ~octave_istrstream (void) = default; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
103 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
104 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
105 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
106 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
107 static octave::stream |
3538 | 108 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
|
109 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
|
110 = 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
|
111 const std::string& encoding = "utf-8"); |
3340 | 112 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
113 static octave::stream |
3538 | 114 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
|
115 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
|
116 = 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
|
117 const std::string& encoding = "utf-8"); |
2081 | 118 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
119 // Return nonzero if EOF has been reached on this stream. |
2081 | 120 |
27172 | 121 bool eof (void) const { return m_istream.eof (); } |
2081 | 122 |
27172 | 123 std::istream * input_stream (void) { return &m_istream; } |
2081 | 124 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
125 std::ostream * output_stream (void) { return nullptr; } |
2081 | 126 |
27172 | 127 off_t tell (void) { return m_istream.tellg (); } |
2081 | 128 |
27172 | 129 std::streambuf * rdbuf (void) |
130 { | |
131 return m_istream ? m_istream.rdbuf () : nullptr; | |
132 } | |
2081 | 133 |
27172 | 134 bool bad (void) const { return m_istream.bad (); } |
135 | |
136 void clear (void) { m_istream.clear (); } | |
2081 | 137 |
138 private: | |
139 | |
27172 | 140 std::istringstream m_istream; |
2081 | 141 }; |
142 | |
143 class | |
144 octave_ostrstream : public octave_base_strstream | |
145 { | |
146 public: | |
147 | |
3538 | 148 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
|
149 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
|
150 = 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
|
151 const std::string& encoding = "utf-8") |
27172 | 152 : octave_base_strstream (arg_md, ff, encoding), m_ostream () { } |
2081 | 153 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
154 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
155 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
156 octave_ostrstream (const octave_ostrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
157 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
158 octave_ostrstream& operator = (const octave_ostrstream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
159 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
160 protected: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
161 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
162 ~octave_ostrstream (void) = default; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
163 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
164 public: |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22868
diff
changeset
|
165 |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22869
diff
changeset
|
166 static octave::stream |
3538 | 167 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
|
168 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
|
169 = 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
|
170 const std::string& encoding = "utf-8"); |
2081 | 171 |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17822
diff
changeset
|
172 // Return nonzero if EOF has been reached on this stream. |
2081 | 173 |
27172 | 174 bool eof (void) const { return m_ostream.eof (); } |
2081 | 175 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
176 std::istream * input_stream (void) { return nullptr; } |
2081 | 177 |
27172 | 178 std::ostream * output_stream (void) { return &m_ostream; } |
2081 | 179 |
27172 | 180 std::string str (void) { return m_ostream.str (); } |
2081 | 181 |
27172 | 182 std::streambuf * rdbuf (void) |
183 { | |
184 return m_ostream ? m_ostream.rdbuf () : nullptr; | |
185 } | |
2081 | 186 |
27172 | 187 bool bad (void) const { return m_ostream.bad (); } |
2081 | 188 |
27172 | 189 void clear (void) { m_ostream.clear (); } |
2081 | 190 |
191 private: | |
192 | |
27172 | 193 std::ostringstream m_ostream; |
2081 | 194 }; |
195 | |
196 #endif |