1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 #ifndef ZYPP_BASE_FXSTREAM_H
10 #define ZYPP_BASE_FXSTREAM_H
18 * @short Common template to define ifgzstream/ofgzstream
19 * reading/writing compressed files.
21 * Don't use fXstream directly, but @ref ifgzstream or
22 * @ref ofgzstream. fXstream is just to avoid almost
25 template<class TBStream,class TStreamBuf>
26 class fXstream : public TBStream
30 using ZlibError = typename TStreamBuf::error_type;
31 using stream_type = TBStream;
32 using streambuf_type = TStreamBuf;
35 : stream_type( nullptr )
36 { this->init( &_streambuf ); }
39 fXstream( const char * file_r )
40 : stream_type( nullptr )
41 { this->init( &_streambuf ); this->open( file_r ); }
49 { return _streambuf.isOpen(); }
52 open( const char * file_r )
54 if ( !_streambuf.open( file_r, defMode(*this) ) )
55 this->setstate(std::ios_base::failbit);
63 if ( !_streambuf.close() )
64 this->setstate(std::ios_base::failbit);
68 * The last error returned retuned from zlib.
72 { return _streambuf.error(); }
74 //! Similar to ios::rdbuf.
75 //! But it returns our specific type, not the generic streambuf *.
78 { return _streambuf; }
82 streambuf_type _streambuf;
84 std::ios_base::openmode
85 defMode( const std::istream & )
86 { return std::ios_base::in; }
88 std::ios_base::openmode
89 defMode( const std::ostream & )
90 { return std::ios_base::out; }