CMS 3D CMS Logo

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 //
12 
13 #include <iostream>
14 #include <vector>
15 
16 #include <zlib.h>
17 
18 namespace ext {
19 
20  // implements STL stream wrappers around other streams
21  // to provide transparent gzip compression/decompression
22  //
23  // constructors take reference to an existing stream, rest is straightforward
24 
25  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
26  class basic_ozstreambuf : public std::basic_streambuf<Item_t, Traits_t> {
27  public:
28  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
29  typedef std::basic_streambuf<Item_t, Traits_t> StreamBuf_t;
30 
31  typedef Item_t char_type;
32  typedef typename Traits_t::int_type int_type;
33  typedef typename Traits_t::pos_type pos_type;
34  typedef typename Traits_t::off_type off_type;
35  typedef unsigned char byte_type;
36  typedef Traits_t traits_type;
37 
39  ~basic_ozstreambuf() override;
40 
41  using StreamBuf_t::epptr;
42  using StreamBuf_t::pbase;
43  using StreamBuf_t::pptr;
44 
45  int sync() override;
46  int_type overflow(int_type c) override;
47  std::streamsize flush();
48 
49  private:
50  bool zipToStream(char_type *buf, std::streamsize size);
51  size_t fillInputBuffer();
52 
54  z_stream zipStream;
55  int err;
56  std::vector<byte_type> outputBuffer;
57  std::vector<char_type, Allocator_t> buffer;
58  };
59 
60  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
61  class basic_izstreambuf : public std::basic_streambuf<Item_t, Traits_t> {
62  public:
63  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
64  typedef std::basic_streambuf<Item_t, Traits_t> StreamBuf_t;
65 
66  typedef Item_t char_type;
67  typedef typename Traits_t::int_type int_type;
68  typedef typename Traits_t::pos_type pos_type;
69  typedef typename Traits_t::off_type off_type;
70  typedef unsigned char byte_type;
71  typedef Traits_t traits_type;
72 
74  ~basic_izstreambuf() override;
75 
76  using StreamBuf_t::eback;
77  using StreamBuf_t::egptr;
78  using StreamBuf_t::gptr;
79 
80  int_type underflow() override;
81 
82  private:
83  void putbackFromZStream();
84  std::streamsize unzipFromStream(char_type *buf, std::streamsize size);
85  size_t fillInputBuffer();
86 
88  z_stream zipStream;
89  int err;
90  std::vector<byte_type> inputBuffer;
91  std::vector<char_type, Allocator_t> buffer;
92  };
93 
94  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
95  class basic_ozstreambase : virtual public std::basic_ios<Item_t, Traits_t> {
96  public:
97  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
99 
100  basic_ozstreambase(OStream_t *os, int level) : buffer(os, level) { this->init(&buffer); }
101 
102  ZOStreamBuf_t *rdbuf() { return &buffer; }
103 
104  private:
106  };
107 
108  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
109  class basic_izstreambase : virtual public std::basic_ios<Item_t, Traits_t> {
110  public:
111  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
113 
115 
116  ZIStreamBuf_t *rdbuf() { return &buffer; }
117 
118  private:
120  };
121 
122  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
123  class basic_ozstream : public basic_ozstreambase<Item_t, Traits_t, Allocator_t>,
124  public std::basic_ostream<Item_t, Traits_t> {
125  public:
126  typedef std::basic_ostream<Item_t, Traits_t> OStream_t;
128 
129  basic_ozstream(OStream_t *os, int open_mode = std::ios::out, int level = 9)
131  ~basic_ozstream() override {}
132  };
133 
134  template <typename Item_t, typename Traits_t = std::char_traits<Item_t>, typename Allocator_t = std::allocator<Item_t> >
135  class basic_izstream : public basic_izstreambase<Item_t, Traits_t, Allocator_t>,
136  public std::basic_istream<Item_t, Traits_t> {
137  public:
138  typedef std::basic_istream<Item_t, Traits_t> IStream_t;
140 
141  basic_izstream(IStream_t *is, int open_mode = std::ios::in)
143  ~basic_izstream() override {}
144  };
145 
150 
151 } // namespace ext
152 
153 #include "PhysicsTools/MVAComputer/interface/zstream.icc"
154 
155 #endif // PhysicsTools_MVAComputer_zstream_h
personalPlayback.level
level
Definition: personalPlayback.py:22
ext::basic_ozstreambuf::zipStream
z_stream zipStream
Definition: zstream.h:54
ext
Definition: memstream.h:15
init
int init
Definition: HydjetWrapper.h:64
ext::basic_ozstreambuf::OStream_t
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:28
ext::basic_ozstream::basic_ozstream
basic_ozstream(OStream_t *os, int open_mode=std::ios::out, int level=9)
Definition: zstream.h:129
ext::ozstream
basic_ozstream< char > ozstream
Definition: zstream.h:146
ext::basic_izstream::IStream_t
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:138
ext::basic_izstream::ZIStreamBase_t
basic_izstreambase< Item_t, Traits_t, Allocator_t > ZIStreamBase_t
Definition: zstream.h:139
ext::basic_izstreambuf::StreamBuf_t
std::basic_streambuf< Item_t, Traits_t > StreamBuf_t
Definition: zstream.h:64
ext::basic_ozstreambase::rdbuf
ZOStreamBuf_t * rdbuf()
Definition: zstream.h:102
ext::basic_ozstreambuf
Definition: zstream.h:26
ext::basic_izstreambuf::off_type
Traits_t::off_type off_type
Definition: zstream.h:69
ext::basic_ozstreambuf::err
int err
Definition: zstream.h:55
ext::basic_ozstreambuf::~basic_ozstreambuf
~basic_ozstreambuf() override
ext::basic_izstreambuf::putbackFromZStream
void putbackFromZStream()
ext::basic_ozstreambuf::traits_type
Traits_t traits_type
Definition: zstream.h:36
ext::basic_ozstreambuf::int_type
Traits_t::int_type int_type
Definition: zstream.h:32
ext::basic_izstream::basic_izstream
basic_izstream(IStream_t *is, int open_mode=std::ios::in)
Definition: zstream.h:141
ext::basic_ozstreambuf::os
OStream_t * os
Definition: zstream.h:53
ext::basic_ozstreambuf::byte_type
unsigned char byte_type
Definition: zstream.h:35
ext::basic_ozstreambuf::char_type
Item_t char_type
Definition: zstream.h:31
ext::basic_izstreambase::ZIStreamBuf_t
basic_izstreambuf< Item_t, Traits_t, Allocator_t > ZIStreamBuf_t
Definition: zstream.h:112
ext::basic_ozstreambuf::basic_ozstreambuf
basic_ozstreambuf(OStream_t *os, int level)
ext::basic_izstreambuf::is
IStream_t * is
Definition: zstream.h:87
ext::basic_izstreambuf::unzipFromStream
std::streamsize unzipFromStream(char_type *buf, std::streamsize size)
ext::basic_izstreambuf::buffer
std::vector< char_type, Allocator_t > buffer
Definition: zstream.h:91
ext::basic_izstreambuf::basic_izstreambuf
basic_izstreambuf(IStream_t *is)
ext::basic_izstream::~basic_izstream
~basic_izstream() override
Definition: zstream.h:143
ext::izstream
basic_izstream< char > izstream
Definition: zstream.h:148
ext::basic_ozstreambase
Definition: zstream.h:95
ext::basic_ozstreambuf::StreamBuf_t
std::basic_streambuf< Item_t, Traits_t > StreamBuf_t
Definition: zstream.h:29
ext::basic_ozstreambuf::zipToStream
bool zipToStream(char_type *buf, std::streamsize size)
ext::basic_ozstreambuf::buffer
std::vector< char_type, Allocator_t > buffer
Definition: zstream.h:57
ext::basic_ozstreambase::ZOStreamBuf_t
basic_ozstreambuf< Item_t, Traits_t, Allocator_t > ZOStreamBuf_t
Definition: zstream.h:98
ext::basic_izstreambuf::fillInputBuffer
size_t fillInputBuffer()
ext::basic_ozstream::~basic_ozstream
~basic_ozstream() override
Definition: zstream.h:131
ext::basic_izstreambase::buffer
ZIStreamBuf_t buffer
Definition: zstream.h:119
ext::basic_izstreambuf::traits_type
Traits_t traits_type
Definition: zstream.h:71
ext::basic_izstreambuf::err
int err
Definition: zstream.h:89
ext::basic_izstreambuf::inputBuffer
std::vector< byte_type > inputBuffer
Definition: zstream.h:90
recoMuon::in
Definition: RecoMuonEnumerators.h:6
ext::basic_izstreambuf::~basic_izstreambuf
~basic_izstreambuf() override
ext::basic_izstreambuf::int_type
Traits_t::int_type int_type
Definition: zstream.h:67
ext::basic_izstreambase::basic_izstreambase
basic_izstreambase(IStream_t *is)
Definition: zstream.h:114
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
ext::basic_ozstreambase::basic_ozstreambase
basic_ozstreambase(OStream_t *os, int level)
Definition: zstream.h:100
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
ext::basic_izstream
Definition: zstream.h:135
ext::basic_izstreambase::rdbuf
ZIStreamBuf_t * rdbuf()
Definition: zstream.h:116
ext::basic_izstreambuf::underflow
int_type underflow() override
ext::basic_ozstreambuf::off_type
Traits_t::off_type off_type
Definition: zstream.h:34
ext::basic_izstreambuf::zipStream
z_stream zipStream
Definition: zstream.h:88
ext::basic_ozstreambuf::fillInputBuffer
size_t fillInputBuffer()
ext::basic_ozstreambuf::outputBuffer
std::vector< byte_type > outputBuffer
Definition: zstream.h:56
ext::wozstream
basic_ozstream< wchar_t > wozstream
Definition: zstream.h:147
ext::basic_izstreambase
Definition: zstream.h:109
ext::basic_izstreambuf::byte_type
unsigned char byte_type
Definition: zstream.h:70
ext::basic_ozstream
Definition: zstream.h:123
ext::basic_izstreambuf::char_type
Item_t char_type
Definition: zstream.h:66
ext::basic_ozstreambuf::flush
std::streamsize flush()
ext::basic_izstreambuf::IStream_t
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:63
ext::basic_ozstreambase::buffer
ZOStreamBuf_t buffer
Definition: zstream.h:105
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ext::basic_izstreambase::IStream_t
std::basic_istream< Item_t, Traits_t > IStream_t
Definition: zstream.h:111
ext::basic_ozstreambuf::pos_type
Traits_t::pos_type pos_type
Definition: zstream.h:33
ext::basic_ozstreambuf::sync
int sync() override
ext::basic_ozstream::ZOStreamBase_t
basic_ozstreambase< Item_t, Traits_t, Allocator_t > ZOStreamBase_t
Definition: zstream.h:127
ext::basic_izstreambuf::pos_type
Traits_t::pos_type pos_type
Definition: zstream.h:68
ext::basic_ozstreambuf::overflow
int_type overflow(int_type c) override
ext::wizstream
basic_izstream< wchar_t > wizstream
Definition: zstream.h:149
ext::basic_ozstream::OStream_t
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:126
ext::basic_izstreambuf
Definition: zstream.h:61
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
ext::basic_ozstreambase::OStream_t
std::basic_ostream< Item_t, Traits_t > OStream_t
Definition: zstream.h:97