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