CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
zstream.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_MVAComputer_zstream_h
2 #define PhysicsTools_MVAComputer_zstream_h
3 // -*- C++ -*-
4 //
5 // Package: MVAComputer
6 //
7 
8 //
9 // Author: Christophe Saout <christophe.saout@cern.ch>
10 // Created: Sat Apr 24 15:18 CEST 2007
11 // $Id: zstream.h,v 1.4 2012/04/02 12:37:11 davidlt Exp $
12 //
13 
14 #include <iostream>
15 #include <vector>
16 
17 #include <zlib.h>
18 
19 namespace ext {
20 
21 // implements STL stream wrappers around other streams
22 // to provide transparent gzip compression/decompression
23 //
24 // constructors take reference to an existing stream, rest is straightforward
25 
26 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
27  typename Allocator_t = std::allocator<Item_t> >
28 class basic_ozstreambuf : public std::basic_streambuf<Item_t, Traits_t> {
29  public:
30  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
31  typedef std::basic_streambuf<Item_t, Traits_t> StreamBuf_t;
32 
33  typedef Item_t char_type;
34  typedef typename Traits_t::int_type int_type;
35  typedef typename Traits_t::pos_type pos_type;
36  typedef typename Traits_t::off_type off_type;
37  typedef unsigned char byte_type;
38  typedef Traits_t traits_type;
39 
42 
43  using StreamBuf_t::pbase;
44  using StreamBuf_t::pptr;
45  using StreamBuf_t::epptr;
46 
47  int sync();
49  std::streamsize flush();
50 
51  private:
52  bool zipToStream(char_type *buf, std::streamsize size);
53  size_t fillInputBuffer();
54 
56  z_stream zipStream;
57  int err;
58  std::vector<byte_type> outputBuffer;
59  std::vector<char_type, Allocator_t> buffer;
60 };
61 
62 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
63  typename Allocator_t = std::allocator<Item_t> >
64 class basic_izstreambuf : public std::basic_streambuf<Item_t, Traits_t> {
65  public:
66  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
67  typedef std::basic_streambuf<Item_t, Traits_t> StreamBuf_t;
68 
69  typedef Item_t char_type;
70  typedef typename Traits_t::int_type int_type;
71  typedef typename Traits_t::pos_type pos_type;
72  typedef typename Traits_t::off_type off_type;
73  typedef unsigned char byte_type;
74  typedef Traits_t traits_type;
75 
78 
79  using StreamBuf_t::gptr;
80  using StreamBuf_t::egptr;
81  using StreamBuf_t::eback;
82 
84 
85  private:
86  void putbackFromZStream();
87  std::streamsize unzipFromStream(char_type *buf, std::streamsize size);
88  size_t fillInputBuffer();
89 
91  z_stream zipStream;
92  int err;
93  std::vector<byte_type> inputBuffer;
94  std::vector<char_type, Allocator_t> buffer;
95 };
96 
97 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
98  typename Allocator_t = std::allocator<Item_t> >
99 class basic_ozstreambase : virtual public std::basic_ios<Item_t, Traits_t> {
100  public:
101  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
103 
105  buffer(os, level) { this->init(&buffer); }
106 
107  ZOStreamBuf_t *rdbuf() { return &buffer; }
108 
109  private:
111 };
112 
113 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
114  typename Allocator_t = std::allocator<Item_t> >
115 class basic_izstreambase : virtual public std::basic_ios<Item_t, Traits_t> {
116  public:
117  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
119 
121 
122  ZIStreamBuf_t *rdbuf() { return &buffer; }
123 
124  private:
126 };
127 
128 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
129  typename Allocator_t = std::allocator<Item_t> >
130 class basic_ozstream : public basic_ozstreambase<Item_t, Traits_t, Allocator_t>,
131  public std::basic_ostream<Item_t, Traits_t> {
132  public:
133  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
135 
136  basic_ozstream(OStream_t *os, int open_mode = std::ios::out,
137  int level = 9) :
138  ZOStreamBase_t(os, level),
141 };
142 
143 template<typename Item_t, typename Traits_t = std::char_traits<Item_t>,
144  typename Allocator_t = std::allocator<Item_t> >
145 class basic_izstream : public basic_izstreambase<Item_t, Traits_t, Allocator_t>,
146  public std::basic_istream<Item_t, Traits_t> {
147  public:
148  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
150 
151  basic_izstream(IStream_t *is, int open_mode = std::ios::in) :
154 };
155 
160 
161 } // namespace ext
162 
163 #include "PhysicsTools/MVAComputer/interface/zstream.icc"
164 
165 #endif // PhysicsTools_MVAComputer_zstream_h
OStream_t * os
Definition: zstream.h:55
unsigned char byte_type
Definition: zstream.h:37
std::basic_streambuf< Item_t, Traits_t > StreamBuf_t
Definition: zstream.h:67
unsigned char byte_type
Definition: zstream.h:73
Traits_t traits_type
Definition: zstream.h:38
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:101
basic_izstream< char > izstream
Definition: zstream.h:158
ZOStreamBuf_t * rdbuf()
Definition: zstream.h:107
int init
Definition: HydjetWrapper.h:63
basic_ozstream< char > ozstream
Definition: zstream.h:156
Traits_t::pos_type pos_type
Definition: zstream.h:71
basic_izstream< wchar_t > wizstream
Definition: zstream.h:159
basic_izstreambuf(IStream_t *is)
basic_ozstream(OStream_t *os, int open_mode=std::ios::out, int level=9)
Definition: zstream.h:136
std::streamsize flush()
basic_izstreambuf< Item_t, Traits_t, Allocator_t > ZIStreamBuf_t
Definition: zstream.h:118
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:66
Traits_t::int_type int_type
Definition: zstream.h:70
basic_izstreambase< Item_t, Traits_t, Allocator_t > ZIStreamBase_t
Definition: zstream.h:149
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:148
Traits_t::pos_type pos_type
Definition: zstream.h:35
std::streamsize unzipFromStream(char_type *buf, std::streamsize size)
z_stream zipStream
Definition: zstream.h:91
basic_ozstream< wchar_t > wozstream
Definition: zstream.h:157
basic_ozstreambuf< Item_t, Traits_t, Allocator_t > ZOStreamBuf_t
Definition: zstream.h:102
std::vector< char_type, Allocator_t > buffer
Definition: zstream.h:94
basic_izstream(IStream_t *is, int open_mode=std::ios::in)
Definition: zstream.h:151
Traits_t::int_type int_type
Definition: zstream.h:34
int_type overflow(int_type c)
basic_ozstreambase(OStream_t *os, int level)
Definition: zstream.h:104
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:133
tuple out
Definition: dbtoconf.py:99
Traits_t traits_type
Definition: zstream.h:74
std::vector< byte_type > inputBuffer
Definition: zstream.h:93
ZIStreamBuf_t buffer
Definition: zstream.h:125
ZIStreamBuf_t * rdbuf()
Definition: zstream.h:122
basic_ozstreambase< Item_t, Traits_t, Allocator_t > ZOStreamBase_t
Definition: zstream.h:134
basic_izstreambase(IStream_t *is)
Definition: zstream.h:120
ZOStreamBuf_t buffer
Definition: zstream.h:110
Traits_t::off_type off_type
Definition: zstream.h:36
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:117
basic_ozstreambuf(OStream_t *os, int level)
Traits_t::off_type off_type
Definition: zstream.h:72
std::vector< byte_type > outputBuffer
Definition: zstream.h:58
tuple level
Definition: testEve_cfg.py:34
IStream_t * is
Definition: zstream.h:90
z_stream zipStream
Definition: zstream.h:56
tuple size
Write out results.
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:30
std::vector< char_type, Allocator_t > buffer
Definition: zstream.h:59
std::basic_streambuf< Item_t, Traits_t > StreamBuf_t
Definition: zstream.h:31
bool zipToStream(char_type *buf, std::streamsize size)