libzypp  17.25.6
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
zypp::detail::fXstream::zError
ZlibError zError() const
The last error returned retuned from zlib.
Definition: fXstream.h:71
zypp::detail::fXstream::streambuf_type
TStreamBuf streambuf_type
Definition: fXstream.h:32
zypp::detail::fXstream::is_open
bool is_open() const
Definition: fXstream.h:48
zypp::detail::fXstream::fXstream
fXstream(const char *file_r)
Definition: fXstream.h:39
nullptr
#define nullptr
Definition: Easy.h:55
zypp::detail::fXstream::close
void close()
Definition: fXstream.h:61
zypp::detail::fXstream::~fXstream
virtual ~fXstream()
Definition: fXstream.h:44
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::detail::fXstream::ZlibError
typename TStreamBuf::error_type ZlibError
Definition: fXstream.h:30
zypp::detail::fXstream
Common template to define ifgzstream/ofgzstream reading/writing compressed files.
Definition: fXstream.h:27
zypp::detail::fXstream::open
void open(const char *file_r)
Definition: fXstream.h:52
TBStream
zypp::detail::fXstream::defMode
std::ios_base::openmode defMode(const std::ostream &)
Definition: fXstream.h:89
zypp::detail::fXstream::getbuf
const streambuf_type & getbuf() const
Similar to ios::rdbuf.
Definition: fXstream.h:77
zypp::detail::fXstream::_streambuf
streambuf_type _streambuf
Definition: fXstream.h:82
zypp::detail::fXstream::fXstream
fXstream()
Definition: fXstream.h:34
zypp::detail::fXstream::defMode
std::ios_base::openmode defMode(const std::istream &)
Definition: fXstream.h:85