12 #ifndef ZYPP_CORE_BASE_SIMPLESTREAMBUF_H_DEFINED 13 #define ZYPP_CORE_BASE_SIMPLESTREAMBUF_H_DEFINED 53 template<
typename Impl>
62 template <
typename OpenSpecType>
65 if ( !this->openImpl( std::forward<OpenSpecType>(name_r), mode_r ) )
68 if ( this->canRead() ) {
73 setg( NULL, NULL, NULL );
81 if ( !this->isOpen() )
84 if ( this->canWrite() )
87 if ( !this->closeImpl() )
97 if ( pbase() < pptr() ) {
99 if ( traits_type::eq_int_type( res, traits_type::eof() ) )
105 int_type
overflow( int_type c = traits_type::eof() )
override {
106 int_type ret = traits_type::eof();
107 if ( this->canWrite() ) {
108 if ( ! traits_type::eq_int_type( c, traits_type::eof() ) )
110 *pptr() = traits_type::to_char_type( c );
113 if ( pbase() <= pptr() )
115 if ( this->writeData( pbase(), pptr() - pbase() ) )
118 ret = traits_type::not_eof( c );
127 int_type ret = traits_type::eof();
128 if ( this->canRead() )
130 if ( gptr() < egptr() )
131 return traits_type::to_int_type( *gptr() );
133 const std::streamsize got = this->readData( &(
_buffer[0]),
_buffer.size() );
137 ret = traits_type::to_int_type( *gptr() );
149 pos_type
seekpos( pos_type pos_r, std::ios_base::openmode openMode )
override {
150 return seekoff( off_type(pos_r), std::ios_base::beg, openMode );
154 pos_type
seekoff( off_type off_r, std::ios_base::seekdir way_r, std::ios_base::openmode openMode )
override {
155 pos_type ret = pos_type(off_type(-1));
156 if ( !this->canSeek( way_r) )
159 if ( this->isOpen() ) {
160 if ( openMode == std::ios_base::out ) {
162 if ( !this->canWrite() ||
sync() != 0 )
165 ret = this->seekTo( off_r, way_r, openMode );
167 }
else if ( openMode == std::ios_base::in ) {
168 if ( !this->canRead() )
172 const off_type buffEndOff = this->tell();
174 if ( buffEndOff != off_type(-1) ) {
175 if ( way_r == std::ios_base::end ) {
177 ret = this->seekTo( off_r, way_r, openMode );
180 const off_type bufLen = egptr() - eback();
181 const off_type bufStartFileOff = buffEndOff - bufLen;
182 const off_type currPtrFileOffset = buffEndOff - ( egptr() - gptr() );
183 off_type newFOff = off_r;
186 if ( way_r == std::ios_base::cur ) {
187 newFOff += currPtrFileOffset;
188 way_r = std::ios_base::beg;
192 if ( way_r == std::ios_base::beg ) {
193 if ( bufStartFileOff <= newFOff && newFOff <= buffEndOff ) {
197 eback() + ( newFOff - bufStartFileOff ),
199 ret = pos_type( newFOff );
203 ret = this->seekTo( off_r, way_r, openMode );
~SimpleStreamBuf() override
SimpleStreamBuf(size_t bufsize_r=512)
int_type underflow() override
SimpleStreamBuf * close()
pos_type seekpos(pos_type pos_r, std::ios_base::openmode openMode) override
int_type overflow(int_type c=traits_type::eof()) override
std::vector< char > buffer_type
pos_type seekoff(off_type off_r, std::ios_base::seekdir way_r, std::ios_base::openmode openMode) override
Easy-to use interface to the ZYPP dependency resolver.
SimpleStreamBuf * open(OpenSpecType &&name_r, std::ios_base::openmode mode_r=std::ios_base::in)