bloaty/third_party/zlib/contrib/iostream3/zfstream.h
Go to the documentation of this file.
1 /*
2  * A C++ I/O streams interface to the zlib gz* functions
3  *
4  * by Ludwig Schwardt <schwardt@sun.ac.za>
5  * original version by Kevin Ruland <kevin@rodin.wustl.edu>
6  *
7  * This version is standard-compliant and compatible with gcc 3.x.
8  */
9 
10 #ifndef ZFSTREAM_H
11 #define ZFSTREAM_H
12 
13 #include <istream> // not iostream, since we don't need cin/cout
14 #include <ostream>
15 #include "zlib.h"
16 
17 /*****************************************************************************/
18 
27 class gzfilebuf : public std::streambuf
28 {
29 public:
30  // Default constructor.
31  gzfilebuf();
32 
33  // Destructor.
34  virtual
35  ~gzfilebuf();
36 
48  int
49  setcompression(int comp_level,
50  int comp_strategy = Z_DEFAULT_STRATEGY);
51 
56  bool
57  is_open() const { return (file != NULL); }
58 
65  gzfilebuf*
66  open(const char* name,
67  std::ios_base::openmode mode);
68 
75  gzfilebuf*
76  attach(int fd,
77  std::ios_base::openmode mode);
78 
83  gzfilebuf*
84  close();
85 
86 protected:
91  bool
92  open_mode(std::ios_base::openmode mode,
93  char* c_mode) const;
94 
102  virtual std::streamsize
103  showmanyc();
104 
112  virtual int_type
113  underflow();
114 
124  virtual int_type
125  overflow(int_type c = traits_type::eof());
126 
135  virtual std::streambuf*
136  setbuf(char_type* p,
137  std::streamsize n);
138 
145  virtual int
146  sync();
147 
148 //
149 // Some future enhancements
150 //
151 // virtual int_type uflow();
152 // virtual int_type pbackfail(int_type c = traits_type::eof());
153 // virtual pos_type
154 // seekoff(off_type off,
155 // std::ios_base::seekdir way,
156 // std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
157 // virtual pos_type
158 // seekpos(pos_type sp,
159 // std::ios_base::openmode mode = std::ios_base::in|std::ios_base::out);
160 
161 private:
170  void
171  enable_buffer();
172 
180  void
181  disable_buffer();
182 
186  gzFile file;
187 
191  std::ios_base::openmode io_mode;
192 
199  bool own_fd;
200 
208 
215  std::streamsize buffer_size;
216 
224 };
225 
226 /*****************************************************************************/
227 
234 class gzifstream : public std::istream
235 {
236 public:
237  // Default constructor
238  gzifstream();
239 
245  explicit
246  gzifstream(const char* name,
247  std::ios_base::openmode mode = std::ios_base::in);
248 
254  explicit
255  gzifstream(int fd,
256  std::ios_base::openmode mode = std::ios_base::in);
257 
261  gzfilebuf*
262  rdbuf() const
263  { return const_cast<gzfilebuf*>(&sb); }
264 
269  bool
270  is_open() { return sb.is_open(); }
271 
284  void
285  open(const char* name,
286  std::ios_base::openmode mode = std::ios_base::in);
287 
296  void
297  attach(int fd,
298  std::ios_base::openmode mode = std::ios_base::in);
299 
305  void
306  close();
307 
308 private:
313 };
314 
315 /*****************************************************************************/
316 
323 class gzofstream : public std::ostream
324 {
325 public:
326  // Default constructor
327  gzofstream();
328 
334  explicit
335  gzofstream(const char* name,
336  std::ios_base::openmode mode = std::ios_base::out);
337 
343  explicit
344  gzofstream(int fd,
345  std::ios_base::openmode mode = std::ios_base::out);
346 
350  gzfilebuf*
351  rdbuf() const
352  { return const_cast<gzfilebuf*>(&sb); }
353 
358  bool
359  is_open() { return sb.is_open(); }
360 
373  void
374  open(const char* name,
375  std::ios_base::openmode mode = std::ios_base::out);
376 
385  void
386  attach(int fd,
387  std::ios_base::openmode mode = std::ios_base::out);
388 
394  void
395  close();
396 
397 private:
402 };
403 
404 /*****************************************************************************/
405 
412 template<typename T1, typename T2>
413  class gzomanip2
414  {
415  public:
416  // Allows insertor to peek at internals
417  template <typename Ta, typename Tb>
418  friend gzofstream&
420  const gzomanip2<Ta,Tb>&);
421 
422  // Constructor
424  T1 v1,
425  T2 v2);
426  private:
427  // Underlying manipulator function
428  gzofstream&
429  (*func)(gzofstream&, T1, T2);
430 
431  // Arguments for manipulator function
434  };
435 
436 /*****************************************************************************/
437 
438 // Manipulator function thunks through to stream buffer
439 inline gzofstream&
441 {
442  (gzs.rdbuf())->setcompression(l, s);
443  return gzs;
444 }
445 
446 // Manipulator constructor stores arguments
447 template<typename T1, typename T2>
448  inline
450  T1 v1,
451  T2 v2)
452  : func(f), val1(v1), val2(v2)
453  { }
454 
455 // Insertor applies underlying manipulator function to stream
456 template<typename T1, typename T2>
457  inline gzofstream&
459  { return (*m.func)(s, m.val1, m.val2); }
460 
461 // Insert this onto stream to simplify setting of compression level
462 inline gzomanip2<int,int>
464 { return gzomanip2<int,int>(&setcompression, l, s); }
465 
466 #endif // ZFSTREAM_H
gzfilebuf::showmanyc
virtual std::streamsize showmanyc()
Number of characters available in stream buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:169
gzfilebuf::close
gzfilebuf * close()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:102
gzfilebuf::sync
virtual int sync()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:206
grpc::testing::val1
const char val1[]
Definition: client_context_test_peer_test.cc:34
gzfilebuf::setbuf
virtual std::streambuf * setbuf(char_type *p, std::streamsize n)
Installs external stream buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:266
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
gzfilebuf::gzfilebuf
gzfilebuf()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:4
gzfilebuf::enable_buffer
void enable_buffer()
Allocate internal buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:308
gzfilebuf::attach
gzfilebuf * attach(int file_descriptor, int io_mode)
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:60
gzfilebuf::open_mode
bool open_mode(std::ios_base::openmode mode, char *c_mode) const
Convert ios open mode int to mode string used by zlib.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:131
char_type
static const unsigned char char_type[]
Definition: charmap.h:6
gzfilebuf::disable_buffer
void disable_buffer()
Destroy internal buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:347
gzFile_s
Definition: bloaty/third_party/zlib/zlib.h:1817
gzomanip2::val1
T1 val1
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:432
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
gzomanip2
Gzipped file output stream manipulator class.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:413
mode
const char int mode
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:135
setup.name
name
Definition: setup.py:542
xds_manager.p
p
Definition: xds_manager.py:60
gzomanip2::gzomanip2
gzomanip2(gzofstream &(*f)(gzofstream &, T1, T2), T1 v1, T2 v2)
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:449
gzofstream::open
void open(const char *name, std::ios_base::openmode mode=std::ios_base::out)
Open gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:453
gzofstream::gzofstream
gzofstream()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:311
gzofstream::sb
gzfilebuf sb
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:401
gzofstream
Gzipped file output stream class.
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.h:80
operator<<
gzofstream & operator<<(gzofstream &s, const gzomanip2< T1, T2 > &m)
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:458
gzfilebuf::file
gzFile file
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.h:35
re2::T1
@ T1
Definition: bloaty/third_party/re2/util/rune.cc:31
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
c
void c(T a)
Definition: miscompile_with_no_unique_address_test.cc:40
autogen_x86imm.f
f
Definition: autogen_x86imm.py:9
gzfilebuf::is_open
bool is_open() const
Check if file is open.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:57
gzfilebuf::own_fd
bool own_fd
True if this object owns file descriptor.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:199
grpc::testing::val2
const char val2[]
Definition: client_context_test_peer_test.cc:35
gzfilebuf::buffer
char_type * buffer
Stream buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:207
gzfilebuf::~gzfilebuf
virtual ~gzfilebuf()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:10
gzfilebuf::underflow
virtual int underflow()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:135
n
int n
Definition: abseil-cpp/absl/container/btree_test.cc:1080
gzfilebuf::setcompression
int setcompression(int comp_level, int comp_strategy=Z_DEFAULT_STRATEGY)
Set compression level and strategy on the fly.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:43
gzifstream::close
void close()
Close gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:420
gzfilebuf
Gzipped file stream buffer class.
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.h:8
gzfilebuf::overflow
virtual int overflow(int=EOF)
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:173
gzomanip2::val2
T2 val2
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:433
func
const EVP_CIPHER *(* func)(void)
Definition: cipher_extra.c:73
gzfilebuf::is_open
int is_open() const
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.h:22
gzofstream::attach
void attach(int fd, std::ios_base::openmode mode=std::ios_base::out)
Attach to already open gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:464
gzofstream::is_open
bool is_open()
Check if file is open.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:359
setcompression
gzofstream & setcompression(gzofstream &gzs, int l, int s=Z_DEFAULT_STRATEGY)
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:440
re2::T2
@ T2
Definition: bloaty/third_party/re2/util/rune.cc:33
gzifstream::sb
gzfilebuf sb
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:312
gzfilebuf::io_mode
std::ios_base::openmode io_mode
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:191
gzifstream::is_open
bool is_open()
Check if file is open.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:270
gzofstream::rdbuf
gzfilebuf * rdbuf() const
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:351
gzifstream
Gzipped file input stream class.
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.h:68
gzfilebuf::own_buffer
bool own_buffer
True if this object owns stream buffer.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:223
gzofstream::close
void close()
Close gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:475
gzifstream::attach
void attach(int fd, std::ios_base::openmode mode=std::ios_base::in)
Attach to already open gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:409
gzifstream::open
void open(const char *name, std::ios_base::openmode mode=std::ios_base::in)
Open gzipped file.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.cc:398
run_grpclb_interop_tests.l
dictionary l
Definition: run_grpclb_interop_tests.py:410
regress.m
m
Definition: regress/regress.py:25
gzfilebuf::buffer_size
std::streamsize buffer_size
Stream buffer size.
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:215
gzfilebuf::open
gzfilebuf * open(const char *name, int io_mode)
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:18
Z_DEFAULT_STRATEGY
#define Z_DEFAULT_STRATEGY
Definition: bloaty/third_party/zlib/zlib.h:200
gzifstream::gzifstream
gzifstream()
Definition: bloaty/third_party/zlib/contrib/iostream/zfstream.cpp:291
gzifstream::rdbuf
gzfilebuf * rdbuf() const
Definition: bloaty/third_party/zlib/contrib/iostream3/zfstream.h:262
gzomanip2::operator<<
friend gzofstream & operator<<(gzofstream &, const gzomanip2< Ta, Tb > &)


grpc
Author(s):
autogenerated on Fri May 16 2025 03:01:01