Mercurial > hg > octave-nkf
annotate src/zfstream.cc @ 14861:f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
* bitfcns.cc, comment-list.cc, data.cc, defun.cc, error.cc, gl-render.cc,
graphics.cc, graphics.in.h, load-path.cc, load-path.h, load-save.cc,
ls-hdf5.cc, ls-mat4.cc, ls-mat5.cc, ls-oct-ascii.cc, mappers.cc, mex.cc,
oct-map.cc, oct-obj.cc, ov-base-int.cc, ov-base-mat.h, ov-base-sparse.cc,
ov-bool-mat.cc, ov-bool-sparse.cc, ov-cell.cc, ov-class.cc, ov-complex.cc,
ov-cx-mat.cc, ov-cx-sparse.cc, ov-fcn-handle.cc, ov-flt-cx-mat.cc,
ov-flt-re-mat.cc, ov-re-mat.cc, ov-re-sparse.cc, ov-scalar.cc, ov-str-mat.cc,
ov-struct.cc, ov-usr-fcn.cc, ov.cc, pr-output.cc, procstream.h, sighandlers.cc,
sparse-xdiv.cc, sparse-xpow.cc, sparse.cc, symtab.cc, syscalls.cc, sysdep.cc,
txt-eng-ft.cc, variables.cc, zfstream.cc, zfstream.h: Use Octave coding
conventions for cuddling parentheses.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 14 Jul 2012 06:22:56 -0700 |
parents | 460a3c6d8bf1 |
children | 560317fd5977 |
rev | line source |
---|---|
5269 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 2005-2012 Ludwig Schwardt, Kevin Ruland |
5269 | 4 |
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. | |
5269 | 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/>. | |
5269 | 21 |
22 */ | |
23 | |
24 /* | |
25 | |
26 This file is adapted from the zlib 1.2.2 contrib/iostream3 code, | |
27 written by | |
28 | |
29 Ludwig Schwardt <schwardt@sun.ac.za> | |
30 original version by Kevin Ruland <kevin@rodin.wustl.edu> | |
31 | |
32 */ | |
33 | |
8025
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
34 #ifdef HAVE_CONFIG_H |
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
35 #include <config.h> |
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
36 #endif |
60e938e1459b
zfstream.cc: include <config.h>
John W. Eaton <jwe@octave.org>
parents:
7520
diff
changeset
|
37 |
8950
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
38 #include <iostream> |
d865363208d6
include <iosfwd> instead of <iostream> in header files
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
39 |
5269 | 40 #include "zfstream.h" |
41 | |
42 #ifdef HAVE_ZLIB | |
43 | |
44 #include <cstring> // for strcpy, strcat, strlen (mode strings) | |
45 #include <cstdio> // for BUFSIZ | |
46 | |
47 // Internal buffer sizes (default and "unbuffered" versions) | |
6783 | 48 #define STASHED_CHARACTERS 16 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
49 #define BIGBUFSIZE (256 * 1024 + STASHED_CHARACTERS) |
5269 | 50 #define SMALLBUFSIZE 1 |
51 | |
52 /*****************************************************************************/ | |
53 | |
54 // Default constructor | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 gzfilebuf::gzfilebuf () |
7520 | 56 : file(0), io_mode(std::ios_base::openmode(0)), own_fd(false), |
57 buffer(0), buffer_size(BIGBUFSIZE), own_buffer(true) | |
5269 | 58 { |
59 // No buffers to start with | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
60 this->disable_buffer (); |
5269 | 61 } |
62 | |
63 // Destructor | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
64 gzfilebuf::~gzfilebuf () |
5269 | 65 { |
66 // Sync output buffer and close only if responsible for file | |
67 // (i.e. attached streams should be left open at this stage) | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
68 this->sync (); |
5269 | 69 if (own_fd) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
70 this->close (); |
5269 | 71 // Make sure internal buffer is deallocated |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
72 this->disable_buffer (); |
5269 | 73 } |
74 | |
75 // Set compression level and strategy | |
76 int | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
77 gzfilebuf::setcompression (int comp_level, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
78 int comp_strategy) |
5269 | 79 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
80 return gzsetparams (file, comp_level, comp_strategy); |
5269 | 81 } |
82 | |
83 // Open gzipped file | |
84 gzfilebuf* | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
85 gzfilebuf::open (const char *name, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
86 std::ios_base::openmode mode) |
5269 | 87 { |
88 // Fail if file already open | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
89 if (this->is_open ()) |
7520 | 90 return 0; |
5269 | 91 // Don't support simultaneous read/write access (yet) |
92 if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) | |
7520 | 93 return 0; |
5269 | 94 |
95 // Build mode string for gzopen and check it [27.8.1.3.2] | |
96 char char_mode[6] = "\0\0\0\0\0"; | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
97 if (! this->open_mode (mode, char_mode)) |
7520 | 98 return 0; |
5269 | 99 |
100 // Attempt to open file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
101 if ((file = gzopen (name, char_mode)) == 0) |
7520 | 102 return 0; |
5269 | 103 |
104 // On success, allocate internal buffer and set flags | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
105 this->enable_buffer (); |
5269 | 106 io_mode = mode; |
107 own_fd = true; | |
108 return this; | |
109 } | |
110 | |
111 // Attach to gzipped file | |
112 gzfilebuf* | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
113 gzfilebuf::attach (int fd, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
114 std::ios_base::openmode mode) |
5269 | 115 { |
116 // Fail if file already open | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
117 if (this->is_open ()) |
7520 | 118 return 0; |
5269 | 119 // Don't support simultaneous read/write access (yet) |
120 if ((mode & std::ios_base::in) && (mode & std::ios_base::out)) | |
7520 | 121 return 0; |
5269 | 122 |
123 // Build mode string for gzdopen and check it [27.8.1.3.2] | |
124 char char_mode[6] = "\0\0\0\0\0"; | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
125 if (! this->open_mode (mode, char_mode)) |
7520 | 126 return 0; |
5269 | 127 |
128 // Attempt to attach to file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
129 if ((file = gzdopen (fd, char_mode)) == 0) |
7520 | 130 return 0; |
5269 | 131 |
132 // On success, allocate internal buffer and set flags | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
133 this->enable_buffer (); |
5269 | 134 io_mode = mode; |
135 own_fd = false; | |
136 return this; | |
137 } | |
138 | |
139 // Close gzipped file | |
140 gzfilebuf* | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
141 gzfilebuf::close () |
5269 | 142 { |
143 // Fail immediately if no file is open | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
144 if (! this->is_open ()) |
7520 | 145 return 0; |
5269 | 146 // Assume success |
147 gzfilebuf* retval = this; | |
148 // Attempt to sync and close gzipped file | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
149 if (this->sync () == -1) |
7520 | 150 retval = 0; |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
151 if (gzclose (file) < 0) |
7520 | 152 retval = 0; |
5269 | 153 // File is now gone anyway (postcondition [27.8.1.3.8]) |
7520 | 154 file = 0; |
5269 | 155 own_fd = false; |
156 // Destroy internal buffer if it exists | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
157 this->disable_buffer (); |
5269 | 158 return retval; |
159 } | |
160 | |
161 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
162 | |
163 // Convert int open mode to mode string | |
164 bool | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
165 gzfilebuf::open_mode (std::ios_base::openmode mode, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
166 char* c_mode) const |
5269 | 167 { |
6959 | 168 // FIXME -- do we need testb? |
169 // bool testb = mode & std::ios_base::binary; | |
5269 | 170 bool testi = mode & std::ios_base::in; |
171 bool testo = mode & std::ios_base::out; | |
172 bool testt = mode & std::ios_base::trunc; | |
173 bool testa = mode & std::ios_base::app; | |
174 | |
175 // Check for valid flag combinations - see [27.8.1.3.2] (Table 92) | |
176 // Original zfstream hardcoded the compression level to maximum here... | |
177 // Double the time for less than 1% size improvement seems | |
178 // excessive though - keeping it at the default level | |
179 // To change back, just append "9" to the next three mode strings | |
180 if (!testi && testo && !testt && !testa) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
181 strcpy (c_mode, "w"); |
5269 | 182 if (!testi && testo && !testt && testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
183 strcpy (c_mode, "a"); |
5269 | 184 if (!testi && testo && testt && !testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
185 strcpy (c_mode, "w"); |
5269 | 186 if (testi && !testo && !testt && !testa) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
187 strcpy (c_mode, "r"); |
5269 | 188 // No read/write mode yet |
189 // if (testi && testo && !testt && !testa) | |
190 // strcpy(c_mode, "r+"); | |
191 // if (testi && testo && testt && !testa) | |
192 // strcpy(c_mode, "w+"); | |
193 | |
194 // Mode string should be empty for invalid combination of flags | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
195 if (strlen (c_mode) == 0) |
5269 | 196 return false; |
6275 | 197 |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
198 strcat (c_mode, "b"); |
6275 | 199 |
5269 | 200 return true; |
201 } | |
202 | |
203 // Determine number of characters in internal get buffer | |
204 std::streamsize | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
205 gzfilebuf::showmanyc () |
5269 | 206 { |
207 // Calls to underflow will fail if file not opened for reading | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
208 if (! this->is_open () || !(io_mode & std::ios_base::in)) |
5269 | 209 return -1; |
210 // Make sure get area is in use | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
211 if (this->gptr () && (this->gptr () < this->egptr ())) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
212 return std::streamsize (this->egptr () - this->gptr ()); |
5269 | 213 else |
214 return 0; | |
215 } | |
216 | |
6777 | 217 // Puts back a character to the stream in two cases. Firstly, when there |
218 // is no putback position available, and secondly when the character putback | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
219 // differs from the one in the file. We can only support the first case |
6777 | 220 // with gzipped files. |
221 gzfilebuf::int_type | |
222 gzfilebuf::pbackfail (gzfilebuf::int_type c) | |
223 { | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
224 if (this->is_open ()) |
6777 | 225 { |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
226 if (gzseek (file, this->gptr () - this->egptr () - 1, SEEK_CUR) < 0) |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
227 return traits_type::eof (); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
228 |
6777 | 229 // Invalidates contents of the buffer |
230 enable_buffer (); | |
231 | |
232 // Attempt to fill internal buffer from gzipped file | |
233 // (buffer must be guaranteed to exist...) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
234 int bytes_read = gzread (file, buffer, buffer_size); |
6777 | 235 // Indicates error or EOF |
236 if (bytes_read <= 0) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
237 { |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
238 // Reset get area |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
239 this->setg (buffer, buffer, buffer); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
240 return traits_type::eof (); |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
241 } |
6777 | 242 |
243 // Make all bytes read from file available as get area | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
244 this->setg (buffer, buffer, buffer + bytes_read); |
6777 | 245 |
246 // If next character in get area differs from putback character | |
247 // flag a failure | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
248 gzfilebuf::int_type ret = traits_type::to_int_type (*(this->gptr ())); |
6777 | 249 if (ret != c) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
250 return traits_type::eof (); |
6777 | 251 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
252 return ret; |
6777 | 253 } |
254 else | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
255 return traits_type::eof (); |
6777 | 256 } |
257 | |
5269 | 258 // Fill get area from gzipped file |
259 gzfilebuf::int_type | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
260 gzfilebuf::underflow () |
5269 | 261 { |
262 // If something is left in the get area by chance, return it | |
263 // (this shouldn't normally happen, as underflow is only supposed | |
264 // to be called when gptr >= egptr, but it serves as error check) | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
265 if (this->gptr () && (this->gptr () < this->egptr ())) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
266 return traits_type::to_int_type (*(this->gptr ())); |
5269 | 267 |
268 // If the file hasn't been opened for reading, produce error | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
269 if (! this->is_open () || !(io_mode & std::ios_base::in)) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
270 return traits_type::eof (); |
5269 | 271 |
6783 | 272 // Copy the final characters to the front of the buffer |
273 int stash = 0; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
274 if (this->eback () && buffer && buffer_size > STASHED_CHARACTERS) |
6783 | 275 { |
276 char_type *ptr1 = buffer; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
277 char_type *ptr2 = this->egptr () - STASHED_CHARACTERS + 1; |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
278 if (ptr2 > this->eback ()) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
279 while (stash++ <= STASHED_CHARACTERS) |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
280 *ptr1++ = *ptr2++; |
6783 | 281 } |
282 | |
5269 | 283 // Attempt to fill internal buffer from gzipped file |
284 // (buffer must be guaranteed to exist...) | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
285 int bytes_read = gzread (file, buffer + stash, buffer_size - stash); |
6783 | 286 |
5269 | 287 // Indicates error or EOF |
288 if (bytes_read <= 0) | |
289 { | |
290 // Reset get area | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
291 this->setg (buffer, buffer, buffer); |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
292 return traits_type::eof (); |
5269 | 293 } |
6783 | 294 // Make all bytes read from file plus the stash available as get area |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
295 this->setg (buffer, buffer + stash, buffer + bytes_read + stash); |
5269 | 296 |
297 // Return next character in get area | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
298 return traits_type::to_int_type (*(this->gptr ())); |
5269 | 299 } |
300 | |
301 // Write put area to gzipped file | |
302 gzfilebuf::int_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
303 gzfilebuf::overflow (int_type c) |
5269 | 304 { |
305 // Determine whether put area is in use | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
306 if (this->pbase ()) |
5269 | 307 { |
308 // Double-check pointer range | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
309 if (this->pptr () > this->epptr () || this->pptr () < this->pbase ()) |
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
310 return traits_type::eof (); |
5269 | 311 // Add extra character to buffer if not EOF |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
312 if (! traits_type::eq_int_type (c, traits_type::eof ())) |
5269 | 313 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
314 *(this->pptr ()) = traits_type::to_char_type (c); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
315 this->pbump (1); |
5269 | 316 } |
317 // Number of characters to write to file | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
318 int bytes_to_write = this->pptr () - this->pbase (); |
5269 | 319 // Overflow doesn't fail if nothing is to be written |
320 if (bytes_to_write > 0) | |
321 { | |
322 // If the file hasn't been opened for writing, produce error | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
323 if (! this->is_open () || !(io_mode & std::ios_base::out)) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
324 return traits_type::eof (); |
5269 | 325 // If gzipped file won't accept all bytes written to it, fail |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
326 if (gzwrite (file, this->pbase (), bytes_to_write) != bytes_to_write) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
327 return traits_type::eof (); |
5269 | 328 // Reset next pointer to point to pbase on success |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
329 this->pbump (-bytes_to_write); |
5269 | 330 } |
331 } | |
332 // Write extra character to file if not EOF | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
333 else if (! traits_type::eq_int_type (c, traits_type::eof ())) |
5269 | 334 { |
335 // If the file hasn't been opened for writing, produce error | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
336 if (! this->is_open () || !(io_mode & std::ios_base::out)) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
337 return traits_type::eof (); |
5269 | 338 // Impromptu char buffer (allows "unbuffered" output) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
339 char_type last_char = traits_type::to_char_type (c); |
5269 | 340 // If gzipped file won't accept this character, fail |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
341 if (gzwrite (file, &last_char, 1) != 1) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
342 return traits_type::eof (); |
5269 | 343 } |
344 | |
345 // If you got here, you have succeeded (even if c was EOF) | |
346 // The return value should therefore be non-EOF | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
347 if (traits_type::eq_int_type (c, traits_type::eof ())) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
348 return traits_type::not_eof (c); |
5269 | 349 else |
350 return c; | |
351 } | |
352 | |
353 // Assign new buffer | |
354 std::streambuf* | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
355 gzfilebuf::setbuf (char_type* p, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
356 std::streamsize n) |
5269 | 357 { |
358 // First make sure stuff is sync'ed, for safety | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
359 if (this->sync () == -1) |
7520 | 360 return 0; |
5269 | 361 // If buffering is turned off on purpose via setbuf(0,0), still allocate one... |
362 // "Unbuffered" only really refers to put [27.8.1.4.10], while get needs at | |
363 // least a buffer of size 1 (very inefficient though, therefore make it bigger?) | |
364 // This follows from [27.5.2.4.3]/12 (gptr needs to point at something, it seems) | |
365 if (!p || !n) | |
366 { | |
367 // Replace existing buffer (if any) with small internal buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
368 this->disable_buffer (); |
7520 | 369 buffer = 0; |
5269 | 370 buffer_size = 0; |
371 own_buffer = true; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
372 this->enable_buffer (); |
5269 | 373 } |
374 else | |
375 { | |
376 // Replace existing buffer (if any) with external buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
377 this->disable_buffer (); |
5269 | 378 buffer = p; |
379 buffer_size = n; | |
380 own_buffer = false; | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
381 this->enable_buffer (); |
5269 | 382 } |
383 return this; | |
384 } | |
385 | |
386 // Write put area to gzipped file (i.e. ensures that put area is empty) | |
387 int | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
388 gzfilebuf::sync () |
5269 | 389 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
390 return traits_type::eq_int_type (this->overflow (), traits_type::eof ()) ? -1 : 0; |
5269 | 391 } |
392 | |
393 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
394 | |
395 // Allocate internal buffer | |
396 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
397 gzfilebuf::enable_buffer () |
5269 | 398 { |
399 // If internal buffer required, allocate one | |
400 if (own_buffer && !buffer) | |
401 { | |
402 // Check for buffered vs. "unbuffered" | |
403 if (buffer_size > 0) | |
404 { | |
405 // Allocate internal buffer | |
406 buffer = new char_type[buffer_size]; | |
407 // Get area starts empty and will be expanded by underflow as need arises | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
408 this->setg (buffer, buffer, buffer); |
5269 | 409 // Setup entire internal buffer as put area. |
410 // The one-past-end pointer actually points to the last element of the buffer, | |
411 // so that overflow(c) can safely add the extra character c to the sequence. | |
412 // These pointers remain in place for the duration of the buffer | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
413 this->setp (buffer, buffer + buffer_size - 1); |
5269 | 414 } |
415 else | |
416 { | |
417 // Even in "unbuffered" case, (small?) get buffer is still required | |
418 buffer_size = SMALLBUFSIZE; | |
419 buffer = new char_type[buffer_size]; | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
420 this->setg (buffer, buffer, buffer); |
5269 | 421 // "Unbuffered" means no put buffer |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
422 this->setp (0, 0); |
5269 | 423 } |
424 } | |
425 else | |
426 { | |
427 // If buffer already allocated, reset buffer pointers just to make sure no | |
428 // stale chars are lying around | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
429 this->setg (buffer, buffer, buffer); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
430 this->setp (buffer, buffer + buffer_size - 1); |
5269 | 431 } |
432 } | |
433 | |
434 // Destroy internal buffer | |
435 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
436 gzfilebuf::disable_buffer () |
5269 | 437 { |
438 // If internal buffer exists, deallocate it | |
439 if (own_buffer && buffer) | |
440 { | |
441 // Preserve unbuffered status by zeroing size | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
442 if (! this->pbase ()) |
5269 | 443 buffer_size = 0; |
444 delete[] buffer; | |
7520 | 445 buffer = 0; |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
446 this->setg (0, 0, 0); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
447 this->setp (0, 0); |
5269 | 448 } |
449 else | |
450 { | |
451 // Reset buffer pointers to initial state if external buffer exists | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
452 this->setg (buffer, buffer, buffer); |
5269 | 453 if (buffer) |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
454 this->setp (buffer, buffer + buffer_size - 1); |
5269 | 455 else |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
456 this->setp (0, 0); |
5269 | 457 } |
458 } | |
459 | |
460 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | |
461 | |
462 // Seek functions | |
463 gzfilebuf::pos_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
464 gzfilebuf::seekoff (off_type off, std::ios_base::seekdir way, |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
465 std::ios_base::openmode) |
5269 | 466 { |
467 pos_type ret = pos_type (off_type (-1)); | |
468 | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
469 if (this->is_open ()) |
5269 | 470 { |
471 off_type computed_off = off; | |
472 | |
473 if ((io_mode & std::ios_base::in) && way == std::ios_base::cur) | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
474 computed_off += this->gptr () - this->egptr (); |
5269 | 475 |
476 if (way == std::ios_base::beg) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
477 ret = pos_type (gzseek (file, computed_off, SEEK_SET)); |
5269 | 478 else if (way == std::ios_base::cur) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
479 ret = pos_type (gzseek (file, computed_off, SEEK_CUR)); |
5269 | 480 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
481 // Can't seek from end of a gzipped file, so this will give -1 |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
482 ret = pos_type (gzseek (file, computed_off, SEEK_END)); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
483 |
5269 | 484 if (io_mode & std::ios_base::in) |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
485 // Invalidates contents of the buffer |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
486 enable_buffer (); |
5269 | 487 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
488 // flush contents of buffer to file |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
489 overflow (); |
5269 | 490 } |
491 | |
492 return ret; | |
493 } | |
494 | |
495 gzfilebuf::pos_type | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
496 gzfilebuf::seekpos (pos_type sp, std::ios_base::openmode) |
5269 | 497 { |
498 pos_type ret = pos_type (off_type (-1)); | |
499 | |
500 if (this->is_open ()) | |
501 { | |
502 ret = pos_type (gzseek (file, sp, SEEK_SET)); | |
503 | |
504 if (io_mode & std::ios_base::in) | |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
505 // Invalidates contents of the buffer |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
506 enable_buffer (); |
5269 | 507 else |
10317
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
508 // flush contents of buffer to file |
42d098307c30
untabify additional source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
509 overflow (); |
5269 | 510 } |
511 | |
512 return ret; | |
513 } | |
514 | |
515 /*****************************************************************************/ | |
516 | |
517 // Default constructor initializes stream buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
518 gzifstream::gzifstream () |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
519 : std::istream (0), sb () |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
520 { this->init (&sb); } |
5269 | 521 |
522 // Initialize stream buffer and open file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
523 gzifstream::gzifstream (const char* name, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
524 std::ios_base::openmode mode) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
525 : std::istream (0), sb () |
5269 | 526 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
527 this->init (&sb); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
528 this->open (name, mode); |
5269 | 529 } |
530 | |
531 // Initialize stream buffer and attach to file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
532 gzifstream::gzifstream (int fd, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
533 std::ios_base::openmode mode) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
534 : std::istream (0), sb () |
5269 | 535 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
536 this->init (&sb); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
537 this->attach (fd, mode); |
5269 | 538 } |
539 | |
540 // Open file and go into fail() state if unsuccessful | |
541 void | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
542 gzifstream::open (const char* name, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
543 std::ios_base::openmode mode) |
5269 | 544 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
545 if (! sb.open (name, mode | std::ios_base::in)) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
546 this->setstate (std::ios_base::failbit); |
5269 | 547 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
548 this->clear (); |
5269 | 549 } |
550 | |
551 // Attach to file and go into fail() state if unsuccessful | |
552 void | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
553 gzifstream::attach (int fd, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
554 std::ios_base::openmode mode) |
5269 | 555 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
556 if (! sb.attach (fd, mode | std::ios_base::in)) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
557 this->setstate (std::ios_base::failbit); |
5269 | 558 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
559 this->clear (); |
5269 | 560 } |
561 | |
562 // Close file | |
563 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
564 gzifstream::close () |
5269 | 565 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
566 if (! sb.close ()) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
567 this->setstate (std::ios_base::failbit); |
5269 | 568 } |
569 | |
570 /*****************************************************************************/ | |
571 | |
572 // Default constructor initializes stream buffer | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
573 gzofstream::gzofstream () |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
574 : std::ostream (0), sb () |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
575 { this->init (&sb); } |
5269 | 576 |
577 // Initialize stream buffer and open file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
578 gzofstream::gzofstream (const char* name, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
579 std::ios_base::openmode mode) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
580 : std::ostream (0), sb () |
5269 | 581 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
582 this->init (&sb); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
583 this->open (name, mode); |
5269 | 584 } |
585 | |
586 // Initialize stream buffer and attach to file | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
587 gzofstream::gzofstream (int fd, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
588 std::ios_base::openmode mode) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
589 : std::ostream (0), sb () |
5269 | 590 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
591 this->init (&sb); |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
592 this->attach (fd, mode); |
5269 | 593 } |
594 | |
595 // Open file and go into fail() state if unsuccessful | |
596 void | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
597 gzofstream::open (const char* name, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
598 std::ios_base::openmode mode) |
5269 | 599 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
600 if (! sb.open (name, mode | std::ios_base::out)) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
601 this->setstate (std::ios_base::failbit); |
5269 | 602 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
603 this->clear (); |
5269 | 604 } |
605 | |
606 // Attach to file and go into fail() state if unsuccessful | |
607 void | |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
608 gzofstream::attach (int fd, |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
609 std::ios_base::openmode mode) |
5269 | 610 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
611 if (! sb.attach (fd, mode | std::ios_base::out)) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
612 this->setstate (std::ios_base::failbit); |
5269 | 613 else |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
614 this->clear (); |
5269 | 615 } |
616 | |
617 // Close file | |
618 void | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
619 gzofstream::close () |
5269 | 620 { |
14861
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
621 if (! sb.close ()) |
f7afecdd87ef
maint: Use Octave coding conventions for cuddling parentheses in src/ directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
622 this->setstate (std::ios_base::failbit); |
5269 | 623 } |
624 | |
625 #endif // HAVE_ZLIB |