Mercurial > octave
annotate libinterp/corefcn/c-file-ptr-stream.h @ 21183:e7fda94aec6b
eliminate OCTAVE_CXX_ISO_COMPLIANT_LIBRARY macro
* m4/acinclude.m4 (OCTAVE_CXX_ISO_COMPLIANT_LIBRARY):
Delete macro definition.
* configure.ac: Don't use it.
* c-file-ptr-stream.h, c-file-ptr-stream.cc, oct-fstrm.cc:
Always assume CXX_ISO_COMPLIANT_LIBRARY is true.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 03 Feb 2016 16:50:38 -0500 |
parents | f7084eae3318 |
children | fcac5dbbf9ed |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 2000-2015 John W. Eaton |
3628 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
3628 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
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 |
19 <http://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 | |
3775 | 26 #include <cstdio> |
3628 | 27 |
20088
1663b82bd009
Stop "implicit instantiation of undefined template" error (bug #44818).
Mike Miller <mtmiller@octave.org>
parents:
19697
diff
changeset
|
28 #include <streambuf> |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
29 |
3628 | 30 class |
4310 | 31 c_file_ptr_buf : public std::streambuf |
3628 | 32 { |
33 public: | |
34 | |
4310 | 35 typedef std::streambuf::int_type int_type; |
3775 | 36 |
3716 | 37 typedef int (*close_fcn) (FILE *); |
38 | |
4797 | 39 FILE* stdiofile (void) { return f; } |
3628 | 40 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
41 c_file_ptr_buf (FILE *f_arg, close_fcn cf_arg = file_close) |
4310 | 42 : 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
|
43 { } |
3628 | 44 |
45 ~c_file_ptr_buf (void); | |
46 | |
3775 | 47 int_type overflow (int_type); |
3628 | 48 |
4310 | 49 int_type underflow (void) { return underflow_common (false); } |
3628 | 50 |
4310 | 51 int_type uflow (void) { return underflow_common (true); } |
3628 | 52 |
3775 | 53 int_type pbackfail (int_type); |
3628 | 54 |
55 std::streamsize xsputn (const char*, std::streamsize); | |
56 | |
57 std::streamsize xsgetn (char *, std::streamsize); | |
58 | |
59 std::streampos seekoff (std::streamoff, std::ios::seekdir, | |
10313 | 60 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
|
61 |
3628 | 62 std::streampos seekpos (std::streampos, |
10313 | 63 std::ios::openmode = std::ios::in | std::ios::out); |
3628 | 64 |
65 int sync (void); | |
3644 | 66 |
3652 | 67 int flush (void); |
68 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
69 int buf_close (void); |
3652 | 70 |
4310 | 71 int file_number () const { return f ? fileno (f) : -1; } |
3775 | 72 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
73 int seek (off_t offset, int origin); |
4797 | 74 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
75 off_t tell (void); |
4797 | 76 |
4888 | 77 void clear (void) { if (f) clearerr (f); } |
78 | |
10411 | 79 static int file_close (FILE *f); |
3951 | 80 |
3644 | 81 protected: |
82 | |
83 FILE *f; | |
3716 | 84 |
85 close_fcn cf; | |
3775 | 86 |
87 private: | |
88 | |
4310 | 89 int_type underflow_common (bool); |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
90 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
91 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
92 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
93 c_file_ptr_buf (const c_file_ptr_buf&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
94 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
95 c_file_ptr_buf& operator = (const c_file_ptr_buf&); |
3628 | 96 }; |
97 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
98 // FIXME: the following three classes could probably share some code... |
5325 | 99 |
100 template <typename STREAM_T, typename FILE_T, typename BUF_T> | |
3628 | 101 class |
5325 | 102 c_file_ptr_stream : public STREAM_T |
3628 | 103 { |
3644 | 104 public: |
105 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
106 c_file_ptr_stream (FILE_T f, typename BUF_T::close_fcn cf = BUF_T::file_close) |
5884 | 107 : STREAM_T (0), buf (new BUF_T (f, cf)) { STREAM_T::init (buf); } |
3644 | 108 |
5325 | 109 ~c_file_ptr_stream (void) { delete buf; buf = 0; } |
3644 | 110 |
5325 | 111 BUF_T *rdbuf (void) { return buf; } |
3644 | 112 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
113 void stream_close (void) { if (buf) buf->buf_close (); } |
3652 | 114 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
115 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
|
116 { return buf ? buf->seek (offset, origin) : -1; } |
4797 | 117 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
118 off_t tell (void) { return buf ? buf->tell () : -1; } |
4797 | 119 |
5325 | 120 void clear (void) { if (buf) buf->clear (); STREAM_T::clear (); } |
4888 | 121 |
3628 | 122 private: |
123 | |
5325 | 124 BUF_T *buf; |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
125 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
126 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
127 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
128 c_file_ptr_stream (const c_file_ptr_stream&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
129 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
130 c_file_ptr_stream& operator = (const c_file_ptr_stream&); |
3628 | 131 }; |
132 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 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
|
134 i_c_file_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
135 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
|
136 o_c_file_ptr_stream; |
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::iostream, FILE *, c_file_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
138 io_c_file_ptr_stream; |
5325 | 139 |
140 #ifdef HAVE_ZLIB | |
141 | |
142 #ifdef HAVE_ZLIB_H | |
143 #include <zlib.h> | |
144 #endif | |
145 | |
3628 | 146 class |
5325 | 147 c_zfile_ptr_buf : public std::streambuf |
3628 | 148 { |
3644 | 149 public: |
150 | |
5325 | 151 typedef std::streambuf::int_type int_type; |
152 | |
153 typedef int (*close_fcn) (gzFile); | |
154 | |
155 gzFile stdiofile (void) { return f; } | |
156 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
157 c_zfile_ptr_buf (gzFile f_arg, close_fcn cf_arg = file_close) |
5325 | 158 : 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
|
159 { } |
5325 | 160 |
161 ~c_zfile_ptr_buf (void); | |
162 | |
163 int_type overflow (int_type); | |
164 | |
165 int_type underflow (void) { return underflow_common (false); } | |
3644 | 166 |
5325 | 167 int_type uflow (void) { return underflow_common (true); } |
168 | |
169 int_type pbackfail (int_type); | |
170 | |
171 std::streamsize xsputn (const char*, std::streamsize); | |
172 | |
173 std::streamsize xsgetn (char *, std::streamsize); | |
3644 | 174 |
5325 | 175 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
10313 | 176 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
|
177 |
5325 | 178 std::streampos seekpos (std::streampos, |
10313 | 179 std::ios::openmode = std::ios::in | std::ios::out); |
3644 | 180 |
5325 | 181 int sync (void); |
182 | |
183 int flush (void); | |
184 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
185 int buf_close (void); |
5325 | 186 |
187 int file_number () const { return -1; } | |
4326 | 188 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
189 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
|
190 { return f ? gzseek (f, offset, origin) >= 0 : -1; } |
5325 | 191 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
192 off_t tell (void) { return f ? gztell (f) : -1; } |
5325 | 193 |
194 void clear (void) { if (f) gzclearerr (f); } | |
4797 | 195 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
196 static int file_close (gzFile f) { return ::gzclose (f); } |
5325 | 197 |
198 protected: | |
4797 | 199 |
5325 | 200 gzFile f; |
201 | |
202 close_fcn cf; | |
4888 | 203 |
4326 | 204 private: |
205 | |
5325 | 206 int_type underflow_common (bool); |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
207 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
208 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
209 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
210 c_zfile_ptr_buf (const c_zfile_ptr_buf&); |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
211 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
212 c_zfile_ptr_buf& operator = (const c_zfile_ptr_buf&); |
4326 | 213 }; |
214 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
215 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
|
216 i_c_zfile_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
217 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
|
218 o_c_zfile_ptr_stream; |
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::iostream, gzFile, c_zfile_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
220 io_c_zfile_ptr_stream; |
4326 | 221 |
5325 | 222 #endif |
3628 | 223 |
224 #endif |