本文整理汇总了C++中setg函数的典型用法代码示例。如果您正苦于以下问题:C++ setg函数的具体用法?C++ setg怎么用?C++ setg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: return
_CRTIMP2 int strstreambuf::underflow()
{ // read only if read position available
if (gptr() == 0)
return (EOF);
else if (gptr() < egptr())
return ((unsigned char)*gptr());
else if (pptr() == 0
|| pptr() <= gptr() && _Seekhigh <= gptr())
return (EOF);
else
{ // update _Seekhigh and expand read region
if (_Seekhigh < pptr())
_Seekhigh = pptr();
setg(eback(), gptr(), _Seekhigh);
return ((unsigned char)*gptr());
}
}
示例2: egptr
int string_parsebuf::underflow()
{
register char* ptr = egptr(); // Point to end of current_line
do {
int i = right() - ptr;
if (i <= 0)
return EOF;
ptr++; i--; // Skip '\n'.
char *line_start = ptr;
while (ptr < right() && *ptr == '\n') ptr++;
setg(line_start-1, line_start, ptr + (ptr < right()));
pos_at_line_start = line_start - left();
_line_length = ptr - line_start;
__line_number++;
} while (gptr() == ptr);
return *gptr();
}
示例3: setg
std::streampos streambuf::seekoff( std::streamoff off,
std::ios_base::seekdir seekdir,
std::ios_base::openmode /*m*/)
{
if(sync())
return -1;
if(!buffer_in_.empty()) {
setg(0,0,0);
}
if(seekdir == std::ios_base::cur)
return device().seek(off,io_device::cur);
if(seekdir == std::ios_base::beg)
return device().seek(off,io_device::set);
if(seekdir == std::ios_base::end)
return device().seek(off,io_device::end);
return -1;
}
示例4: underflow
int_type underflow()
{
// if there is still data, then return it
if ( gptr() < egptr() )
return static_cast<int_type>(*(reinterpret_cast<uint8_t const *>(gptr())));
assert ( gptr() == egptr() );
// number of bytes for putback buffer
uint64_t const putbackcopy = std::min(
static_cast<uint64_t>(gptr() - eback()),
putbackspace
);
// copy bytes
#if 0
std::copy(
gptr()-putbackcopy,
gptr(),
buffer.begin() + putbackspace - putbackcopy
);
#endif
std::memmove(
buffer.begin() + putbackspace - putbackcopy,
gptr()-putbackcopy,
putbackcopy
);
// load data
uint64_t const uncompressedsize = stream.readPart(
buffer.begin()+putbackspace,
buffer.size()-putbackspace
);
// set buffer pointers
setg(
buffer.begin()+putbackspace-putbackcopy,
buffer.begin()+putbackspace,
buffer.begin()+putbackspace+uncompressedsize
);
if ( uncompressedsize )
return static_cast<int_type>(*(reinterpret_cast<uint8_t const *>(gptr())));
else
return traits_type::eof();
}
示例5: setg
ProcReader*
ProcReader::open(const char* fileName, const char* mode)
{
std::string fullName = "/proc/";
fullName.append(fileName);
fFD = ::open(fullName.c_str(), O_RDONLY);
if (fFD < 0)
return NULL;
fBuffer = new char[512];
if (fBuffer == NULL)
return NULL;
setg(fBuffer, fBuffer, fBuffer);
return this;
}
示例6: socket
/// Move-assign a basic_socket_streambuf from another.
basic_socket_streambuf& operator=(basic_socket_streambuf&& other)
{
this->close();
socket() = std::move(other.socket());
detail::socket_streambuf_io_context::operator=(other);
ec_ = other.ec_;
expiry_time_ = other.expiry_time_;
get_buffer_.swap(other.get_buffer_);
put_buffer_.swap(other.put_buffer_);
setg(other.eback(), other.gptr(), other.egptr());
setp(other.pptr(), other.epptr());
other.ec_ = asio::error_code();
other.expiry_time_ = max_expiry_time();
other.put_buffer_.resize(buffer_size);
other.init_buffers();
return *this;
}
示例7: base
int strstreambuf::underflow()
{
char * tptr;
if (gptr() >= egptr())
{
// try to grow get area if we can...
if (egptr()<pptr())
{
tptr = base() + (gptr()-eback());
setg(base(),tptr,pptr());
}
if (gptr() >= egptr())
return EOF;
}
return (int)(unsigned char) *gptr();
}
示例8: return
sockbuf::int_type sockbuf::underflow ()
{
if (gptr () == 0)
return eof; // input stream has been disabled
if (gptr () < egptr ())
return (unsigned char) *gptr (); // eof is a -ve number; make it
// unsigned to be diff from eof
int rlen = read (eback (), (char*) rep->gend - (char*) eback ());
if (rlen == 0)
return eof;
setg (eback (), eback (), eback () + rlen);
return (unsigned char) *gptr ();
}
示例9: gptr
void BinaryStreamBuffer::reserve(size_t newSize)
{
size_t getPos = 0;
size_t putPos = 0;
size_t readEndPos = 0;
if(!m_dataBuf.empty()){
getPos = gptr() - eback();
readEndPos = egptr() - eback();
putPos = pptr() - buffer();
}
if(newSize > m_dataBuf.size())
m_dataBuf.resize(newSize);
setg(buffer(), buffer() + getPos, buffer() + readEndPos);
setp(buffer() + putPos, end());
}
示例10: category
LoggerMessage::LoggerMessage(LoggerMessage&& other)
: std::ostream(nullptr)
, std::streambuf()
, category(other.category)
, logLevel(other.logLevel)
, logger(other.logger)
, message(other.message)
, timestamp(boost::posix_time::microsec_clock::local_time())
, gotText(false) {
if (this != &other) {
_M_tie = nullptr;
_M_streambuf = nullptr;
//ios_base swap
std::swap(_M_streambuf_state, other._M_streambuf_state);
std::swap(_M_exception, other._M_exception);
std::swap(_M_flags, other._M_flags);
std::swap(_M_precision, other._M_precision);
std::swap(_M_width, other._M_width);
std::swap(_M_callbacks, other._M_callbacks);
std::swap(_M_ios_locale, other._M_ios_locale);
//ios_base swap
//streambuf swap
char *_Pfirst = pbase();
char *_Pnext = pptr();
char *_Pend = epptr();
char *_Gfirst = eback();
char *_Gnext = gptr();
char *_Gend = egptr();
setp(other.pbase(), other.epptr());
other.setp(_Pfirst, _Pend);
setg(other.eback(), other.gptr(), other.egptr());
other.setg(_Gfirst, _Gnext, _Gend);
std::swap(_M_buf_locale, other._M_buf_locale);
//streambuf swap
std::swap(_M_fill, other._M_fill);
std::swap(_M_tie, other._M_tie);
}
_M_streambuf = this;
}
示例11: _ASSERT
ERW_Result CRWStreambuf::x_Pushback(void)
{
if ( !m_Reader ) {
_ASSERT(!gptr() && !egptr());
return eRW_Success;
}
ERW_Result result;
const CT_CHAR_TYPE* ptr = gptr();
size_t count = (size_t)(egptr() - ptr);
setg(0, 0, 0);
if ( !count )
result = eRW_Success;
else if ((result = m_Reader->Pushback(ptr, count, m_pBuf)) == eRW_Success)
m_pBuf = 0;
return result;
}
示例12: STL_ASSERT
stringbuf::pos_type stringbuf::seekoff(off_type __off, ios_base::seekdir __dir, ios_base::openmode __mode /* = ios_base::in | ios_base::out */)
{
__mode &= __M_mode;
bool __imode = (__mode & ios_base::in) != 0;
bool __omode = (__mode & ios_base::out) != 0;
if ((__imode == false) && (__omode == false)) return pos_type(-1);
if ((__imode && (gptr() == 0)) || (__omode && (pptr() == 0))) return pos_type(-1);
STL_ASSERT((eback() <= gptr()) && (gptr() <= egptr()) && (pbase() <= pptr()) && (pptr() <= epptr()));
streamoff __newoff;
switch (__dir)
{
case ios_base::beg:
__newoff = 0;
break;
case ios_base::end:
__newoff = __M_str.size();
break;
case ios_base::cur:
__newoff = __imode ? (gptr() - eback()) : (pptr() - pbase());
if (__off == 0) return pos_type(__newoff);
break;
default:
return pos_type(-1);
}
__off += __newoff;
if (__imode)
{
ptrdiff_t __size = egptr() - eback();
if ((__off < 0) || (__off > __size)) return pos_type(-1);
setg(eback(), eback() + static_cast<ptrdiff_t>(__off), eback() + static_cast<ptrdiff_t>(__size));
}
if (__omode)
{
ptrdiff_t __size = epptr() - pbase();
if ((__off < 0) || (__off > __size)) return pos_type(-1);
setp(pbase(), pbase() + __size);
pbump(static_cast<int>(__off));
}
return pos_type(__off);
}
示例13: pptr
streamsize stringbuf::xsputn(const char_type* __string, streamsize __length)
{
if (((__M_mode & ios_base::out) == 0) || (__length <= 0)) return 0;
streamsize __nwritten = 0;
// If the put pointer is somewhere in the middle of the string, then overwrite instead of append.
if (!__M_str.empty() && (pbase() == __M_str.begin()))
{
ptrdiff_t __avail = __M_str.end() - pptr();
if (__avail >= __length)
{
VOS_memcpy_s(pptr(), epptr() - pptr(), __string, static_cast<size_t>(__length));
pbump(static_cast<int>(__length));
return __length;
}
else
{
VOS_memcpy_s(pptr(), epptr() - pptr(), __string, __avail);
__nwritten += __avail;
__length -= __avail;
__string += __avail;
}
}
// At this point we know we're appending.
char_type* __data_ptr;
if (__M_mode & ios_base::in)
{
ptrdiff_t __get_offset = gptr() - eback();
__M_str.append(__string, __string + static_cast<ptrdiff_t>(__length));
__data_ptr = __M_str.begin();
setg(__data_ptr, __data_ptr + __get_offset, __M_str.end());
}
else
{
__M_str.append(__string, __string + static_cast<ptrdiff_t>(__length));
__data_ptr = __M_str.begin();
}
setp(__data_ptr, __M_str.end());
pbump(static_cast<int>(__M_str.size()));
__nwritten += __length;
return __nwritten;
}
示例14: _TRACE
EIO_Status CConn_Streambuf::x_Close(bool close)
{
if (!m_Conn)
return close ? eIO_Closed : eIO_Success;
EIO_Status status;
// flush only if some data pending
if (pbase() < pptr()) {
if ((status = CONN_Status(m_Conn, eIO_Write)) != eIO_Success) {
m_Status = status;
if (CONN_Status(m_Conn, eIO_Open) == eIO_Success) {
_TRACE(x_Message("Close(): Cannot finalize implicitly"
", data loss may result"));
}
} else if (sync() != 0)
status = m_Status != eIO_Success ? m_Status : eIO_Unknown;
} else
status = eIO_Success;
setg(0, 0, 0);
setp(0, 0);
CONN c = m_Conn;
m_Conn = 0; // NB: no re-entry
if (close) {
// here: not called from the close callback x_OnClose
if (m_CbValid) {
SCONN_Callback cb;
CONN_SetCallback(c, eCONN_OnClose, &m_Cb, &cb);
if ((void*) cb.func != (void*) x_OnClose || cb.data != this)
CONN_SetCallback(c, eCONN_OnClose, &cb, 0);
}
if (m_Close && (m_Status = CONN_Close(c)) != eIO_Success) {
_TRACE(x_Message("Close(): CONN_Close() failed"));
if (status == eIO_Success)
status = m_Status;
}
} else if (m_CbValid && m_Cb.func) {
EIO_Status cbstat = m_Cb.func(c, eCONN_OnClose, m_Cb.data);
if (cbstat != eIO_Success)
status = cbstat;
}
return status;
}
示例15: common
istreambuf::istreambuf(std::streambuf * sb)
: common(sb), end(false) {
LOG("bz::istreambuf");
int cret =::BZ2_bzDecompressInit(z_strm,
0, //verbosity
0 //no small memory
);
if (BZ_OK != cret) {
LOG("\terror creating zstream " << cret);
raise_error(cret);
}
//initialize streambuf interface functions
//first call will call uflow and this will set the buffer accordingly
//no buffering
setg(out.buf, out.buf, out.buf);
}