本文整理汇总了C++中std::streambuf类的典型用法代码示例。如果您正苦于以下问题:C++ streambuf类的具体用法?C++ streambuf怎么用?C++ streambuf使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了streambuf类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: unpackState
void StarsNode::unpackState(std::streambuf & in) {
uint32_t size;
in.sgetn((char *)&size, 4);
msgpack::unpacker upk;
upk.reserve_buffer(size);
in.sgetn(upk.buffer(), size);
upk.buffer_consumed(size);
MsgpackInArchive ar(upk);
ar & power & mem & disk & static_cast<SimOverlayBranch &>(getBranch()) & static_cast<SimOverlayLeaf &>(getLeaf());
switch (Configuration::getInstance().getPolicy()) {
case Configuration::IBPolicy:
static_cast<IBPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::MMPolicy:
static_cast<MMPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::DPolicy:
static_cast<DPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::FSPolicy:
static_cast<FSPDispatcher &>(getDisp()).serializeState(ar);
break;
default:
break;
}
}
示例2: if
std::streambuf::int_type SolidusEscaper::operator()(std::streambuf &destination,
std::streambuf::int_type character) {
bool notEscaped = true;
std::streambuf::char_type tmpChar = std::streambuf::traits_type::to_char_type(character);
// If we encounter a quotation mark.
if (tmpChar == Strings::Json::Escape::QUOTATION_MARK) {
// If we're not in a string, we change that. If we're in a string,
// we change that only if we're not after an escape back slash.
inString = !inString || (afterBackSlash);
} else if (inString && !afterBackSlash) {
// If we are in a string definition and we're not after a backslash
// escape.
if (tmpChar == Strings::Std::SOLIDUS) {
destination.sputn(Strings::Json::SOLIDUS.c_str(), Strings::Json::SOLIDUS.size());
notEscaped = false;
}
}
// We determine if we start a backslash escape or not.
afterBackSlash = inString && !afterBackSlash && (tmpChar == Strings::Json::Escape::BEGIN_ESCAPE);
return (notEscaped) ? (destination.sputc(tmpChar)) : (0);
}
示例3: packState
void StarsNode::packState(std::streambuf & out) {
msgpack::sbuffer buffer;
msgpack::packer<msgpack::sbuffer> pk(&buffer);
MsgpackOutArchive ar(pk);
ar & power & mem & disk & static_cast<SimOverlayBranch &>(getBranch()) & static_cast<SimOverlayLeaf &>(getLeaf());
switch (Configuration::getInstance().getPolicy()) {
case Configuration::IBPolicy:
static_cast<IBPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::MMPolicy:
static_cast<MMPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::DPolicy:
static_cast<DPDispatcher &>(getDisp()).serializeState(ar);
break;
case Configuration::FSPolicy:
static_cast<FSPDispatcher &>(getDisp()).serializeState(ar);
break;
default:
break;
}
uint32_t size = buffer.size();
out.sputn((const char *)&size, 4);
out.sputn(buffer.data(), size);
}
示例4: parseXMLIdentifier
static std::string parseXMLIdentifier(std::streambuf& buffer)
{
std::stringstream identifier;
{
char c=buffer.sgetc();
if((c<'A' || c>'Z') && (c<'a' || c>'z'))
{
throw XMLParseException();
}
buffer.snextc();
identifier<<c;
}
for(;;)
{
char c=buffer.sgetc();
if((c<'0' || c>'9') && (c<'A' || c>'Z') && (c<'a' || c>'z'))
{
break;
}
buffer.snextc();
identifier<<c;
}
return identifier.str();
}
示例5: parseXMLSkipSpace
static void parseXMLSkipSpace(std::streambuf& buffer)
{
while(buffer.sgetc()==' ' || buffer.sgetc()=='\n' || buffer.sgetc()=='\r')
{
buffer.snextc();
}
}
示例6: size
/**
read whole contents of streambuf 'buf'
\return size of data malloced and copied into \param[out] buffer unless size
is 0 (in which case buffer is set to NULL for convenience, so you can blindly free)
requires put pointer is at end for determining size (e.g. just-written iostream)
*/
inline std::size_t read_streambuf_malloc(std::streambuf& buf, void*& buffer) {
typedef std::streambuf::pos_type Pos;
typedef std::streambuf::off_type Off;
Pos sz = buf.pubseekoff(0, std::ios::end, std::ios_base::out);
if (sz > 0 && seek_ok(sz) && seek_ok(buf.pubseekpos(0, std::ios_base::in)))
return buf.sgetn((char*)(buffer = std::malloc(sz)), sz);
else {
buffer = 0;
return 0;
}
}
示例7:
std::streambuf::int_type Indenter::operator()(std::streambuf &destination,
std::streambuf::int_type character) {
std::streambuf::char_type tmpChar = std::streambuf::traits_type::to_char_type(character);
if (atStartOfLine && tmpChar != Whitespace::NEW_LINE) {
destination.sputc(Whitespace::HORIZONTAL_TAB);
}
atStartOfLine = (tmpChar == Whitespace::NEW_LINE);
return destination.sputc(tmpChar);
}
示例8: advance
std::size_t HeaderParser::advance(std::streambuf& sb)
{
std::size_t ret = 0;
while (sb.in_avail() > 0)
{
++ret;
if (parse(sb.sbumpc()))
return ret;
}
return ret;
}
示例9: if
virtual std::streampos seekoff (std::streamoff off, std::ios_base::seekdir way,
std::ios_base::openmode which = std::ios_base::in)
{
std::streamoff newpos;
if ( way == std::ios_base::beg )
{
newpos = off;
}
else if ( way == std::ios_base::cur )
{
newpos = _curPos + off;
}
else if ( way == std::ios_base::end )
{
newpos = _numChars + off;
}
else
{
return -1;
}
if ( newpos<0 || newpos>_numChars ) return -1;
if ( ARCHIVE_POS(_streambuf->pubseekpos( STREAM_POS(_startPos+newpos), which)) < 0 ) return -1;
_curPos = newpos;
return _curPos;
}
示例10: parseXML
XMLNode_SPtr parseXML(std::streambuf& buffer)
{
std::cout<<"Parse Start"<<std::endl;
parseXMLSkipSpace(buffer);
char c=buffer.sgetc();
if(c=='<')
{
buffer.snextc();
std::cout<<"Parse Node"<<std::endl;
XMLNode_SPtr current=parseXMLNode(buffer);
std::cout<<"Something"<<std::endl;
return current;
}
std::cout<<"Nothing"<<std::endl;
return XMLNode_SPtr();
}
示例11: serializar
Ttamanio Bloque::serializar(std::streambuf&salida)const{
unsigned char nrocomponetes=componentes.size();
Ttamanio offset=sizeof(unsigned char);
salida.sputn((char*)&nrocomponetes,offset);
for(Ttamanio i=0;i<nrocomponetes;i++){
offset+=componentes.at(i)->serializar(salida);
}
return offset;
}
示例12: operator
int operator()(std::streambuf& sbuf, int c)
{
int result = eof();
if (c != eof() && new_line)
{
std::ostream(&sbuf) << ++line_number << ": ";
}
new_line = (c == '\n');
return result != eof() ? result : sbuf.sputc(c);
}
示例13: read
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
bool t_single_scenario_campaign_file_header::read(
std::streambuf & stream,
t_progress_handler * progress_handler_ptr )
{
m_map_data_start = stream.pubseekoff( 0, std::ios::cur );
m_map_data_end = stream.pubseekoff( 0, std::ios::end );
stream.pubseekpos( m_map_data_start );
try
{
t_inflate_filter inflater( stream );
if ( !::read( inflater, *m_map_header_ptr, progress_handler_ptr ) )
return false;
}
catch ( t_inflate_filter::t_data_error const & )
{
return false;
}
return true;
}
示例14: read
//////////////////////////////////////////////////////////////////////////////
// STATIC
void
read(std::streambuf & istrm, void * dataIn, size_t dataInLen)
{
std::streamsize cnt = dataInLen;
#ifdef BLOCXX_WIN32
// VC10 warns that sgetn is unsafe.
#pragma warning(push)
#pragma warning(disable:4996)
#endif
if (istrm.sgetn(static_cast<char *>(dataIn), cnt) != cnt)
#ifdef BLOCXX_WIN32
#pragma warning(pop)
#endif
{
BLOCXX_THROW(IOException, "Failed reading data");
}
}
示例15: tmp
std::streambuf::int_type Escaper::operator()(std::streambuf &destination,
std::streambuf::int_type character) {
bool notEscaped = true;
std::streambuf::char_type tmpChar = std::streambuf::traits_type::to_char_type(character);
// If we encounter a quotation mark.
if (tmpChar == Structural::BEGIN_END_STRING) {
// If we're not in a string, we change that. If we're in a string,
// we change that only if we're not after an escape back slash.
inString = !inString || (afterBackSlash);
} else if (inString && !afterBackSlash) {
// If we are in a string definition and we're not after a backslash
// escape.
if (tmpChar == Strings::Std::REVERSE_SOLIDUS) {
destination.sputn(Strings::Json::REVERSE_SOLIDUS.c_str(), Strings::Json::REVERSE_SOLIDUS.size());
notEscaped = false;
} else if (tmpChar == Strings::Std::BACKSPACE) {
destination.sputn(Strings::Json::BACKSPACE.c_str(), Strings::Json::BACKSPACE.size());
notEscaped = false;
} else if (tmpChar == Strings::Std::FORM_FEED) {
destination.sputn(Strings::Json::FORM_FEED.c_str(), Strings::Json::FORM_FEED.size());
notEscaped = false;
} else if (tmpChar == Strings::Std::LINE_FEED) {
destination.sputn(Strings::Json::LINE_FEED.c_str(), Strings::Json::LINE_FEED.size());
notEscaped = false;
} else if (tmpChar == Strings::Std::TAB) {
destination.sputn(Strings::Json::TAB.c_str(), Strings::Json::TAB.size());
notEscaped = false;
} else if (tmpChar >= '\0' && tmpChar <= '\x1f') {
std::string tmp(Value::escapeToUnicode(tmpChar));
destination.sputn(tmp.c_str(), tmp.size());
notEscaped = false;
}
}
// We determine if we start a backslash escape or not.
afterBackSlash = inString && !afterBackSlash && (tmpChar == Strings::Json::Escape::BEGIN_ESCAPE);
return (notEscaped) ? (destination.sputc(tmpChar)) : (0);
}