FileStreamBuf::pos_type FileStreamBuf::seekoff(off_type offset, std::ios_base::seekdir whence, std::ios_base::openmode mode) { if(!usrFile || (mode&std::ios_base::out)) return traits_type::eof(); pos_type pos = traits_type::eof(); switch(whence) { case std::ios_base::beg: if(offset == off_type(alureInt64(offset))) pos = pos_type(fio.seek(usrFile, offset, SEEK_SET)); break; case std::ios_base::cur: offset -= off_type(egptr()-gptr()); if(offset == off_type(alureInt64(offset))) pos = pos_type(fio.seek(usrFile, offset, SEEK_CUR)); break; case std::ios_base::end: if(offset == off_type(alureInt64(offset))) pos = pos_type(fio.seek(usrFile, offset, SEEK_END)); break; default: break; } if(pos >= 0) setg(0, 0, 0); return pos; }
typename parser_buf<charT, traits>::pos_type parser_buf<charT, traits>::seekpos(pos_type sp, ::std::ios_base::openmode which) { if(which & ::std::ios_base::out) return pos_type(off_type(-1)); off_type size = static_cast<off_type>(this->egptr() - this->eback()); charT* g = this->eback(); if(off_type(sp) <= size) { this->setg(g, g + off_type(sp), g + size); } return pos_type(off_type(-1)); }
IFileStreambuf::pos_type IFileStreambuf::seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode mode) { off_type pos = off; PHYSFS_sint64 ptell = PHYSFS_tell(file); switch(dir) { case std::ios_base::beg: break; case std::ios_base::cur: if(off == 0) return static_cast<pos_type> (ptell) - static_cast<pos_type> (egptr() - gptr()); pos += static_cast<off_type> (ptell) - static_cast<off_type> (egptr() - gptr()); break; case std::ios_base::end: pos += static_cast<off_type> (PHYSFS_fileLength(file)); break; default: assert(false); return pos_type(off_type(-1)); } return seekpos(static_cast<pos_type> (pos), mode); }
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) override { // We only have a get area, so no put area (= out) operations. if ((which & std::ios_base::out) == std::ios_base::out) return pos_type(off_type(-1)); return this->default_seekoff(off, dir, which); }
std::streambuf::pos_type DataIStreamBuf::seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) { pos_type ret = pos_type(off_type(-1)); char* begin = eback(); char* cur = gptr(); char* end = egptr(); off_type newOff = 0; if (way == std::ios_base::cur) { newOff = cur - begin; } else if (way == std::ios_base::end) { newOff = end - begin; } if (newOff + off >= 0 && end - begin >= newOff + off) { setg(begin, begin + newOff + off, end); ret = pos_type(newOff); } return ret; }
strstreambuf::pos_type strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which) { off_type __p(-1); bool pos_in = (__which & ios::in) != 0; bool pos_out = (__which & ios::out) != 0; bool legal = false; switch (__way) { case ios::beg: case ios::end: if (pos_in || pos_out) legal = true; break; case ios::cur: if (pos_in != pos_out) legal = true; break; } if (pos_in && gptr() == nullptr) legal = false; if (pos_out && pptr() == nullptr) legal = false; if (legal) { off_type newoff; char* seekhigh = epptr() ? epptr() : egptr(); switch (__way) { case ios::beg: newoff = 0; break; case ios::cur: newoff = (pos_in ? gptr() : pptr()) - eback(); break; case ios::end: newoff = seekhigh - eback(); break; default: return pos_type(off_type(-1)); } newoff += __off; if (0 <= newoff && newoff <= seekhigh - eback()) { char* newpos = eback() + newoff; if (pos_in) setg(eback(), newpos, _VSTD::max(newpos, egptr())); if (pos_out) { // min(pbase, newpos), newpos, epptr() __off = epptr() - newpos; setp(min(pbase(), newpos), epptr()); pbump(static_cast<int>((epptr() - pbase()) - __off)); } __p = newoff; } } return pos_type(__p); }
pos_type seekpos(pos_type pos, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override { // We only have a get area, so no put area (= out) operations. if ((which & std::ios_base::out) == std::ios_base::out) return pos_type(off_type(-1)); return this->default_seekpos(pos, which); }
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out ) { if (dir == std::ios_base::beg) current_ = std::min(begin_ + off, end_); else if (dir == std::ios_base::cur) current_ = std::min(current_ + off, end_); else current_ = std::max(end_ - off, begin_); // dir == std::ios_base::end return pos_type(off_type(current_ - begin_)); }
pos_type default_seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode which) { auto new_off = pos_type(off_type(-1)); auto get = (which & std::ios_base::in) == std::ios_base::in; auto put = (which & std::ios_base::out) == std::ios_base::out; if (!(get || put)) return new_off; // nothing to do if (get) { switch (dir) { default: return pos_type(off_type(-1)); case std::ios_base::beg: new_off = 0; break; case std::ios_base::cur: new_off = this->gptr() - this->eback(); break; case std::ios_base::end: new_off = this->egptr() - this->eback(); break; } new_off += off; this->setg(this->eback(), this->eback() + new_off, this->egptr()); } if (put) { switch (dir) { default: return pos_type(off_type(-1)); case std::ios_base::beg: new_off = 0; break; case std::ios_base::cur: new_off = this->pptr() - this->pbase(); break; case std::ios_base::end: new_off = this->egptr() - this->pbase(); break; } new_off += off; this->setp(this->pbase(), this->epptr()); safe_pbump(new_off); } return new_off; }
typename parser_buf<charT, traits>::pos_type parser_buf<charT, traits>::seekoff(off_type off, ::std::ios_base::seekdir way, ::std::ios_base::openmode which) { typedef typename boost::int_t<sizeof(way) * CHAR_BIT>::least cast_type; if(which & ::std::ios_base::out) return pos_type(off_type(-1)); std::ptrdiff_t size = this->egptr() - this->eback(); std::ptrdiff_t pos = this->gptr() - this->eback(); charT* g = this->eback(); switch(static_cast<cast_type>(way)) { case ::std::ios_base::beg: if((off < 0) || (off > size)) return pos_type(off_type(-1)); else this->setg(g, g + off, g + size); break; case ::std::ios_base::end: if((off < 0) || (off > size)) return pos_type(off_type(-1)); else this->setg(g, g + size - off, g + size); break; case ::std::ios_base::cur: { std::ptrdiff_t newpos = static_cast<std::ptrdiff_t>(pos + off); if((newpos < 0) || (newpos > size)) return pos_type(off_type(-1)); else this->setg(g, g + newpos, g + size); break; } default: ; } #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4244) #endif return static_cast<pos_type>(this->gptr() - this->eback()); #ifdef BOOST_MSVC #pragma warning(pop) #endif }
IFileStreambuf::pos_type IFileStreambuf::seekpos(pos_type pos, std::ios_base::openmode) { if(PHYSFS_seek(file, static_cast<PHYSFS_uint64> (pos)) == 0) { return pos_type(off_type(-1)); } // the seek invalidated the buffer setg(buf, buf, buf); return pos; }
pos_type default_seekpos(pos_type pos, std::ios_base::openmode which) { auto get = (which & std::ios_base::in) == std::ios_base::in; auto put = (which & std::ios_base::out) == std::ios_base::out; if (!(get || put)) return pos_type(off_type(-1)); // nothing to do if (get) this->setg(this->eback(), this->eback() + pos, this->egptr()); if (put) { this->setp(this->pbase(), this->epptr()); safe_pbump(pos); } return pos; }
std::streampos tellg() { ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit); pos_type p = pos_type(off_type(-1)); try { if (!this->fail()) { if (is_ram_file(m_file)) { p = ((ram_filebuf*)m_streambuf)->pubseekoff(0, std::ios_base::cur); } else { p = ((std::filebuf*)m_streambuf)->pubseekoff(0, std::ios_base::cur); } if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; } } } catch (...) { if (err) { this->setstate(err); } } return p; }
inline typename basic_dbgstreambuf<elem_t, traits_t>::pos_type basic_dbgstreambuf<elem_t, traits_t>::seekoff( off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) { off_type pos = -1; if (which & std::ios_base::out) { const ptrdiff_t buflen = epptr() - pbase(); switch (way) { case std::ios_base::beg: pos = off; break; case std::ios_base::cur: pos = off_type(ppos()) + off; break; case std::ios_base::end: pos = off_type(buflen) + off; break; } if (pos < 0) pos = -1; else if (pos > off_type(buflen)) pos = -1; else ppos(pos); } return pos; }
std::streambuf::pos_type DataIStreamBuf::seekpos(pos_type sp, std::ios_base::openmode which) { pos_type ret = pos_type(off_type(-1)); char* begin = eback(); char* end = egptr(); if (sp <= end - begin) { setg(begin, begin + sp, end); ret = sp; } return ret; }
pos_type seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which) { if (file && off == 0 && way == std::ios_base::cur && which == std::ios_base::out) { #if ZLIB_VERNUM >= 0x1240 // gzoffset is only available in zlib 1.2.4 or later return pos_type(gzoffset(file)); #else // return an approximation of file size (only used in progress dialog) z_off_t offset = gztell(file); if (offset > 0) offset /= 4; return pos_type(offset); #endif } return pos_type(off_type(-1)); }
std::streampos SimpleStreamBuf::seekpos(std::streampos pos, std::ios_base::openmode which) { size_t maxSeek = pptr() - m_buffer; assert(static_cast<size_t>(pos) <= maxSeek); if (static_cast<size_t>(pos) > maxSeek) { return pos_type(off_type(-1)); } if (which == std::ios_base::in) { setg(m_buffer, m_buffer + static_cast<size_t>(pos), pptr()); } if (which == std::ios_base::out) { setp(m_buffer + static_cast<size_t>(pos), epptr()); } return pos; }
std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::seekdir way, std::ios_base::openmode which) { /* A bit of explanation: We are reading file by m_bufferSize parts so our 3 internal pointers will be * eback (not used here) - start of block * gptr - position of read cursor in block * egtpr - end of block off argument is relative to way */ std::streamoff new_position{}; switch (way) { case std::ios_base::beg: new_position = off; break; case std::ios_base::cur: // tell will give cursor at begining of block so we have to add where in block we currently are new_position = off + static_cast<off_type>(PHYSFS_tell(m_file)) - static_cast<off_type> (egptr() - gptr()); break; case std::ios_base::end: new_position = off + static_cast<off_type>(PHYSFS_fileLength(m_file)); break; default: break; } if (PHYSFS_seek(m_file, new_position)) { setg(m_buffer.get(), m_buffer.get(), m_buffer.get()); // reset buffer return pos_type(new_position); } return pos_type(off_type(-1)); }
inline typename basic_dbgstreambuf<elem_t, traits_t>::pos_type basic_dbgstreambuf<elem_t, traits_t>::seekpos( pos_type pos_, std::ios_base::openmode which) { off_type pos = -1; if (which & std::ios_base::out) { pos = pos_; const ptrdiff_t buflen = epptr() - pbase(); if (pos < 0) pos = -1; else if (pos > off_type(buflen)) pos = -1; else ppos(pos); } return pos; }
isfstream& seekg(off_type off, ios_base::seekdir way) { ios_base::iostate err = std::ios_base::iostate(ios_base::goodbit); try { if (!this->fail()) { pos_type p = 0; if (is_ram_file(m_file)) { p = ((ram_filebuf*)m_streambuf)->pubseekoff(off, way, std::ios_base::in); } else { p = ((std::filebuf*)m_streambuf)->pubseekoff(off, way, std::ios_base::in); } if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; } } } catch (...) { if (err) { this->setstate(err); } } return *this; }
osfstream& seekp(pos_type pos) { ios_base::iostate err = std::ios_base::iostate(std::ios_base::goodbit); try { if (!this->fail()) { pos_type p = 0; if (is_ram_file(m_file)) { p = ((ram_filebuf*)m_streambuf)->pubseekpos(pos, std::ios_base::out); } else { p = ((std::filebuf*)m_streambuf)->pubseekpos(pos, std::ios_base::out); } if (p == pos_type(off_type(-1))) { err |= ios_base::failbit; this->setstate(err); } } } catch (...) { if (err) { this->setstate(err); } } return *this; }
std::streampos SimpleStreamBuf::seekoff(std::streamoff off, std::ios_base::seekdir dir, std::ios_base::openmode which) { if (dir == std::ios_base::beg) { return seekpos(off, which); } else if (dir == std::ios_base::end) { return seekpos((pptr() - m_buffer) - off, which); } else if (dir == std::ios_base::cur) { if(which == std::ios_base::in) { return seekpos((gptr() - m_buffer) + off, which); } else { return seekpos((pptr() - m_buffer) + off, which); } } return off_type(-1); }
FileStreamBuf::pos_type FileStreamBuf::seekpos(pos_type pos, std::ios_base::openmode mode) { if(pos != pos_type(off_type(pos))) return traits_type::eof(); return seekoff(off_type(pos), std::ios_base::beg, mode); }
strstreambuf::pos_type strstreambuf::seekpos(pos_type pos, ios_base::openmode mode) { return seekoff(pos - pos_type(off_type(0)), ios_base::beg, mode); }
strstreambuf::pos_type strstreambuf::seekoff(off_type off, ios_base::seekdir dir, ios_base::openmode mode) { bool do_get = false; bool do_put = false; if ((mode & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out) && (dir == ios_base::beg || dir == ios_base::end)) do_get = do_put = true; else if (mode & ios_base::in) do_get = true; else if (mode & ios_base::out) do_put = true; // !gptr() is here because, according to D.7.1 paragraph 4, the seekable // area is undefined if there is no get area. if ((!do_get && !do_put) || (do_put && !pptr()) || !gptr()) return pos_type(off_type(-1)); char* seeklow = eback(); char* seekhigh = epptr() ? epptr() : egptr(); off_type newoff; switch(dir) { case ios_base::beg: newoff = 0; break; case ios_base::end: newoff = seekhigh - seeklow; break; case ios_base::cur: newoff = do_put ? pptr() - seeklow : gptr() - seeklow; break; default: return pos_type(off_type(-1)); } off += newoff; if (off < 0 || off > seekhigh - seeklow) return pos_type(off_type(-1)); if (do_put) { if (seeklow + __STATIC_CAST(ptrdiff_t, off) < pbase()) { setp(seeklow, epptr()); pbump((int)off); } else { setp(pbase(), epptr()); pbump((int)(off - (pbase() - seeklow))); } } if (do_get) { if (off <= egptr() - seeklow) setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), egptr()); else if (off <= pptr() - seeklow) setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), pptr()); else setg(seeklow, seeklow + __STATIC_CAST(ptrdiff_t, off), epptr()); } return pos_type(newoff); }
std::streampos CInputStreamBuffer::seekpos(std::streampos sp, std::ios_base::openmode which) { return seekoff(off_type(sp), std::ios_base::beg, which); }
/* virtual */ strstreambuf::pos_type strstreambuf::seekoff (off_type off, ios::seekdir way, ios::openmode which) { _RWSTD_ASSERT (_C_is_valid ()); // should implicitly hold as long as ios::seekdir is an enum _RWSTD_ASSERT (ios::beg == way || ios::cur == way || ios::end == way); _RWSTD_ASSERT (_C_is_valid ()); // determine seekable area - D.7.1, p4 char* const seeklo = eback (); char* const seekhi = epptr () ? epptr () : egptr (); const char* const xnext = which & ios::in ? gptr () : pptr (); const char* const xbeg = which & ios::in ? eback () : pbase (); // D.7.1.3, p13 if (!xnext) return pos_type (off_type (-1)); off_type saved_off = off; // compute new offset - D.7.1.3, p13, table 105 if (ios::cur == way) off += off_type (xnext - xbeg); else if (ios::end == way) off += off_type (seekhi - xbeg); // test conditions in D.7.1.3, p13, table 105, row 4 if (off < seeklo - xbeg || off > seekhi - xbeg) off = -1; // failure else if (which & ios::in) { // position input sequence // fail if `way' is `cur', otherwise position output sequence first if ( which & ios::out && ( way == ios::cur || pos_type (-1) == seekoff (saved_off, way, ios::out))) return pos_type (off_type (-1)); // adjust input sequence as necessary to maintain invariant if (off <= egptr () - eback ()) setg (eback (), eback () + off, egptr ()); else if (off <= pptr () - egptr ()) // advance egptr() setg (eback (), eback () + off, pptr ()); else // advance egptr() even further setg (eback (), eback () + off, epptr ()); } else if (which & ios::out) { // position output sequence if (seeklo + off < pbase ()) { // adjust beginning of output sequence, then increment pptr() setp (seeklo, epptr ()); pbump (off); } else { // reset pptr() first, then increment it by offset setp (pbase (), epptr ()); pbump (off - (pbase () - seeklo)); } } else off = -1; // failure _RWSTD_ASSERT (_C_is_valid ()); return pos_type (off); }