libzypp: zypp-core/base/fxstream.h Source File

libzypp 17.38.14

fxstream.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#ifndef ZYPP_CORE_BASE_FXSTREAM_H
10#define ZYPP_CORE_BASE_FXSTREAM_H
11
12#include <iosfwd>
13#include <iostream>
14
15namespace 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;
31 using stream_type = TBStream;
32 using streambuf_type = TStreamBuf;
33
34 fXstream()
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
44 ~fXstream()
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
61 close()
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
82 streambuf_type _streambuf;
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
TBStream
zypp::detail::fXstream< std::istream, gzstream_detail::fgzstreambuf >::defMode
std::ios_base::openmode defMode(const std::istream &)
Definition fxstream.h:85
zypp::detail::fXstream::zError
ZlibError zError() const
The last error returned retuned from zlib.
Definition fxstream.h:71
zypp::detail::fXstream::is_open
bool is_open() const
Definition fxstream.h:48
zypp::detail::fXstream::getbuf
const streambuf_type & getbuf() const
Definition fxstream.h:77
zypp::detail::fXstream::defMode
std::ios_base::openmode defMode(const std::ostream &)
Definition fxstream.h:89
zypp::detail::fXstream::~fXstream
virtual ~fXstream()
Definition fxstream.h:44
zypp::detail::fXstream::streambuf_type
TStreamBuf streambuf_type
Definition fxstream.h:32
zypp::detail::fXstream::fXstream
fXstream(const char *file_r)
Definition fxstream.h:39
zypp::detail::fXstream::fXstream
fXstream()
Definition fxstream.h:34
zypp::detail::fXstream::ZlibError
typename TStreamBuf::error_type ZlibError
Definition fxstream.h:30
zypp::detail::fXstream< std::istream, gzstream_detail::fgzstreambuf >::_streambuf
streambuf_type _streambuf
Definition fxstream.h:82
zypp::detail::fXstream::open
void open(const char *file_r)
Definition fxstream.h:52
zypp::detail::fXstream::close
void close()
Definition fxstream.h:61
zypp::detail::fXstream::stream_type
TBStream stream_type
Definition fxstream.h:31
zypp::detail
Definition PoolQuery.cc:1509
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2