LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
gzfstream.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa Akiyama
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_GZ_GZFSTREAM_H
33#define RCSC_GZ_GZFSTREAM_H
34
35#include <memory>
36#include <iostream>
37#include <string>
38
39namespace rcsc {
40
51 : public std::streambuf {
52public:
63 DEFAULT_COMPRESSION = -1,
64 NO_COMPRESSION = 0,
65 BEST_SPEED = 1,
66 BEST_COMPRESSION = 9,
67 };
68
80 enum Strategy {
81 DEFAULT_STRATEGY = 0,
82 FILTERED = 1,
83 HUFFMAN_ONLY = 2,
84 RLE = 3,
85 };
86
87private:
88
90 struct Impl;
91
93 std::unique_ptr< Impl > M_impl;
94
96 std::size_t M_buf_size;
98 char_type * M_buf;
99
101 int M_remained_size;
103 char_type M_remained_char;
104
105
107 gzfilebuf( const gzfilebuf & ) = delete;
109 gzfilebuf & operator=( const gzfilebuf & ) = delete;
110
111public:
119
126 virtual
128
133 bool is_open();
134
149 gzfilebuf * open( const char * path,
150 std::ios_base::openmode mode,
151 int level = DEFAULT_COMPRESSION,
152 int strategy = DEFAULT_STRATEGY );
153
158 gzfilebuf * close() throw();
159
160
161private:
162
169 bool flushBuf();
170
181 std::string makeModeString( std::ios_base::openmode mode,
182 int level,
183 int strategy );
184
191 void destroyInternalBuffer() throw();
192
193protected:
194 //virtual
195 //void imbue( const locale& loc );
196 //virtual
197 //int_type pbackfail( int_type c );
198 //virtual
199 //std::streambuf* setbuf( char_type* p, std::streamsize n );
200
213 virtual
214 std::streampos seekoff( std::streamoff off,
215 std::ios_base::seekdir way,
216 std::ios_base::openmode mode );
217
225 virtual
226 std::streampos seekpos( std::streampos pos,
227 std::ios_base::openmode mode );
228
234 virtual
235 std::streamsize showmanyc();
236
242 virtual
243 int sync();
244
250 virtual
251 std::streambuf::int_type overflow( std::streambuf::int_type c );
252
253 // Not need to override because super class works sufficiently.
254 //virtual
255 //int_type uflow();
256
261 virtual
262 std::streambuf::int_type underflow();
263
264 // Not need to override because super class works sufficiently.
265 //virtual
266 //std::streamsize xsgetn( char_type* s, std::streamsize n );
267
268 // Not need to override because super class works sufficiently.
269 //virtual
270 //std::streamsize xsputn( char_type * s, std::streamsize n );
271
272 /* All virtual methods defined in std::streambuf.
273 See: http://www.cplusplus.com/ref/iostream/
274 XXX imbue Imbue locale [virtual]
275 OK overflow Put character at current position [virtual]
276 XXX pbackfail Put character back [virtual]
277 N/A seekoff Set relative position of internal position pointer [virtual]
278 OK seekpos Set absolute position of internal position pointer [virtual]
279 XXX setbuf Set buffer [virtual]
280 OK showmanyc Get number of characters availbale in input sequence [virtual]
281 OK sync Synchronize stream buffer [virtual]
282 OK uflow Get current character [virtual]
283 OK underflow Get current character [virtual]
284 OK xsgetn Get some characters [virtual]
285 OK xsputn Write some characters [virtual]
286 */
287};
288
289
290/*-------------------------------------------------------------------*/
291/*-------------------------------------------------------------------*/
292/*-------------------------------------------------------------------*/
293
294
303 : public std::istream {
304private:
306 gzfilebuf M_file_buf;
307public:
312
317 explicit
318 gzifstream( const char * path );
319
324 gzfilebuf * rdbuf() const
325 {
326 return const_cast< gzfilebuf * >( &M_file_buf );
327 }
328
334 bool is_open()
335 {
336 return M_file_buf.is_open();
337 }
338
350 void open( const char * path );
351
357 void close();
358};
359
360/*****************************************************************************/
361
370 : public std::ostream {
371private:
373 gzfilebuf M_file_buf;
374
375public:
382
391 explicit
392 gzofstream( const char* path,
393 int level = gzfilebuf::DEFAULT_COMPRESSION,
394 int strategy = gzfilebuf::DEFAULT_STRATEGY );
395
400 gzfilebuf * rdbuf() const
401 {
402 return const_cast< gzfilebuf * >( &M_file_buf );
403 }
404
410 bool is_open()
411 {
412 return M_file_buf.is_open();
413 }
414
428 void open( const char * path,
429 int level = gzfilebuf::DEFAULT_COMPRESSION,
430 int strategy = gzfilebuf::DEFAULT_STRATEGY );
431
437 void close();
438};
439
440} // end namespace
441
442#endif // include guard
gzip file stream buffer class.
Definition: gzfstream.h:51
Strategy
typical compression strategy enumeration.
Definition: gzfstream.h:80
bool is_open()
check if file is open.
virtual std::streampos seekpos(std::streampos pos, std::ios_base::openmode mode)
overrided method. seek stream.
virtual std::streambuf::int_type underflow()
get current character
virtual std::streamsize showmanyc()
overrided method. get number of characters availbale in input sequence
virtual int sync()
synchronize stream buffer
virtual std::streambuf::int_type overflow(std::streambuf::int_type c)
put character at current put position.
gzfilebuf()
default constructor.
CompressionLevel
typical compression level enumeration
Definition: gzfstream.h:62
virtual ~gzfilebuf()
destructor.
virtual std::streampos seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode mode)
overrided method. set relative position of internal position pointer
gzfilebuf * close()
closes the file if opened.
gzfilebuf * open(const char *path, std::ios_base::openmode mode, int level=DEFAULT_COMPRESSION, int strategy=DEFAULT_STRATEGY)
open the file.
gzipped file input stream class.
Definition: gzfstream.h:303
gzifstream()
default constructor
void open(const char *path)
open gzipped file.
gzifstream(const char *path)
init stream buffer and open file.
void close()
close gzipped file.
gzfilebuf * rdbuf() const
get underlying stream buffer.
Definition: gzfstream.h:324
bool is_open()
check if file is open.
Definition: gzfstream.h:334
gzipped file output stream class.
Definition: gzfstream.h:370
gzofstream()
default constructor
gzofstream(const char *path, int level=gzfilebuf::DEFAULT_COMPRESSION, int strategy=gzfilebuf::DEFAULT_STRATEGY)
construct streambuf with file name.
void close()
close gzipped file.
void open(const char *path, int level=gzfilebuf::DEFAULT_COMPRESSION, int strategy=gzfilebuf::DEFAULT_STRATEGY)
open gzipped file.
gzfilebuf * rdbuf() const
get const_cast<> pointer to the underlying stream buffer.
Definition: gzfstream.h:400
bool is_open()
check if file is open
Definition: gzfstream.h:410