Mercurial > hg > octave-nkf
annotate src/c-file-ptr-stream.cc @ 9590:b18a50c56144
More care with contour integrals in quadgk
author | David Bateman <dbateman@free.fr> |
---|---|
date | Mon, 31 Aug 2009 23:24:07 +0200 |
parents | d865363208d6 |
children | cd96d29c5efa |
rev | line source |
---|---|
3628 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 |
7017 | 4 John W. Eaton |
3628 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3628 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3628 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
28 #include <iostream> |
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
29 |
3629 | 30 #include "c-file-ptr-stream.h" |
3628 | 31 |
32 #ifndef SEEK_SET | |
33 #define SEEK_SET 0 | |
34 #endif | |
35 | |
36 #ifndef SEEK_CUR | |
37 #define SEEK_CUR 1 | |
38 #endif | |
39 | |
40 #ifndef SEEK_END | |
41 #define SEEK_END 2 | |
42 #endif | |
43 | |
3642 | 44 c_file_ptr_buf::~c_file_ptr_buf (void) |
45 { | |
3693 | 46 close (); |
3642 | 47 } |
3628 | 48 |
5775 | 49 // FIXME -- I'm sure there is room for improvement here... |
3628 | 50 |
3775 | 51 c_file_ptr_buf::int_type |
52 c_file_ptr_buf::overflow (int_type c) | |
3628 | 53 { |
3775 | 54 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
55 if (f) | |
56 return (c != traits_type::eof ()) ? fputc (c, f) : flush (); | |
57 else | |
58 return traits_type::not_eof (c); | |
59 #else | |
3644 | 60 if (f) |
3652 | 61 return (c != EOF) ? fputc (c, f) : flush (); |
3644 | 62 else |
63 return EOF; | |
3775 | 64 #endif |
3628 | 65 } |
66 | |
3775 | 67 c_file_ptr_buf::int_type |
4310 | 68 c_file_ptr_buf::underflow_common (bool bump) |
3628 | 69 { |
3644 | 70 if (f) |
4310 | 71 { |
72 int_type c = fgetc (f); | |
73 | |
74 if (! bump | |
75 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
76 && c != traits_type::eof ()) | |
77 #else | |
78 && c != EOF) | |
79 #endif | |
80 ungetc (c, f); | |
81 | |
82 return c; | |
83 } | |
3644 | 84 else |
3775 | 85 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
86 return traits_type::eof (); | |
87 #else | |
3644 | 88 return EOF; |
3775 | 89 #endif |
3628 | 90 } |
91 | |
3775 | 92 c_file_ptr_buf::int_type |
93 c_file_ptr_buf::pbackfail (int_type c) | |
3628 | 94 { |
3775 | 95 #if defined (CXX_ISO_COMPLIANT_LIBRARY) |
96 return (c != traits_type::eof () && f) ? ungetc (c, f) : | |
97 traits_type::not_eof (c); | |
98 #else | |
3644 | 99 return (c != EOF && f) ? ungetc (c, f) : EOF; |
3775 | 100 #endif |
3628 | 101 } |
102 | |
103 std::streamsize | |
104 c_file_ptr_buf::xsputn (const char* s, std::streamsize n) | |
105 { | |
3644 | 106 if (f) |
107 return fwrite (s, 1, n, f); | |
108 else | |
109 return 0; | |
3628 | 110 } |
111 | |
112 std::streamsize | |
113 c_file_ptr_buf::xsgetn (char *s, std::streamsize n) | |
114 { | |
3644 | 115 if (f) |
116 return fread (s, 1, n, f); | |
117 else | |
118 return 0; | |
3628 | 119 } |
120 | |
121 static inline int | |
122 seekdir_to_whence (std::ios::seekdir dir) | |
123 { | |
124 return ((dir == std::ios::beg) ? SEEK_SET : | |
125 (dir == std::ios::cur) ? SEEK_CUR : | |
126 (dir == std::ios::end) ? SEEK_END : | |
127 dir); | |
128 } | |
129 | |
130 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
131 c_file_ptr_buf::seekoff (std::streamoff /* offset */, |
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
132 std::ios::seekdir /* dir */, |
3628 | 133 std::ios::openmode) |
134 { | |
5775 | 135 // FIXME |
4643 | 136 #if 0 |
3644 | 137 if (f) |
138 { | |
139 fseek (f, offset, seekdir_to_whence (dir)); | |
3628 | 140 |
3644 | 141 return ftell (f); |
142 } | |
143 else | |
144 return 0; | |
4643 | 145 #endif |
146 return -1; | |
3628 | 147 } |
148 | |
149 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
150 c_file_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
3628 | 151 { |
5775 | 152 // FIXME |
4643 | 153 #if 0 |
3644 | 154 if (f) |
155 { | |
156 fseek (f, offset, SEEK_SET); | |
3628 | 157 |
3644 | 158 return ftell (f); |
159 } | |
160 else | |
161 return 0; | |
4643 | 162 #endif |
163 return -1; | |
3628 | 164 } |
165 | |
166 int | |
167 c_file_ptr_buf::sync (void) | |
168 { | |
3652 | 169 flush (); |
170 | |
3628 | 171 return 0; |
172 } | |
173 | |
3652 | 174 int |
175 c_file_ptr_buf::flush (void) | |
176 { | |
177 return f ? fflush (f) : EOF; | |
178 } | |
179 | |
180 int | |
181 c_file_ptr_buf::close (void) | |
182 { | |
3693 | 183 int retval = -1; |
184 | |
3716 | 185 flush (); |
186 | |
3652 | 187 if (f) |
3693 | 188 { |
3716 | 189 retval = cf (f); |
3693 | 190 f = 0; |
191 } | |
192 | |
193 return retval; | |
3652 | 194 } |
195 | |
5325 | 196 #ifdef HAVE_ZLIB |
197 | |
198 c_zfile_ptr_buf::~c_zfile_ptr_buf (void) | |
199 { | |
200 close (); | |
201 } | |
202 | |
5775 | 203 // FIXME -- I'm sure there is room for improvement here... |
5325 | 204 |
205 c_zfile_ptr_buf::int_type | |
206 c_zfile_ptr_buf::overflow (int_type c) | |
207 { | |
208 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
209 if (f) | |
210 return (c != traits_type::eof ()) ? gzputc (f, c) : flush (); | |
211 else | |
212 return traits_type::not_eof (c); | |
213 #else | |
214 if (f) | |
215 return (c != EOF) ? gzputc (f, c) : flush (); | |
216 else | |
217 return EOF; | |
218 #endif | |
219 } | |
220 | |
221 c_zfile_ptr_buf::int_type | |
222 c_zfile_ptr_buf::underflow_common (bool bump) | |
223 { | |
224 if (f) | |
225 { | |
226 int_type c = gzgetc (f); | |
227 | |
228 if (! bump | |
229 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
230 && c != traits_type::eof ()) | |
231 #else | |
232 && c != EOF) | |
233 #endif | |
234 gzungetc (c, f); | |
235 | |
236 return c; | |
237 } | |
238 else | |
239 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
240 return traits_type::eof (); | |
241 #else | |
242 return EOF; | |
243 #endif | |
244 } | |
245 | |
246 c_zfile_ptr_buf::int_type | |
247 c_zfile_ptr_buf::pbackfail (int_type c) | |
248 { | |
249 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
250 return (c != traits_type::eof () && f) ? gzungetc (c, f) : | |
251 traits_type::not_eof (c); | |
252 #else | |
253 return (c != EOF && f) ? gzungetc (c, f) : EOF; | |
254 #endif | |
255 } | |
256 | |
257 std::streamsize | |
258 c_zfile_ptr_buf::xsputn (const char* s, std::streamsize n) | |
259 { | |
260 if (f) | |
261 return gzwrite (f, s, n); | |
262 else | |
263 return 0; | |
264 } | |
265 | |
266 std::streamsize | |
267 c_zfile_ptr_buf::xsgetn (char *s, std::streamsize n) | |
268 { | |
269 if (f) | |
270 return gzread (f, s, n); | |
271 else | |
272 return 0; | |
273 } | |
274 | |
275 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
276 c_zfile_ptr_buf::seekoff (std::streamoff /* offset */, |
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
277 std::ios::seekdir /* dir */, |
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
278 std::ios::openmode) |
5325 | 279 { |
5775 | 280 // FIXME |
5325 | 281 #if 0 |
282 if (f) | |
283 { | |
284 gzseek (f, offset, seekdir_to_whence (dir)); | |
285 | |
286 return gztell (f); | |
287 } | |
288 else | |
289 return 0; | |
290 #endif | |
291 return -1; | |
292 } | |
293 | |
294 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
295 c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
5325 | 296 { |
5775 | 297 // FIXME |
5325 | 298 #if 0 |
299 if (f) | |
300 { | |
301 gzseek (f, offset, SEEK_SET); | |
302 | |
303 return gztell (f); | |
304 } | |
305 else | |
306 return 0; | |
307 #endif | |
308 return -1; | |
309 } | |
310 | |
311 int | |
312 c_zfile_ptr_buf::sync (void) | |
313 { | |
314 flush (); | |
315 | |
316 return 0; | |
317 } | |
318 | |
319 int | |
320 c_zfile_ptr_buf::flush (void) | |
321 { | |
5775 | 322 // FIXME -- do we need something more complex here, passing |
5325 | 323 // something other than 0 for the second argument to gzflush and |
324 // checking the return value, etc.? | |
325 | |
326 return f ? gzflush (f, 0) : EOF; | |
327 } | |
328 | |
329 int | |
330 c_zfile_ptr_buf::close (void) | |
331 { | |
332 int retval = -1; | |
333 | |
334 flush (); | |
335 | |
336 if (f) | |
337 { | |
338 retval = cf (f); | |
339 f = 0; | |
340 } | |
341 | |
342 return retval; | |
343 } | |
344 | |
345 #endif | |
346 | |
3628 | 347 /* |
348 ;;; Local Variables: *** | |
349 ;;; mode: C++ *** | |
350 ;;; End: *** | |
351 */ |