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

libzypp 17.38.6

filestreambuf.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#ifndef ZYPP_CORE_BASE_FILESTREAMBUF_H
11#define ZYPP_CORE_BASE_FILESTREAMBUF_H
12
13#include <zypp-core/AutoDispose.h>
14#include <zypp-core/base/SimpleStreambuf>
15
16namespace zypp {
17 namespace detail {
18 class FdStreamBufImpl {
19 public:
20 FdStreamBufImpl() {}
21 ~FdStreamBufImpl() { closeImpl(); }
22
27 void disableAutoClose();
28
29 bool
30 isOpen () const
31 { return (_fd >= 0); }
32
33 bool
34 canRead () const
35 { return( _mode == std::ios_base::in ); }
36
37 bool
38 canWrite () const
39 { return( _mode == std::ios_base::out ); }
40
41 bool canSeek ( std::ios_base::seekdir way_r ) const {
42 // we could implement seek for regular files, in that case openImpl should
43 // check for the file type using fstat and S_ISREG
44 return false;
45 }
46
47 std::streamsize readData ( char * buffer_r, std::streamsize maxcount_r );
48
49 bool writeData( const char * buffer_r, std::streamsize count_r );
50
51 off_t seekTo( off_t off_r, std::ios_base::seekdir way_r, std::ios_base::openmode omode_r ) {
52 return -1;
53 }
54
55 off_t tell() const {
56 return -1;
57 }
58
59 protected:
60 bool openImpl( int fd, std::ios_base::openmode mode_r );
61 bool closeImpl (); // closes the file
62
63 private:
64 zypp::AutoFD _fd = -1;
65 std::ios_base::openmode _mode = std::ios_base::openmode(0);
66 };
67 }
68
69 using FdStreamBuf = detail::SimpleStreamBuf<detail::FdStreamBufImpl>;
70}
71#endif // ZYPP_CORE_BASE_FILESTREAMBUF_H
AutoDispose.h
zypp::detail::FdStreamBufImpl::seekTo
off_t seekTo(off_t off_r, std::ios_base::seekdir way_r, std::ios_base::openmode omode_r)
Definition filestreambuf.h:51
zypp::detail::FdStreamBufImpl::disableAutoClose
void disableAutoClose()
Definition filestreambuf.cc:15
zypp::detail::FdStreamBufImpl::readData
std::streamsize readData(char *buffer_r, std::streamsize maxcount_r)
Definition filestreambuf.cc:20
zypp::detail::FdStreamBufImpl::FdStreamBufImpl
FdStreamBufImpl()
Definition filestreambuf.h:20
zypp::detail::FdStreamBufImpl::_fd
zypp::AutoFD _fd
Definition filestreambuf.h:64
zypp::detail::FdStreamBufImpl::canRead
bool canRead() const
Definition filestreambuf.h:34
zypp::detail::FdStreamBufImpl::_mode
std::ios_base::openmode _mode
Definition filestreambuf.h:65
zypp::detail::FdStreamBufImpl::tell
off_t tell() const
Definition filestreambuf.h:55
zypp::detail::FdStreamBufImpl::closeImpl
bool closeImpl()
Definition filestreambuf.cc:55
zypp::detail::FdStreamBufImpl::writeData
bool writeData(const char *buffer_r, std::streamsize count_r)
Definition filestreambuf.cc:32
zypp::detail::FdStreamBufImpl::~FdStreamBufImpl
~FdStreamBufImpl()
Definition filestreambuf.h:21
zypp::detail::FdStreamBufImpl::isOpen
bool isOpen() const
Definition filestreambuf.h:30
zypp::detail::FdStreamBufImpl::canWrite
bool canWrite() const
Definition filestreambuf.h:38
zypp::detail::FdStreamBufImpl::canSeek
bool canSeek(std::ios_base::seekdir way_r) const
Definition filestreambuf.h:41
zypp::detail::FdStreamBufImpl::openImpl
bool openImpl(int fd, std::ios_base::openmode mode_r)
Definition filestreambuf.cc:48
zypp::detail::SimpleStreamBuf
Definition simplestreambuf.h:55
zypp::detail
Definition PoolQuery.cc:1509
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::FdStreamBuf
detail::SimpleStreamBuf< detail::FdStreamBufImpl > FdStreamBuf
Definition filestreambuf.h:69
zypp::AutoFD
AutoDispose<int> calling close
Definition AutoDispose.h:310