本文整理汇总了C++中egptr函数的典型用法代码示例。如果您正苦于以下问题:C++ egptr函数的具体用法?C++ egptr怎么用?C++ egptr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了egptr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: switch
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;
}
示例2: sync
std::streampos FileStreamBuf::seekoff(std::streamoff off, std::ios::seekdir dir, std::ios::openmode mode)
{
if (_fd == -1 || !(getMode() & mode))
return -1;
if (getMode() & std::ios::out)
sync();
std::streamoff adj;
if (mode & std::ios::in)
adj = static_cast<std::streamoff>(egptr() - gptr());
else
adj = 0;
resetBuffers();
int whence = SEEK_SET;
if (dir == std::ios::cur)
{
whence = SEEK_CUR;
off -= adj;
}
else if (dir == std::ios::end)
{
whence = SEEK_END;
}
_pos = lseek(_fd, off, whence);
return _pos;
}
示例3: gptr
int filebuf::sync()
{
// char* ptr = cur_ptr();
if (pptr() > pbase())
if (do_flush()) return EOF;
if (gptr() != egptr()) {
streampos delta = gptr() - egptr();
if (in_backup())
delta -= eGptr() - Gbase();
if (sys_seek(delta, ios::cur) == EOF)
return EOF;
}
// FIXME: Cleanup - can this be shared?
// setg(base(), ptr, ptr);
return 0;
}
示例4: LOG
//read to buffer in place (apart from data already buffered)
std::streamsize istreambuf::xsgetn(char *buffer, std::streamsize n) {
LOG("bz::istreambuf::xsgetn (" << n << ")");
//try to satisfy request from buffered input
std::streamsize available = egptr() - gptr();
int read = (available >= n)? n : available;
if (read) {
std::copy(gptr(), gptr() + read, buffer);
gbump(read);
}
//inflate the rest directly into the user's buffer
if (read < n) {
if (end) {
LOG("\tend of stream (EOF)");
//signal the stream has reached it's end
return eof;
}
z_strm->next_out = buffer + read;
z_strm->avail_out = n - read;
if (0 < z_strm->avail_in) {
decompress();
}
while (!(end || 0 == z_strm->avail_out)) {
read_decompress();
}
underflow();
}
return n;
}
示例5: switch
ConstrainedFileStreamBuf::pos_type ConstrainedFileStreamBuf::seekoff(off_type offset, std::ios_base::seekdir whence, std::ios_base::openmode mode)
{
if((mode&std::ios_base::out) || !(mode&std::ios_base::in))
return traits_type::eof();
// new file position, relative to mOrigin
std::streampos newPos = traits_type::eof();
switch(whence)
{
case std::ios_base::beg:
newPos = offset + mStart;
break;
case std::ios_base::cur:
newPos = offset + mFile->tellg() - (egptr()-gptr());
break;
case std::ios_base::end:
newPos = offset + mEnd;
break;
default:
return traits_type::eof();
}
if(newPos < mStart || newPos > mEnd)
return traits_type::eof();
if(!mFile->seekg(newPos))
return traits_type::eof();
// Clear read pointers so underflow() gets called on the next read attempt.
setg(0, 0, 0);
return newPos - mStart;
}
示例6: pos_type
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;
}
示例7: allocate
int strstreambuf::overflow(int c)
{
/*
- if no room and not dynamic, give error
- if no room and dynamic, allocate (1 more or min) and store
- if and when the buffer has room, store c if not EOF
*/
int temp;
if (pptr() >= epptr())
{
if (!x_dynamic)
return EOF;
if (strstreambuf::doallocate()==EOF)
return EOF;
if (!epptr()) // init if first time through
{
setp(base() + (egptr() - eback()),ebuf());
}
else
{
temp = pptr()-pbase();
setp(pbase(),ebuf());
pbump(temp);
}
}
if (c!=EOF)
{
*pptr() = (char)c;
pbump(1);
}
return(1);
}
示例8: underflow
// input functions
int_type underflow(
)
{
if (gptr() < egptr())
{
return static_cast<unsigned char>(*gptr());
}
int num_put_back = static_cast<int>(gptr() - eback());
if (num_put_back > max_putback)
{
num_put_back = max_putback;
}
// copy the putback characters into the putback end of the in_buffer
std::memmove(in_buffer+(max_putback-num_put_back), gptr()-num_put_back, num_put_back);
if (read_echoing_select(fd, fd_printf))
return EOF;
int num = read(fd,in_buffer+max_putback, in_buffer_size-max_putback);
if (num <= 0)
{
// an error occurred or the connection is over which is EOF
return EOF;
}
// reset in_buffer pointers
setg (in_buffer+(max_putback-num_put_back),
in_buffer+max_putback,
in_buffer+max_putback+num);
return static_cast<unsigned char>(*gptr());
}
示例9: seekoff
virtual pos_type seekoff(off_type offset, std::ios_base::seekdir whence, std::ios_base::openmode mode)
{
if((mode&std::ios_base::out) || !(mode&std::ios_base::in))
return traits_type::eof();
// new file position, relative to mOrigin
size_t newPos;
switch (whence)
{
case std::ios_base::beg:
newPos = offset;
break;
case std::ios_base::cur:
newPos = (mFile.tell() - mOrigin - (egptr() - gptr())) + offset;
break;
case std::ios_base::end:
newPos = mSize + offset;
break;
default:
return traits_type::eof();
}
if (newPos > mSize)
return traits_type::eof();
mFile.seek(mOrigin+newPos);
// Clear read pointers so underflow() gets called on the next read attempt.
setg(0, 0, 0);
return newPos;
}
示例10: underflow
int func_parsebuf::underflow()
{
retry:
if (gptr() < egptr())
return *gptr();
if (gptr() != (char*)NewLine+1) {
// Get buffer was line buffer. Move to following '\n'.
setg((char*)NewLine, (char*)NewLine, (char*)NewLine+1);
return *gptr();
}
if (backed_up_to_newline)
// Get buffer was '\n' preceding current line. Move to current line.
backed_up_to_newline = 0;
else {
// Get buffer was '\n' following current line. Read new line.
if (buf_start) free(buf_start);
char *str = (*read_func)(arg);
buf_start = str;
if (str == NULL)
return EOF;
// Initially, _line_length == -1, so pos_at_line_start becomes 0.
pos_at_line_start += _line_length + 1;
_line_length = strlen(str);
buf_end = str + _line_length;
__line_number++;
}
setg(buf_start, buf_start, buf_end);
goto retry;
}
示例11: underflow
int castorstreambuf::underflow()
{
if ( gptr() && ( gptr()<egptr() ) )
return * reinterpret_cast<unsigned char *>(gptr());
if ( !(mode & std::ios::in) || !opened) return EOF;
// Josuttis' implementation of inbuf
int n_putback = gptr() - eback();
if ( n_putback > 4) n_putback = 4;
memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback);
#ifdef CASTOR_USE
signed int num = rfio_read( file_, buffer+4, bufferSize-4);
#else
signed int num = -1;
#endif
if (num <= 0) return EOF;
// reset buffer pointers
setg( buffer + (4 - n_putback), // beginning of putback area
buffer + 4, // read position
buffer + 4 + num); // end of buffer
// return next character
return * reinterpret_cast<unsigned char *>( gptr());
}
示例12: lzma_code
std::streamsize buf_base::load()
{
lzma_.next_out = reinterpret_cast<uint8_t *>(&buf_[0]);
if (lzma_.total_out > 0)
{
lzma_.avail_out = buf_.size();
lzma_.total_out = 0;
lzma_ret retval = lzma_code(&lzma_, action_);
if (retval != LZMA_OK && retval != LZMA_STREAM_END) throw compress_error{"Compression failed with liblzma error " + util::t2s(retval)};
if (lzma_.total_out > 0) goto loaded; // Valid use case?
}
lzma_.next_out = reinterpret_cast<uint8_t *>(&buf_[0]);
while (lzma_.total_out == 0)
{
lzma_.total_in = 0;
lzma_.next_in = reinterpret_cast<uint8_t *>(&inbuf_[0]);
std::streamsize insize = fill();
if (insize == 0) action_ = LZMA_FINISH;
lzma_.avail_in = insize;
lzma_.avail_out = buf_.size();
lzma_ret retval = lzma_code(&lzma_, action_);
//std::cout << "Got " << lzma_.total_in << " bytes, compressed to " << lzma_.total_out << "\n";
if (retval == LZMA_STREAM_END) break;
else if (retval != LZMA_OK) throw compress_error{"Compression failed with liblzma error " + util::t2s(retval)};
}
loaded: char *start = &buf_[0], *end = start + lzma_.total_out;
pos_ += egptr() - eback();
setg(start, start, end);
return lzma_.total_out;
}
示例13: _ASSERT
CT_INT_TYPE CConn_Streambuf::underflow(void)
{
_ASSERT(gptr() >= egptr());
if (!m_Conn)
return CT_EOF;
// flush output buffer, if tied up to it
if (m_Tie && x_sync() != 0)
return CT_EOF;
#ifdef NCBI_COMPILER_MIPSPRO
if (m_MIPSPRO_ReadsomeGptrSetLevel && m_MIPSPRO_ReadsomeGptr != gptr())
return CT_EOF;
m_MIPSPRO_ReadsomeGptr = (CT_CHAR_TYPE*)(-1L);
#endif /*NCBI_COMPILER_MIPSPRO*/
// read from connection
size_t n_read;
m_Status = CONN_Read(m_Conn, m_ReadBuf, m_BufSize,
&n_read, eIO_ReadPlain);
_ASSERT(n_read <= m_BufSize);
if (!n_read) {
_ASSERT(m_Status != eIO_Success);
if (m_Status != eIO_Closed)
ERR_POST_X(8, x_Message("underflow(): CONN_Read() failed"));
return CT_EOF;
}
// update input buffer with the data just read
x_GPos += (CT_OFF_TYPE) n_read;
setg(m_ReadBuf, m_ReadBuf, m_ReadBuf + n_read);
return CT_TO_INT_TYPE(*m_ReadBuf);
}
示例14: eback
void IOBuffer::beginRead()
{
if(_ioDevice == 0 || _ioDevice->isReading())
return;
if( ! _ibuffer)
_ibuffer = new char[_ibufferSize];
std::size_t putback = _pbmax;
std::size_t leftover = 0;
// Keep chars for putback
if( gptr() )
{
putback = std::min<std::size_t>(gptr() - eback(), _pbmax);
char* to = _ibuffer + _pbmax - putback;
char* from = gptr() - putback;
leftover = egptr() - gptr();
std::memmove(to, from, putback + leftover);
}
std::size_t used = _pbmax + leftover;
if(_ibufferSize == used)
throw std::logic_error(PT_ERROR_MSG("IOBuffer is full"));
_ioDevice->beginRead(_ibuffer + used, _ibufferSize - used);
setg(_ibuffer + (_pbmax - putback), // start of get area
_ibuffer + used, // gptr position
_ibuffer + used); // end of get area
}
示例15: egptr
void BinaryStreamBuffer::reset()
{
size_t readEndPos = egptr() - eback();
setg(buffer(), buffer(), buffer() + readEndPos);
setp(buffer(), end());
}