Mercurial > hg > octave-lyh
annotate src/c-file-ptr-stream.h @ 14553:aacb604ca2b6
Clean generated fortran files.
* libcruft/Makefile.am (nodist_libcruft_la_SOURCES): New variable.
(DISTCLEANFILES): Include $(nodist_libcruft_la_SOURCES) in the list.
* libcruft/slatec-fn/module.mk (nodist_libcruft_la_SOURCES):
Append derfc.f and erfc.f here.
(libcruft_la_SOURCES): Not here.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Wed, 11 Apr 2012 23:12:43 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12927
diff
changeset
|
3 Copyright (C) 2000-2012 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) |
3775 | 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 |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
77 int seek (long offset, int origin); |
4797 | 78 |
12927
f9c1f7c1ead0
maint: undo part of previous gnulib changes
John W. Eaton <jwe@octave.org>
parents:
12918
diff
changeset
|
79 long 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 | |
5775 | 102 // FIXME -- the following three classes could probably share |
5325 | 103 // some code... |
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) |
5884 | 112 : STREAM_T (0), buf (new BUF_T (f, cf)) { STREAM_T::init (buf); } |
3644 | 113 |
5325 | 114 ~c_file_ptr_stream (void) { delete buf; buf = 0; } |
3644 | 115 |
5325 | 116 BUF_T *rdbuf (void) { return buf; } |
3644 | 117 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
118 void stream_close (void) { if (buf) buf->buf_close (); } |
3652 | 119 |
4797 | 120 int seek (long offset, int origin) |
121 { return buf ? buf->seek (offset, origin) : -1; } | |
122 | |
123 long tell (void) { return buf ? buf->tell () : -1; } | |
124 | |
5325 | 125 void clear (void) { if (buf) buf->clear (); STREAM_T::clear (); } |
4888 | 126 |
3628 | 127 private: |
128 | |
5325 | 129 BUF_T *buf; |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
130 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
131 // No copying! |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
132 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
133 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
|
134 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
135 c_file_ptr_stream& operator = (const c_file_ptr_stream&); |
3628 | 136 }; |
137 | |
5325 | 138 typedef c_file_ptr_stream<std::istream, FILE *, c_file_ptr_buf> i_c_file_ptr_stream; |
139 typedef c_file_ptr_stream<std::ostream, FILE *, c_file_ptr_buf> o_c_file_ptr_stream; | |
140 typedef c_file_ptr_stream<std::iostream, FILE *, c_file_ptr_buf> io_c_file_ptr_stream; | |
141 | |
142 #ifdef HAVE_ZLIB | |
143 | |
144 #ifdef HAVE_ZLIB_H | |
145 #include <zlib.h> | |
146 #endif | |
147 | |
3628 | 148 class |
5325 | 149 c_zfile_ptr_buf : public std::streambuf |
3628 | 150 { |
3644 | 151 public: |
152 | |
5325 | 153 #if !defined (CXX_ISO_COMPLIANT_LIBRARY) |
154 typedef int int_type; | |
155 #else | |
156 typedef std::streambuf::int_type int_type; | |
157 #endif | |
158 | |
159 typedef int (*close_fcn) (gzFile); | |
160 | |
161 gzFile stdiofile (void) { return f; } | |
162 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
163 c_zfile_ptr_buf (gzFile f_arg, close_fcn cf_arg = file_close) |
5325 | 164 : std::streambuf (), f (f_arg), cf (cf_arg) |
165 { } | |
166 | |
167 ~c_zfile_ptr_buf (void); | |
168 | |
169 int_type overflow (int_type); | |
170 | |
171 int_type underflow (void) { return underflow_common (false); } | |
3644 | 172 |
5325 | 173 int_type uflow (void) { return underflow_common (true); } |
174 | |
175 int_type pbackfail (int_type); | |
176 | |
177 std::streamsize xsputn (const char*, std::streamsize); | |
178 | |
179 std::streamsize xsgetn (char *, std::streamsize); | |
3644 | 180 |
5325 | 181 std::streampos seekoff (std::streamoff, std::ios::seekdir, |
10313 | 182 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
|
183 |
5325 | 184 std::streampos seekpos (std::streampos, |
10313 | 185 std::ios::openmode = std::ios::in | std::ios::out); |
3644 | 186 |
5325 | 187 int sync (void); |
188 | |
189 int flush (void); | |
190 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
191 int buf_close (void); |
5325 | 192 |
193 int file_number () const { return -1; } | |
4326 | 194 |
4797 | 195 int seek (long offset, int origin) |
5325 | 196 { return f ? gzseek (f, offset, origin) : -1; } |
197 | |
198 long tell (void) { return f ? gztell (f) : -1; } | |
199 | |
200 void clear (void) { if (f) gzclearerr (f); } | |
4797 | 201 |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
202 static int file_close (gzFile f) { return ::gzclose (f); } |
5325 | 203 |
204 protected: | |
4797 | 205 |
5325 | 206 gzFile f; |
207 | |
208 close_fcn cf; | |
4888 | 209 |
4326 | 210 private: |
211 | |
5325 | 212 int_type underflow_common (bool); |
12122
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
213 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
214 // No copying! |
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 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
|
217 |
f4689107dd8c
Explicitly disallow copying in some classes.
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
218 c_zfile_ptr_buf& operator = (const c_zfile_ptr_buf&); |
4326 | 219 }; |
220 | |
5325 | 221 typedef c_file_ptr_stream<std::istream, gzFile, c_zfile_ptr_buf> i_c_zfile_ptr_stream; |
222 typedef c_file_ptr_stream<std::ostream, gzFile, c_zfile_ptr_buf> o_c_zfile_ptr_stream; | |
223 typedef c_file_ptr_stream<std::iostream, gzFile, c_zfile_ptr_buf> io_c_zfile_ptr_stream; | |
4326 | 224 |
5325 | 225 #endif |
3628 | 226 |
227 #endif |