void put_val(char_type e){
     if(NULL != m_ostream){
         m_ostream->put(e);
         if(! m_ostream->good())
             m_ostream = NULL;
     }
 }
Exemple #2
0
        void to_stream(T const& value)
        {
            std::locale loc = m_Stream.getloc();
            if (!std::has_facet< FacetT >(loc))
            {
                // Add the formatting facet
                std::auto_ptr< FacetT > facet(new FacetT(m_Format.c_str()));
                m_Stream.imbue(std::locale(loc, facet.get()));
                facet.release();
                loc = m_Stream.getloc();
            }

            // Perform formatting
            std::ostreambuf_iterator< char_type > osb_it(m_Stream);
            std::use_facet< FacetT >(loc).put(osb_it, m_Stream, m_Stream.fill(), value);
        }
 //! Put date into an ostream
 static void date_put(const date_type& d,
                      ostream_type& os)
 {
   //retrieve the local from the ostream
   std::locale locale = os.getloc();
   if (std::has_facet<facet_type>(locale)) {
     const facet_type& f = std::use_facet<facet_type>(locale);
     date_put(d, os, f);
   }
   else {
     //default to something sensible if no facet installed
     facet_type default_facet;
     date_put(d, os, default_facet);
   }
 } // date_to_ostream
Exemple #4
0
    /*!
     * Formatting operator. Invokes all aggregated formatters, collects their formatting results
     * and composes them according to the format string passed on construction.
     *
     * \param strm A reference to the stream, where the final text of the logging record is composed
     * \param record A logging record
     */
    void operator() (ostream_type& strm, record_type const& record) const
    {
        boost::log::aux::cleanup_guard< format_type > cleanup1(m_Format);
        boost::log::aux::cleanup_guard< streambuf_type > cleanup2(m_StreamBuf);
        {
            rdbuf_saver cleanup3(strm, &m_StreamBuf);
            for (typename formatters::const_iterator it = m_Formatters.begin(), end = m_Formatters.end(); it != end; ++it)
            {
                boost::log::aux::cleanup_guard< string_type > cleanup4(m_Buffer);
                (*it)(strm, record);
                strm.flush();
                m_Format % m_Buffer;
            }
        }

        strm << m_Format.str();
    }
Exemple #5
0
int retrieve(option& opt, istream_type& is, ostream_type& os)
{
    typedef std::basic_string<char_type> string_type;
    typedef std::vector<string_type> strings_type;
    typedef simstring::reader reader_type;

    std::ostream& es = std::cerr;

    // Open the database.
    reader_type db;
    if (!db.open(opt.name)) {
        es << "ERROR: " << db.error() << std::endl;
        return 1;
    }

    // Check the size of characters.
    if (db.char_size() != sizeof(char_type)) {
        es << "ERROR: Inconsistent character encoding " <<
            "(DB:" << db.char_size() << ", " <<
            "CUR:" << sizeof(char_type) << "): " << std::endl;
        es << "This problem may be solved by specifying -u (--unicode) option." << std::endl;
        return 1;
    }

    int num_queries = 0;
    int num_retrieved = 0;
    clock_t clk_total = 0;
    for (;;) {
        // Read a line.
        string_type line;
        std::getline(is, line);
        if (is.eof()) {
            break;
        }

        // Issue a query.
        strings_type xstrs;
        clock_t clk = std::clock();
        db.retrieve(line, opt.measure, opt.threshold, std::back_inserter(xstrs));
        clock_t elapsed = (std::clock() - clk);

        // Update stats.
        clk_total += elapsed;
        num_retrieved += (int)xstrs.size();
        ++num_queries;

        // Do not output results when the benchmarking flag is on.
        if (!opt.benchmark) {
            // Output the query string if necessary.
            if (opt.echo_back) {
                os << line << std::endl;
            }

            // Output the retrieved strings.
            typename strings_type::const_iterator it;
            for (it = xstrs.begin();it != xstrs.end();++it) {
                os << os.widen('\t') << *it << std::endl;
            }
            os.flush();
        }

        // Do not output information when the quiet flag is on.
        if (!opt.quiet) {
            os <<
                xstrs.size() <<
                widen<char_type>(" strings retrieved (") <<
                (std::clock() - clk) / (double)CLOCKS_PER_SEC <<
                widen<char_type>(" sec)") << std::endl;
        }
    }

    // Output the benchmark information if necessary.
    if (opt.benchmark) {
        os <<
            widen<char_type>("Total number of queries: ") <<
            num_queries << std::endl;
        os <<
            widen<char_type>("Seconds per query: ") <<
            clk_total / (double)CLOCKS_PER_SEC / num_queries << std::endl;
        os <<
            widen<char_type>("Number of retrieved strings per query: ") <<
            num_retrieved / (double)num_queries << std::endl;
    }

    return 0;
}
		ostreambuf_iterator(ostream_type& s) noexcept
		: sbuf_(s.rdbuf()) {}
Exemple #7
0
 //! Cleanup method
 void clear()
 {
     m_Stream.clear();
     m_StreamBuf.clear();
     m_Buffer.clear();
 }