Mercurial > hg > octave-nkf
annotate src/c-file-ptr-stream.cc @ 10785:c2041adcf234
remove unnecessary sparse indexing overloads
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 13 Jul 2010 12:08:08 +0200 |
parents | bbe99b2a5ba7 |
children | fd0a3ac60b0e |
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 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
46 buf_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) | |
10411 | 56 return (c != traits_type::eof ()) ? gnulib::fputc (c, f) : flush (); |
3775 | 57 else |
58 return traits_type::not_eof (c); | |
59 #else | |
3644 | 60 if (f) |
10411 | 61 return (c != EOF) ? gnulib::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) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
76 && c != traits_type::eof ()) |
4310 | 77 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
78 && c != EOF) |
4310 | 79 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
80 ungetc (c, f); |
4310 | 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) |
10411 | 107 return gnulib::fwrite (s, 1, n, f); |
3644 | 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 : | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
125 (dir == std::ios::cur) ? SEEK_CUR : |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
126 (dir == std::ios::end) ? SEEK_END : |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
127 dir); |
3628 | 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 */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
132 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
133 std::ios::openmode) |
3628 | 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 | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
181 c_file_ptr_buf::buf_close (void) |
3652 | 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 | |
10411 | 196 int |
197 c_file_ptr_buf::file_close (FILE *f) | |
198 { | |
199 return gnulib::fclose (f); | |
200 } | |
201 | |
5325 | 202 #ifdef HAVE_ZLIB |
203 | |
204 c_zfile_ptr_buf::~c_zfile_ptr_buf (void) | |
205 { | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
206 buf_close (); |
5325 | 207 } |
208 | |
5775 | 209 // FIXME -- I'm sure there is room for improvement here... |
5325 | 210 |
211 c_zfile_ptr_buf::int_type | |
212 c_zfile_ptr_buf::overflow (int_type c) | |
213 { | |
214 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
215 if (f) | |
216 return (c != traits_type::eof ()) ? gzputc (f, c) : flush (); | |
217 else | |
218 return traits_type::not_eof (c); | |
219 #else | |
220 if (f) | |
221 return (c != EOF) ? gzputc (f, c) : flush (); | |
222 else | |
223 return EOF; | |
224 #endif | |
225 } | |
226 | |
227 c_zfile_ptr_buf::int_type | |
228 c_zfile_ptr_buf::underflow_common (bool bump) | |
229 { | |
230 if (f) | |
231 { | |
232 int_type c = gzgetc (f); | |
233 | |
234 if (! bump | |
235 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
236 && c != traits_type::eof ()) |
5325 | 237 #else |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
238 && c != EOF) |
5325 | 239 #endif |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
240 gzungetc (c, f); |
5325 | 241 |
242 return c; | |
243 } | |
244 else | |
245 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
246 return traits_type::eof (); | |
247 #else | |
248 return EOF; | |
249 #endif | |
250 } | |
251 | |
252 c_zfile_ptr_buf::int_type | |
253 c_zfile_ptr_buf::pbackfail (int_type c) | |
254 { | |
255 #if defined (CXX_ISO_COMPLIANT_LIBRARY) | |
256 return (c != traits_type::eof () && f) ? gzungetc (c, f) : | |
257 traits_type::not_eof (c); | |
258 #else | |
259 return (c != EOF && f) ? gzungetc (c, f) : EOF; | |
260 #endif | |
261 } | |
262 | |
263 std::streamsize | |
264 c_zfile_ptr_buf::xsputn (const char* s, std::streamsize n) | |
265 { | |
266 if (f) | |
267 return gzwrite (f, s, n); | |
268 else | |
269 return 0; | |
270 } | |
271 | |
272 std::streamsize | |
273 c_zfile_ptr_buf::xsgetn (char *s, std::streamsize n) | |
274 { | |
275 if (f) | |
276 return gzread (f, s, n); | |
277 else | |
278 return 0; | |
279 } | |
280 | |
281 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
282 c_zfile_ptr_buf::seekoff (std::streamoff /* offset */, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
283 std::ios::seekdir /* dir */, |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10288
diff
changeset
|
284 std::ios::openmode) |
5325 | 285 { |
5775 | 286 // FIXME |
5325 | 287 #if 0 |
288 if (f) | |
289 { | |
290 gzseek (f, offset, seekdir_to_whence (dir)); | |
291 | |
292 return gztell (f); | |
293 } | |
294 else | |
295 return 0; | |
296 #endif | |
297 return -1; | |
298 } | |
299 | |
300 std::streampos | |
8802
061780d8da1e
c-file-ptr-stream.cc: avoid unused parameter warnings
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
301 c_zfile_ptr_buf::seekpos (std::streampos /* offset */, std::ios::openmode) |
5325 | 302 { |
5775 | 303 // FIXME |
5325 | 304 #if 0 |
305 if (f) | |
306 { | |
307 gzseek (f, offset, SEEK_SET); | |
308 | |
309 return gztell (f); | |
310 } | |
311 else | |
312 return 0; | |
313 #endif | |
314 return -1; | |
315 } | |
316 | |
317 int | |
318 c_zfile_ptr_buf::sync (void) | |
319 { | |
320 flush (); | |
321 | |
322 return 0; | |
323 } | |
324 | |
325 int | |
326 c_zfile_ptr_buf::flush (void) | |
327 { | |
5775 | 328 // FIXME -- do we need something more complex here, passing |
5325 | 329 // something other than 0 for the second argument to gzflush and |
330 // checking the return value, etc.? | |
331 | |
332 return f ? gzflush (f, 0) : EOF; | |
333 } | |
334 | |
335 int | |
10288
5e972e2deffe
avoid some possible gnulib #defines
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
336 c_zfile_ptr_buf::buf_close (void) |
5325 | 337 { |
338 int retval = -1; | |
339 | |
340 flush (); | |
341 | |
342 if (f) | |
343 { | |
344 retval = cf (f); | |
345 f = 0; | |
346 } | |
347 | |
348 return retval; | |
349 } | |
350 | |
351 #endif |