Esempio n. 1
0
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);
}
Esempio n. 2
0
BufferStream::BufferStream(std::ostream &stream, QByteArray &buffer)
    : stream_(stream)
    , outputBuffer_(buffer)
{
    oldBuffer_ = stream.rdbuf();
    stream.rdbuf(this);
}
 StreamRedirect( std::ostream& stream, std::string& targetString )
 :   m_stream( stream ),
     m_prevBuf( stream.rdbuf() ),
     m_targetString( targetString )
 {
     stream.rdbuf( m_oss.rdbuf() );
 }
Esempio n. 4
0
File: Utils.hpp Progetto: PDAL/PDAL
    /**
      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;
    }
Esempio n. 5
0
File: Utils.hpp Progetto: PDAL/PDAL
    /**
      Redirect a stream to a null stream.

      \param out   Stream to redirect.
      \return  Context for stream restoration (see \ref restore()).
    */
    inline RedirectStream redirect(std::ostream& out)
    {
        RedirectStream redir;

        redir.m_buf = out.rdbuf();
        out.rdbuf(redir.m_null->rdbuf());
        return redir;
    }
Esempio n. 6
0
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();
}
Esempio n. 7
0
File: Utils.hpp Progetto: PDAL/PDAL
    /**
      Redirect a stream to some file.

      \param out   Stream to redirect.
      \param file  Name of file where stream should be redirected.
      \return  Context for stream restoration (see \ref restore()).
    */
    inline RedirectStream redirect(std::ostream& out, const std::string& file)
    {
        RedirectStream redir;

        redir.m_out = new std::ofstream(file);
        redir.m_buf = out.rdbuf();
        out.rdbuf(redir.m_out->rdbuf());
        return redir;
    }
Esempio n. 8
0
    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());
      }
    }
Esempio n. 9
0
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);
}
Esempio n. 10
0
DebugStream::DebugStream(std::ostream &stream, QPlainTextEdit *text_edit)
    : stream_(stream)
{
    logWindow_ = text_edit;

    QObject::connect(this
                     , &DebugStream::appendLog
                     , logWindow_
                     , &QPlainTextEdit::appendPlainText);

    oldBuffer_ = stream.rdbuf();
    stream.rdbuf(this);
}
Esempio n. 11
0
reset_level_buf::reset_level_buf(std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf())
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 12
0
/** \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());
}
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
Logger::Logger( std::ostream& str ):
    _logLevel( Warning ),
    _displayFilePosition( true ),
    _out( str.rdbuf() )
{

}
Esempio n. 15
0
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();
}
Esempio n. 16
0
syslog_buf::syslog_buf(std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf())
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 17
0
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 );
}
Esempio n. 18
0
color_level_buf::color_level_buf(std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf()),
    m_start_new_line(true)
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 19
0
timestamp_buf::timestamp_buf(std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf()),
    m_start_new_line(true)
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
GZIPOutputStream::GZIPOutputStream( std::ostream &os )
    : ostream( 0 ),
      ofs( 0 )
{
    ozf = new GZIPOutputStreambuf( os.rdbuf() ) ;

    init( ozf ) ;
}
Esempio n. 21
0
fold_duplicates_buf::fold_duplicates_buf(std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf()),
    m_duplicate_count(0)
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 22
0
filter_by_level_buf::filter_by_level_buf(const log_level_t MinimumLevel, std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf()),
    m_minimum_level(MinimumLevel)
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 23
0
File: Utils.hpp Progetto: PDAL/PDAL
    /**
      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;
    }
Esempio n. 24
0
ZipOutputStream::ZipOutputStream( std::ostream &os ) 
  : std::ostream( 0 ), 
// SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
    ofs( 0 )
{
  ozf = new ZipOutputStreambuf( os.rdbuf() ) ;
  
  init( ozf ) ;
}
Esempio n. 25
0
tag_buf::tag_buf(const std::string& Tag, std::ostream& Stream) :
    m_stream(Stream),
    m_streambuf(Stream.rdbuf()),
    m_start_new_line(true),
    m_tag(Tag + " ")
{
    setp(0, 0);
    m_stream.rdbuf(this);
}
Esempio n. 26
0
static bool setFd(std::ostream &stream, int *state_fd, int fd)
{
    std::lock_guard<std::mutex> lock(s_stateMutex);
    if (*state_fd != -1)
        return false;
    *state_fd = fd;
    delete dynamic_cast<FdWriter*>(stream.rdbuf(new FdWriter(fd)));
    return true;
}
Esempio n. 27
0
// Save & change and restore stream properties
void
saver_tests_2
(
    std::istream &  input,
    std::ostream &  output,
    std::ostream &  err
)
{
    using std::locale;
    using std::ios_base;

    boost::io::ios_tie_saver const    its( input, &err );
    boost::io::ios_rdbuf_saver const  irs( output, err.rdbuf() );
    boost::io::ios_iword_saver const  iis( output, my_index, 69L );
    boost::io::ios_pword_saver const  ipws( output, my_index, &err );
    output << "The data is (a third time; adding the numbers):\n";

    boost::io::ios_flags_saver const      ifls( output, (output.flags()
     & ~ios_base::adjustfield) | ios_base::showpos | ios_base::boolalpha
     | (ios_base::internal & ios_base::adjustfield) );
    boost::io::ios_precision_saver const  iprs( output, 9 );
    boost::io::ios_fill_saver const       ifis( output, '@' );
    output << '\t' << test_string << '\n';

    boost::io::ios_width_saver const  iws( output, 12 );
    output.put( '\t' );
    output << test_num1 + test_num2;
    output.put( '\n' );

    locale                             loc( locale::classic(),
     new backward_bool_names );
    boost::io::ios_locale_saver const  ils( output, loc );
    output << '\t' << test_bool << '\n';

    BOOST_CHECK( &err == output.pword(my_index) );
    BOOST_CHECK( 69L == output.iword(my_index) );

    try
    {
        boost::io::ios_exception_saver const  ies( output, ios_base::eofbit  );
        boost::io::ios_iostate_saver const    iis( output, output.rdstate()
         | ios_base::eofbit );

        BOOST_ERROR( "previous line should have thrown" );
    }
    catch ( ios_base::failure &f )
    {
        err << "Got the expected I/O failure: \"" << f.what() << "\".\n";
        BOOST_CHECK( output.exceptions() == ios_base::goodbit );
    }
    catch ( ... )
    {
        err << "Got an unknown error when doing exception test!\n";
        throw;
    }
}
 portable_binary_oarchive(std::ostream & os, unsigned flags = 0) :
     primitive_base_t(
         * os.rdbuf(),
         0 != (flags & boost::archive::no_codecvt)
     ),
     archive_base_t(flags),
     m_flags(flags & (endian_big | endian_little))
 {
     init(flags);
 }
Esempio n. 29
0
void redirect (std::ostream& strm, const std::string& dateiname)
{
    // Datei (mit dazugehörigem Puffer) zum Schreiben öffnen
    std::ofstream datei(dateiname.c_str());
    
    // Ausgabepuffer des übergebenen Streams merken
    std::streambuf* strm_puffer = strm.rdbuf();

    // Ausgaben in die Datei umlenken
    strm.rdbuf(datei.rdbuf());

    datei << "direkt in die Datei geschriebene Zeile" << std::endl;
    strm  << "auf den umgelenkten Stream geschriebene Zeile"
          << std::endl;

    // alten Ausgabepuffer des übergebenen Streams restaurieren
    strm.rdbuf(strm_puffer);

}  // schließt die Datei und den dazugehörigen Puffer
Esempio n. 30
0
/*!

*/
gzofilterstream::gzofilterstream( std::ostream & dest,
                                  int level,
                                  std::size_t buf_size )
    : std::ostream( static_cast< std::streambuf * >( 0 ) )
    , M_filter_buf( *(dest.rdbuf()), level, buf_size )

{
    // std::basic_ios::init( basic_streambuf<charT,traits>* sb );
    this->init( &M_filter_buf );
}