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