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