libzypp  17.24.1
fXstream.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 #ifndef ZYPP_BASE_FXSTREAM_H
10 #define ZYPP_BASE_FXSTREAM_H
11 
12 #include <iosfwd>
13 #include <iostream>
14 
15 namespace zypp {
16  namespace detail {
25  template<class TBStream,class TStreamBuf>
26  class fXstream : public TBStream
27  {
28  public:
29 
30  using ZlibError = typename TStreamBuf::error_type;
32  using streambuf_type = TStreamBuf;
33 
35  : stream_type( nullptr )
36  { this->init( &_streambuf ); }
37 
38  explicit
39  fXstream( const char * file_r )
40  : stream_type( nullptr )
41  { this->init( &_streambuf ); this->open( file_r ); }
42 
43  virtual
45  {}
46 
47  bool
48  is_open() const
49  { return _streambuf.isOpen(); }
50 
51  void
52  open( const char * file_r )
53  {
54  if ( !_streambuf.open( file_r, defMode(*this) ) )
55  this->setstate(std::ios_base::failbit);
56  else
57  this->clear();
58  }
59 
60  void
62  {
63  if ( !_streambuf.close() )
64  this->setstate(std::ios_base::failbit);
65  }
66 
70  ZlibError
71  zError() const
72  { return _streambuf.error(); }
73 
76  const streambuf_type&
77  getbuf() const
78  { return _streambuf; }
79 
80  private:
81 
83 
84  std::ios_base::openmode
85  defMode( const std::istream & )
86  { return std::ios_base::in; }
87 
88  std::ios_base::openmode
89  defMode( const std::ostream & )
90  { return std::ios_base::out; }
91 
92  };
93  }
94 }
95 
96 #endif
bool is_open() const
Definition: fXstream.h:48
ZlibError zError() const
The last error returned retuned from zlib.
Definition: fXstream.h:71
fXstream(const char *file_r)
Definition: fXstream.h:39
TStreamBuf streambuf_type
Definition: fXstream.h:32
Common template to define ifgzstream/ofgzstream reading/writing compressed files. ...
Definition: fXstream.h:26
virtual ~fXstream()
Definition: fXstream.h:44
#define nullptr
Definition: Easy.h:55
typename TStreamBuf::error_type ZlibError
Definition: fXstream.h:30
void open(const char *file_r)
Definition: fXstream.h:52
const streambuf_type & getbuf() const
Similar to ios::rdbuf.
Definition: fXstream.h:77
std::ios_base::openmode defMode(const std::istream &)
Definition: fXstream.h:85
std::ios_base::openmode defMode(const std::ostream &)
Definition: fXstream.h:89
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
streambuf_type _streambuf
Definition: fXstream.h:82