MIRA
GzStream.h
Go to the documentation of this file.
1 // ============================================================================
2 // gzstream, C++ iostream classes wrapping the zlib compression library.
3 // Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // ============================================================================
19 //
20 // File : gzstream.h
21 // Revision : $Revision: 1.5 $
22 // Revision_date : $Date: 2002/04/26 23:30:15 $
23 // Author(s) : Deepak Bandyopadhyay, Lutz Kettner
24 //
25 // Standard streambuf implementation following Nicolai Josuttis, "The
26 // Standard C++ Library".
27 // ============================================================================
28 
29 #ifndef GZSTREAM_H
30 #define GZSTREAM_H
31 
32 // standard C++ with new header file names and std:: namespace
33 #include <iostream>
34 #include <fstream>
35 #include <zlib.h>
36 
37 // added for mira
38 #include <platform/Platform.h>
39 
40 // modified for mira
41 namespace mira {
42 
43 // ----------------------------------------------------------------------------
44 // Internal classes to implement gzstream. See below for user classes.
45 // ----------------------------------------------------------------------------
46 
47 class gzstreambuf : public std::streambuf {
48 private:
49  static const int bufferSize = 47+256; // size of data buff
50  // totals 512 bytes under g++ for igzstream at the end.
51 
52  gzFile file; // file handle for compressed file
53  char buffer[bufferSize]; // data buffer
54  char opened; // open/close state of stream
55  int mode; // I/O mode
56 
57  int flush_buffer();
58 public:
59  gzstreambuf() : opened(0) {
60  setp( buffer, buffer + (bufferSize-1));
61  setg( buffer + 4, // beginning of putback area
62  buffer + 4, // read position
63  buffer + 4); // end position
64  // ASSERT: both input & output capabilities will not be used together
65  }
66  int is_open() { return opened; }
67  gzstreambuf* open( const char* name, int open_mode);
68  gzstreambuf* close();
70 
71  virtual int overflow( int c = EOF);
72  virtual int underflow();
73  virtual int sync();
74 };
75 
76 class gzstreambase : virtual public std::ios {
77 protected:
79 public:
80  gzstreambase() { init(&buf); }
81  gzstreambase( const char* name, int open_mode);
82  ~gzstreambase();
83  void open( const char* name, int open_mode);
84  void close();
85  gzstreambuf* rdbuf() { return &buf; }
86 };
87 
93 class MIRA_BASE_EXPORT igzstream : public gzstreambase, public std::istream {
94 public:
95  igzstream() : std::istream( &buf) {}
96  igzstream( const char* name, int open_mode = std::ios::in)
97  : gzstreambase( name, open_mode), std::istream( &buf) {}
99  void open( const char* name, int open_mode = std::ios::in) {
100  gzstreambase::open( name, open_mode);
101  }
102 };
103 
109 class MIRA_BASE_EXPORT ogzstream : public gzstreambase, public std::ostream {
110 public:
111  ogzstream() : std::ostream( &buf) {}
112  ogzstream( const char* name, int mode = std::ios::out)
113  : gzstreambase( name, mode), std::ostream( &buf) {}
115  void open( const char* name, int open_mode = std::ios::out) {
116  gzstreambase::open( name, open_mode);
117  }
118 };
119 
120 }
121 
122 #endif // GZSTREAM_H
123 // ============================================================================
124 // EOF //
125 
int is_open()
Definition: GzStream.h:66
void open(const char *name, int open_mode=std::ios::out)
Definition: GzStream.h:115
Definition: GzStream.h:76
Use igzstream and ogzstream analogously to ifstream and ofstream respectively.
Definition: GzStream.h:109
Definition: GzStream.h:47
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
virtual int underflow()
Use igzstream and ogzstream analogously to ifstream and ofstream respectively.
Definition: GzStream.h:93
gzstreambuf * open(const char *name, int open_mode)
STL namespace.
gzstreambuf * close()
gzstreambase()
Definition: GzStream.h:80
gzstreambuf * rdbuf()
Definition: GzStream.h:114
gzstreambuf * rdbuf()
Definition: GzStream.h:98
gzstreambuf * rdbuf()
Definition: GzStream.h:85
virtual int sync()
void open(const char *name, int open_mode)
gzstreambuf buf
Definition: GzStream.h:78
igzstream(const char *name, int open_mode=std::ios::in)
Definition: GzStream.h:96
ogzstream()
Definition: GzStream.h:111
void open(const char *name, int open_mode=std::ios::in)
Definition: GzStream.h:99
virtual int overflow(int c=EOF)
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
ogzstream(const char *name, int mode=std::ios::out)
Definition: GzStream.h:112
gzstreambuf()
Definition: GzStream.h:59
igzstream()
Definition: GzStream.h:95
Platform dependent defines and macros.
~gzstreambuf()
Definition: GzStream.h:69