本文整理汇总了C++中std::ostream::rdbuf方法的典型用法代码示例。如果您正苦于以下问题:C++ ostream::rdbuf方法的具体用法?C++ ostream::rdbuf怎么用?C++ ostream::rdbuf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::ostream
的用法示例。
在下文中一共展示了ostream::rdbuf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: swapstdout
void swapstdout(std::ostream& buf)
{
// Switch the stream buffer with std::cout, which is used by Print.
std::streambuf* cout_strbuf(std::cout.rdbuf());
std::cout.rdbuf(buf.rdbuf());
buf.rdbuf(cout_strbuf);
}
示例2:
BufferStream::BufferStream(std::ostream &stream, QByteArray &buffer)
: stream_(stream)
, outputBuffer_(buffer)
{
oldBuffer_ = stream.rdbuf();
stream.rdbuf(this);
}
示例3: StreamRedirect
StreamRedirect( std::ostream& stream, std::string& targetString )
: m_stream( stream ),
m_prevBuf( stream.rdbuf() ),
m_targetString( targetString )
{
stream.rdbuf( m_oss.rdbuf() );
}
示例4: redirect
/**
Redirect a stream to some other stream, by default a null stream.
\param out Stream to redirect.
\param dst Destination stream.
\return Context for stream restoration (see \ref restore()).
*/
inline RedirectStream redirect(std::ostream& out, std::ostream& dst)
{
RedirectStream redir;
redir.m_buf = out.rdbuf();
out.rdbuf(dst.rdbuf());
return redir;
}
示例5: printCurrentOrderBook
void Reporter::printCurrentOrderBook(std::ostream& os) const
{
StrStream strstream;
auto cap = strstream.capacity() - 128;
const auto nbBids = bids_.size();
const auto nbAsks = asks_.size();
os << "Full Bids/Asks:\n";
auto i = 0U;
while (1)
{
StrStream strstream_tmp;
if (i < nbBids)
{
Limit bid = bids_[i];
strstream_tmp << i;
strstream_tmp.append(6, ' ');
strstream_tmp << ": " << getQty(bid) << " @ " << getPrice(bid);
strstream_tmp.append(40, ' ');
if (i < nbAsks)
{
Limit ask = asks_[i];
strstream_tmp << getQty(ask) << " @ " << getPrice(ask) << '\n';
}
else
{
strstream_tmp << "empty\n";
}
}
else
{
strstream_tmp << i;
strstream_tmp.append(6, ' ');
strstream_tmp << ": empty";
strstream_tmp.append(40, ' ');
if (i < nbAsks)
{
Limit ask = asks_[i];
strstream_tmp << getQty(ask) << " @ " << getPrice(ask) << '\n';
}
else
{
strstream << strstream_tmp;
strstream << "empty\n";
break;
}
}
if (strstream.length() + strstream_tmp.length() > cap)
{
os.rdbuf()->sputn(strstream.c_str(), strstream.length());
strstream.clear();
}
strstream << strstream_tmp;
++i;
}
os.rdbuf()->sputn(strstream.c_str(), strstream.length());
os.flush();
}
示例6: set
void set(std::istream& in, std::ostream& out, std::ostream& err) {
if (not activated) {
using namespace std;
in_buf = cin.rdbuf(); out_buf = cout.rdbuf(); err_buf = cerr.rdbuf();
in_state = cin.rdstate(); out_state = cin.rdstate(); err_state = cerr.rdstate();
cin.rdbuf(in.rdbuf()); cout.rdbuf(out.rdbuf()); cerr.rdbuf(err.rdbuf());
cin.exceptions(ios_base::goodbit); cout.exceptions(ios_base::goodbit); cerr.exceptions(ios_base::goodbit);
cin.clear(in.rdstate()); cout.clear(out.rdstate()); cerr.clear(err.rdstate());
}
}
示例7:
nc_window_streambuf::nc_window_streambuf(WINDOW* _p, std::ostream& _os, unsigned long _cursesAttr):
m_pnl(_p),
m_flags(_cursesAttr),
m_os(&_os),
m_old(_os.rdbuf())
{
setp(0, 0);
setg(0, 0, 0);
_os.rdbuf(this);
scrollok(_p, true);
mvwinch(_p, 0, 0);
}
示例8: setp
reset_level_buf::reset_level_buf(std::ostream& Stream) :
m_stream(Stream),
m_streambuf(Stream.rdbuf())
{
setp(0, 0);
m_stream.rdbuf(this);
}
示例9: GZIPOutputStreambuf
/** \brief Create a ZIP output stream object.
*
* This constructor creates a zip stream from an existing standard
* output stream.
*
* \warning
* You must keep the output stream valid for as long as this object
* exists (although this object close() function can be used to close
* the \p os stream.)
*
* \param[in,out] os ostream to which the compressed zip archive is written.
* \param[in] compression_level The compression level to use to compress.
*/
GZIPOutputStream::GZIPOutputStream(std::ostream& os, FileEntry::CompressionLevel compression_level)
: std::ostream( nullptr )
//, m_ofs(nullptr) -- auto-init
, m_ozf(new GZIPOutputStreambuf(os.rdbuf(), compression_level))
{
init(m_ozf.get());
}
示例10: writeNode
virtual WriteResult writeNode( const osg::Node& node, std::ostream& fOut, const Options* options ) const
{
// Convert Options to FltOptions.
ExportOptions* fltOpt = new ExportOptions( options );
fltOpt->parseOptionsString();
// If user didn't specify a temp dir, use the output directory
// that was implicit in the output file name.
if (fltOpt->getTempDir().empty())
fltOpt->setTempDir( _implicitPath );
if (!fltOpt->getTempDir().empty())
{
// If the temp directory doesn't already exist, make it.
if ( !osgDB::makeDirectory( fltOpt->getTempDir() ) )
{
osg::notify( osg::FATAL ) << "fltexp: Error creating temp dir: " << fltOpt->getTempDir() << std::endl;
return WriteResult::ERROR_IN_WRITING_FILE;
}
}
flt::DataOutputStream dos( fOut.rdbuf(), fltOpt->getValidateOnly() );
flt::FltExportVisitor fnv( &dos, fltOpt );
// Hm. 'node' is const, but in order to write out this scene graph,
// must use Node::accept() which requires 'node' to be non-const.
// Pretty much requires casting away const.
osg::Node* nodeNonConst = const_cast<osg::Node*>( &node );
if (!nodeNonConst)
return WriteResult::ERROR_IN_WRITING_FILE;
nodeNonConst->accept( fnv );
fnv.complete( node );
return fltOpt->getWriteResult();
}
示例11:
Logger::Logger( std::ostream& str ):
_logLevel( Warning ),
_displayFilePosition( true ),
_out( str.rdbuf() )
{
}
示例12: printMidQuotesAndTrades
void Reporter::printMidQuotesAndTrades(std::ostream& os, Errors& errors)
{
StrStream strstream;
if (unlikely(bids_.begin() == bids_.end() || asks_.begin() == asks_.end()))
{
strstream << "NAN" << '\n';
}
else if (receivedNewTrade_)
{
strstream << getQty(currentTrade_) << '@' << getPrice(currentTrade_) << '\n';
receivedNewTrade_ = false;
detectCross_ = false;
}
else if (unlikely(getPrice(*bids_.begin()) >= getPrice(*asks_.begin())))
{
if (likely(!detectCross_)) detectCross_ = true;
else
{
strstream << "Cross BID (" << getPrice(*bids_.begin()) << ")/ASK(" << getPrice(*asks_.begin()) << ')' << '\n';
++errors.bestBidEqualOrUpperThanBestAsk;
}
}
else
{
Price midQuote = (getPrice(*bids_.begin())+getPrice(*asks_.begin()))/2;
strstream << midQuote << '\n';
}
os.rdbuf()->sputn(strstream.c_str(), strstream.length());
os.flush();
}
示例13:
gzostream::gzostream( std::ostream & dest,
unsigned int buffer_size )
: std::ostream( static_cast< std::streambuf * >( 0 ) )
, M_gzstreambuf( *(dest.rdbuf()), buffer_size )
{
this->init( &M_gzstreambuf );
}
示例14: ostream
GZIPOutputStream::GZIPOutputStream( std::ostream &os )
: ostream( 0 ),
ofs( 0 )
{
ozf = new GZIPOutputStreambuf( os.rdbuf() ) ;
init( ozf ) ;
}
示例15: restore
/**
Restore a stream redirected with redirect().
\param out Stream to be restored.
\param redir RedirectStream returned from corresponding
\ref redirect() call.
*/
inline void restore(std::ostream& out, RedirectStream& redir)
{
out.rdbuf(redir.m_buf);
if (redir.m_out)
redir.m_out->close();
redir.m_out = NULL;
redir.m_buf = NULL;
}