Mercurial > hg > octave-nkf
annotate libinterp/corefcn/c-file-ptr-stream.h @ 18189:d638db6d045c stable
doc: Note that dbstop can be used with class methods as well (bug #40958).
* debug.txi: Note that dbstop can be used with class methods as well
(bug #40958).
author | Rik <rik@octave.org> |
---|---|
date | Wed, 01 Jan 2014 18:24:55 -0800 |
parents | 175b392e91fe |
children | 4197fc428c7d |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16892
diff
changeset
|
3 Copyright (C) 2000-2013 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 | |
23 #if !defined (octave_c_file_ptr_stream_h) | |
24 #define octave_c_file_ptr_stream_h 1 | |
25 | |
3775 | 26 #include <cstdio> |
3628 | 27 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
28 #include <iosfwd> |
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 | |
3775 | 35 #if !defined (CXX_ISO_COMPLIANT_LIBRARY) |
36 typedef int int_type; | |
3944 | 37 #else |
4310 | 38 typedef std::streambuf::int_type int_type; |
3775 | 39 #endif |
40 | |
3716 | 41 typedef int (*close_fcn) (FILE *); |
42 | |
4797 | 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 |
49 ~c_file_ptr_buf (void); | |
50 | |
3775 | 51 int_type overflow (int_type); |
3628 | 52 |
4310 | 53 int_type underflow (void) { return underflow_common (false); } |
3628 | 54 |
4310 | 55 int_type uflow (void) { return underflow_common (true); } |
3628 | 56 |
3775 | 57 int_type pbackfail (int_type); |
3628 | 58 |
59 std::streamsize xsputn (const char*, std::streamsize); | |
60 | |
61 std::streamsize xsgetn (char *, std::streamsize); | |
62 | |
63 std::streampos seekoff (std::streamoff, std::ios::seekdir, | |
10313 | 64 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
|
65 |
3628 | 66 std::streampos seekpos (std::streampos, |
10313 | 67 std::ios::openmode = std::ios::in | std::ios::out); |
3628 | 68 |
69 int sync (void); | |
3644 | 70 |
3652 | 71 int flush (void); |
72 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
73 int buf_close (void); |
3652 | 74 |
4310 | 75 int file_number () const { return f ? fileno (f) : -1; } |
3775 | 76 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
77 int seek (off_t offset, int origin); |
4797 | 78 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
79 off_t tell (void); |
4797 | 80 |
4888 | 81 void clear (void) { if (f) clearerr (f); } |
82 | |
10411 | 83 static int file_close (FILE *f); |
3951 | 84 |
3644 | 85 protected: |
86 | |
87 FILE *f; | |
3716 | 88 |
89 close_fcn cf; | |
3775 | 90 |
91 private: | |
92 | |
4310 | 93 int_type underflow_common (bool); |
12122
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 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
96 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
97 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
|
98 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
99 c_file_ptr_buf& operator = (const c_file_ptr_buf&); |
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) |
5884 | 111 : STREAM_T (0), buf (new BUF_T (f, cf)) { STREAM_T::init (buf); } |
3644 | 112 |
5325 | 113 ~c_file_ptr_stream (void) { delete buf; buf = 0; } |
3644 | 114 |
5325 | 115 BUF_T *rdbuf (void) { return buf; } |
3644 | 116 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
117 void stream_close (void) { if (buf) buf->buf_close (); } |
3652 | 118 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
119 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
|
120 { return buf ? buf->seek (offset, origin) : -1; } |
4797 | 121 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
122 off_t tell (void) { return buf ? buf->tell () : -1; } |
4797 | 123 |
5325 | 124 void clear (void) { if (buf) buf->clear (); STREAM_T::clear (); } |
4888 | 125 |
3628 | 126 private: |
127 | |
5325 | 128 BUF_T *buf; |
12122
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 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
131 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
132 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
|
133 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
134 c_file_ptr_stream& operator = (const c_file_ptr_stream&); |
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 |
144 #ifdef HAVE_ZLIB | |
145 | |
146 #ifdef HAVE_ZLIB_H | |
147 #include <zlib.h> | |
148 #endif | |
149 | |
3628 | 150 class |
5325 | 151 c_zfile_ptr_buf : public std::streambuf |
3628 | 152 { |
3644 | 153 public: |
154 | |
5325 | 155 #if !defined (CXX_ISO_COMPLIANT_LIBRARY) |
156 typedef int int_type; | |
157 #else | |
158 typedef std::streambuf::int_type int_type; | |
159 #endif | |
160 | |
161 typedef int (*close_fcn) (gzFile); | |
162 | |
163 gzFile stdiofile (void) { return f; } | |
164 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
165 c_zfile_ptr_buf (gzFile f_arg, close_fcn cf_arg = file_close) |
5325 | 166 : 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
|
167 { } |
5325 | 168 |
169 ~c_zfile_ptr_buf (void); | |
170 | |
171 int_type overflow (int_type); | |
172 | |
173 int_type underflow (void) { return underflow_common (false); } | |
3644 | 174 |
5325 | 175 int_type uflow (void) { return underflow_common (true); } |
176 | |
177 int_type pbackfail (int_type); | |
178 | |
179 std::streamsize xsputn (const char*, std::streamsize); | |
180 | |
181 std::streamsize xsgetn (char *, std::streamsize); | |
3644 | 182 |
5325 | 183 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
10313 | 184 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
|
185 |
5325 | 186 std::streampos seekpos (std::streampos, |
10313 | 187 std::ios::openmode = std::ios::in | std::ios::out); |
3644 | 188 |
5325 | 189 int sync (void); |
190 | |
191 int flush (void); | |
192 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
193 int buf_close (void); |
5325 | 194 |
195 int file_number () const { return -1; } | |
4326 | 196 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
197 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
|
198 { return f ? gzseek (f, offset, origin) >= 0 : -1; } |
5325 | 199 |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
200 off_t tell (void) { return f ? gztell (f) : -1; } |
5325 | 201 |
202 void clear (void) { if (f) gzclearerr (f); } | |
4797 | 203 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
204 static int file_close (gzFile f) { return ::gzclose (f); } |
5325 | 205 |
206 protected: | |
4797 | 207 |
5325 | 208 gzFile f; |
209 | |
210 close_fcn cf; | |
4888 | 211 |
4326 | 212 private: |
213 | |
5325 | 214 int_type underflow_common (bool); |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
215 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
216 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
217 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
218 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
|
219 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
220 c_zfile_ptr_buf& operator = (const c_zfile_ptr_buf&); |
4326 | 221 }; |
222 | |
17787
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::istream, gzFile, c_zfile_ptr_buf> |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
224 i_c_zfile_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
225 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
|
226 o_c_zfile_ptr_stream; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
227 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
|
228 io_c_zfile_ptr_stream; |
4326 | 229 |
5325 | 230 #endif |
3628 | 231 |
232 #endif |