12#ifndef ZYPP_CORE_BASE_SIMPLESTREAMBUF_H_DEFINED
13#define ZYPP_CORE_BASE_SIMPLESTREAMBUF_H_DEFINED
53 template<
typename Impl>
64 if ( !this->openImpl( name_r, mode_r ) )
67 if ( this->canRead() ) {
72 setg( NULL, NULL, NULL );
80 if ( !this->isOpen() )
83 if ( this->canWrite() )
86 if ( !this->closeImpl() )
96 if ( pbase() < pptr() ) {
98 if ( traits_type::eq_int_type( res, traits_type::eof() ) )
104 virtual int_type
overflow( int_type c = traits_type::eof() ) {
105 int_type ret = traits_type::eof();
106 if ( this->canWrite() ) {
107 if ( ! traits_type::eq_int_type( c, traits_type::eof() ) )
109 *pptr() = traits_type::to_char_type( c );
112 if ( pbase() <= pptr() )
114 if ( this->writeData( pbase(), pptr() - pbase() ) )
117 ret = traits_type::not_eof( c );
126 int_type ret = traits_type::eof();
127 if ( this->canRead() )
129 if ( gptr() < egptr() )
130 return traits_type::to_int_type( *gptr() );
132 const std::streamsize got = this->readData( &(
_buffer[0]),
_buffer.size() );
136 ret = traits_type::to_int_type( *gptr() );
148 virtual pos_type
seekpos( pos_type pos_r, std::ios_base::openmode openMode ) {
149 return seekoff( off_type(pos_r), std::ios_base::beg, openMode );
153 virtual pos_type
seekoff( off_type off_r, std::ios_base::seekdir way_r, std::ios_base::openmode openMode ) {
154 pos_type ret = pos_type(off_type(-1));
155 if ( !this->canSeek( way_r) )
158 if ( this->isOpen() ) {
159 if ( openMode == std::ios_base::out ) {
161 if ( !this->canWrite() ||
sync() != 0 )
164 ret = this->seekTo( off_r, way_r, openMode );
166 }
else if ( openMode == std::ios_base::in ) {
167 if ( !this->canRead() )
171 const off_type buffEndOff = this->tell();
173 if ( buffEndOff != off_type(-1) ) {
174 if ( way_r == std::ios_base::end ) {
176 ret = this->seekTo( off_r, way_r, openMode );
179 const off_type bufLen = egptr() - eback();
180 const off_type bufStartFileOff = buffEndOff - bufLen;
181 const off_type currPtrFileOffset = buffEndOff - ( egptr() - gptr() );
182 off_type newFOff = off_r;
185 if ( way_r == std::ios_base::cur ) {
186 newFOff += currPtrFileOffset;
187 way_r = std::ios_base::beg;
191 if ( way_r == std::ios_base::beg ) {
192 if ( bufStartFileOff <= newFOff && newFOff <= buffEndOff ) {
196 eback() + ( newFOff - bufStartFileOff ),
198 ret = pos_type( newFOff );
202 ret = this->seekTo( off_r, way_r, openMode );
RepoManager implementation.
SimpleStreamBuf * close()
std::vector< char > buffer_type
virtual ~SimpleStreamBuf()
virtual pos_type seekoff(off_type off_r, std::ios_base::seekdir way_r, std::ios_base::openmode openMode)
virtual int_type overflow(int_type c=traits_type::eof())
virtual int_type underflow()
SimpleStreamBuf(size_t bufsize_r=512)
virtual pos_type seekpos(pos_type pos_r, std::ios_base::openmode openMode)
SimpleStreamBuf * open(const char *name_r, std::ios_base::openmode mode_r=std::ios_base::in)
Easy-to use interface to the ZYPP dependency resolver.