Mercurial > octave
annotate libinterp/corefcn/c-file-ptr-stream.h @ 25444:37132909ac91
Supply missing iostream declarations via <istream> (bug #54091)
* c-file-ptr-stream.h: Replace both <iosfwd> and <streambuf> header files with
the more inclusive <istream> header file.
author | Daniel J Sebald <daniel.sebald@ieee.org> |
---|---|
date | Sat, 09 Jun 2018 20:01:38 -0500 |
parents | cb1606f78f6b |
children | 00f796120a6d |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
3 Copyright (C) 2000-2018 John W. Eaton |
3628 | 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. |
3628 | 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. |
3628 | 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/>. |
3628 | 20 |
21 */ | |
22 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
20088
diff
changeset
|
23 #if ! defined (octave_c_file_ptr_stream_h) |
3628 | 24 #define octave_c_file_ptr_stream_h 1 |
25 | |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21200
diff
changeset
|
27 |
3775 | 28 #include <cstdio> |
25444
37132909ac91
Supply missing iostream declarations via <istream> (bug #54091)
Daniel J Sebald <daniel.sebald@ieee.org>
parents:
25438
diff
changeset
|
29 #include <istream> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
30 |
3628 | 31 class |
4310 | 32 c_file_ptr_buf : public std::streambuf |
3628 | 33 { |
34 public: | |
35 | |
4310 | 36 typedef std::streambuf::int_type int_type; |
3775 | 37 |
3716 | 38 typedef int (*close_fcn) (FILE *); |
39 | |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23446
diff
changeset
|
40 FILE *stdiofile (void) { return f; } |
3628 | 41 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
42 c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = file_close) |
4310 | 43 : std::streambuf (), f (f_arg), cf (cf_arg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
44 { } |
3628 | 45 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
46 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
47 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
48 c_file_ptr_buf (const c_file_ptr_buf&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
49 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
50 c_file_ptr_buf& operator = (const c_file_ptr_buf&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
51 |
3628 | 52 ~c_file_ptr_buf (void); |
53 | |
3775 | 54 int_type overflow (int_type); |
3628 | 55 |
4310 | 56 int_type underflow (void) { return underflow_common (false); } |
3628 | 57 |
4310 | 58 int_type uflow (void) { return underflow_common (true); } |
3628 | 59 |
3775 | 60 int_type pbackfail (int_type); |
3628 | 61 |
62 std::streamsize xsputn (const char*, std::streamsize); | |
63 | |
64 std::streamsize xsgetn (char *, std::streamsize); | |
65 | |
66 std::streampos seekoff (std::streamoff, std::ios::seekdir, | |
10313 | 67 std::ios::openmode = std::ios::in | std::ios::out); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
68 |
3628 | 69 std::streampos seekpos (std::streampos, |
10313 | 70 std::ios::openmode = std::ios::in | std::ios::out); |
3628 | 71 |
72 int sync (void); | |
3644 | 73 |
3652 | 74 int flush (void); |
75 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
76 int buf_close (void); |
3652 | 77 |
4310 | 78 int file_number () const { return f ? fileno (f) : -1; } |
3775 | 79 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
80 int seek (off_t offset, int origin); |
4797 | 81 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
82 off_t tell (void); |
4797 | 83 |
4888 | 84 void clear (void) { if (f) clearerr (f); } |
85 | |
10411 | 86 static int file_close (FILE *f); |
3951 | 87 |
3644 | 88 protected: |
89 | |
90 FILE *f; | |
3716 | 91 |
92 close_fcn cf; | |
3775 | 93 |
94 private: | |
95 | |
4310 | 96 int_type underflow_common (bool); |
3628 | 97 }; |
98 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
99 // FIXME: the following three classes could probably share some code... |
5325 | 100 |
101 template <typename STREAM_T, typename FILE_T, typename BUF_T> | |
3628 | 102 class |
5325 | 103 c_file_ptr_stream : public STREAM_T |
3628 | 104 { |
3644 | 105 public: |
106 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
107 c_file_ptr_stream (FILE_T f, typename BUF_T::close_fcn cf = BUF_T::file_close) |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
108 : STREAM_T (nullptr), buf (new BUF_T (f, cf)) { STREAM_T::init (buf); } |
3644 | 109 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
110 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
111 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
112 c_file_ptr_stream (const c_file_ptr_stream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
113 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
114 c_file_ptr_stream& operator = (const c_file_ptr_stream&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
115 |
23795
980f39c3ab90
Use C++11 nullptr rather than 0 in code (bug #51565).
Rik <rik@octave.org>
parents:
23449
diff
changeset
|
116 ~c_file_ptr_stream (void) { delete buf; buf = nullptr; } |
3644 | 117 |
23446
cd4e1ee28716
maint: Use convention 'void * fcn ()' for functions which return pointers.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
118 BUF_T * rdbuf (void) { return buf; } |
3644 | 119 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
120 void stream_close (void) { if (buf) buf->buf_close (); } |
3652 | 121 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
122 int seek (off_t offset, int origin) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 { return buf ? buf->seek (offset, origin) : -1; } |
4797 | 124 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
125 off_t tell (void) { return buf ? buf->tell () : -1; } |
4797 | 126 |
5325 | 127 void clear (void) { if (buf) buf->clear (); STREAM_T::clear (); } |
4888 | 128 |
3628 | 129 private: |
130 | |
5325 | 131 BUF_T *buf; |
3628 | 132 }; |
133 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
134 typedef c_file_ptr_stream<std::istream, FILE *, c_file_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
135 i_c_file_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
136 typedef c_file_ptr_stream<std::ostream, FILE *, c_file_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
137 o_c_file_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 typedef c_file_ptr_stream<std::iostream, FILE *, c_file_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
139 io_c_file_ptr_stream; |
5325 | 140 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
141 #if defined (HAVE_ZLIB) |
5325 | 142 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
143 #if defined (HAVE_ZLIB_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21183
diff
changeset
|
144 # include <zlib.h> |
5325 | 145 #endif |
146 | |
3628 | 147 class |
5325 | 148 c_zfile_ptr_buf : public std::streambuf |
3628 | 149 { |
3644 | 150 public: |
151 | |
5325 | 152 typedef std::streambuf::int_type int_type; |
153 | |
154 typedef int (*close_fcn) (gzFile); | |
155 | |
156 gzFile stdiofile (void) { return f; } | |
157 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
158 c_zfile_ptr_buf (gzFile f_arg, close_fcn cf_arg = file_close) |
5325 | 159 : std::streambuf (), f (f_arg), cf (cf_arg) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
160 { } |
5325 | 161 |
22869
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
162 // No copying! |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
163 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
164 c_zfile_ptr_buf (const c_zfile_ptr_buf&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
165 |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
166 c_zfile_ptr_buf& operator = (const c_zfile_ptr_buf&) = delete; |
f75d289645ec
make deleted functions public
John W. Eaton <jwe@octave.org>
parents:
22865
diff
changeset
|
167 |
5325 | 168 ~c_zfile_ptr_buf (void); |
169 | |
170 int_type overflow (int_type); | |
171 | |
172 int_type underflow (void) { return underflow_common (false); } | |
3644 | 173 |
5325 | 174 int_type uflow (void) { return underflow_common (true); } |
175 | |
176 int_type pbackfail (int_type); | |
177 | |
178 std::streamsize xsputn (const char*, std::streamsize); | |
179 | |
180 std::streamsize xsgetn (char *, std::streamsize); | |
3644 | 181 |
5325 | 182 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
10313 | 183 std::ios::openmode = std::ios::in | std::ios::out); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
184 |
5325 | 185 std::streampos seekpos (std::streampos, |
10313 | 186 std::ios::openmode = std::ios::in | std::ios::out); |
3644 | 187 |
5325 | 188 int sync (void); |
189 | |
190 int flush (void); | |
191 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
192 int buf_close (void); |
5325 | 193 |
194 int file_number () const { return -1; } | |
4326 | 195 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
196 int seek (off_t offset, int origin) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
197 { return f ? gzseek (f, offset, origin) >= 0 : -1; } |
5325 | 198 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
199 off_t tell (void) { return f ? gztell (f) : -1; } |
5325 | 200 |
201 void clear (void) { if (f) gzclearerr (f); } | |
4797 | 202 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
203 static int file_close (gzFile f) { return ::gzclose (f); } |
5325 | 204 |
205 protected: | |
4797 | 206 |
5325 | 207 gzFile f; |
208 | |
209 close_fcn cf; | |
4888 | 210 |
4326 | 211 private: |
212 | |
5325 | 213 int_type underflow_common (bool); |
4326 | 214 }; |
215 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
216 typedef c_file_ptr_stream<std::istream, gzFile, c_zfile_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
217 i_c_zfile_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
218 typedef c_file_ptr_stream<std::ostream, gzFile, c_zfile_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
219 o_c_zfile_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
220 typedef c_file_ptr_stream<std::iostream, gzFile, c_zfile_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
221 io_c_zfile_ptr_stream; |
4326 | 222 |
5325 | 223 #endif |
3628 | 224 |
225 #endif |