Beispiel #1
0
static void writeConfig (po::variables_map & vm, std::ostream & out) {
    // Also: http://stackoverflow.com/questions/4703134/is-there-a-way-to-print-config-file-for-boost-program-options
    using boost::property_tree::ptree;

    ptree root;

    for(auto i:vm) {
        // Do not write the config option in the new config
        if(i.first == "config")
            continue;

        if(i.second.value().type() == typeid(int))
            root.put(i.first, i.second.as<int>());
        else if(i.second.value().type() == typeid(std::string))
            root.put(i.first, i.second.as<std::string>());
        else if(i.second.value().type() == typeid(float))
            root.put(i.first, i.second.as<float>());
        else if(i.second.value().type() == typeid(bool))
            root.put(i.first, i.second.as<bool>());
        else if(i.second.value().type() == typeid(unsigned long))
            root.put(i.first, i.second.as<unsigned long>());
        else if(i.second.value().type() == typeid(unsigned int))
            root.put(i.first, i.second.as<unsigned int>());
        else if(i.second.value().type() == typeid(double))
            root.put(i.first, i.second.as<double>());
        else
            std::cerr << "Unknown options type: " << i.second.value().type().name() << " " << i.first << std::endl;
    }

    write_ini( out, root );
    out.flush();
}
Beispiel #2
0
  /**
   * @brief This method outputs parameters of the URI.
   * @param out Output stream
   */
  void
  URI::debug(std::ostream& out) const {
    out << "Kind     : " ;
    out << (scheme!="" ? "ABSOLUTE " : "RELATIVE ") ;
    if (opaque!="") out << "OPAQUE " ;
    out << std::endl ;

    if (scheme!="") 
      out << "Scheme   : " << scheme << std::endl ;

    if (opaque!="") 
      out << "OPAQUE   : " << opaque << std::endl ;
    else {
      out << "User     : "******"Password : "******"Host     : " << host << std::endl ;
      out << "Port     : " << port << std::endl ;
      out << "Path     : " << path << std::endl ;
    }

    out << "Query    : " << query << std::endl ;
    out << "Fragment : " << fragment << std::endl ;

    out.flush() ;
  }
Beispiel #3
0
void SupportVectorShape::SaveAsText(std::ostream & ostr) {
    for (int i = 0; i < FeaturePoints_->size(); ++i) {
        PointType const& p = FeaturePoints_->at(i);
        ostr << p.x << ' ' << p.y << ' ' << p.z << '\n';
    }
    ostr.flush();
}
inline
void
arma_ostream::print(std::ostream& o, const subview_field<oT>& x)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  const std::streamsize cell_width = o.width();
  
  const uword x_n_rows = x.n_rows;
  const uword x_n_cols = x.n_cols;
  
  for(uword col=0; col<x_n_cols; ++col)
    {
    o << "[field column " << col << ']' << '\n'; 
    for(uword row=0; row<x_n_rows; ++row)
      {
      o.width(cell_width);
      o << x.at(row,col) << '\n';
      }
    
    o << '\n';
    }
  
  o.flush();
  stream_state.restore(o);
  }
Beispiel #5
0
	static void dump_node(std::ostream&out, const Node*node){
		for (unsigned line = 1, height = get_height(node); line <= height; ++line){
			dump_line(out, node, line);
			out.put('\n');
		}
		out.flush();
	}
Beispiel #6
0
void NetworkSimulator::OutputNodePositionsInXY(
    const TimeType lastOutputTime,
    std::ostream& nodePositionOutStream) const
{
    typedef map<NodeIdType, shared_ptr<NetworkNode> >::const_iterator IterType;

    for(IterType iter = nodes.begin(); (iter != nodes.end()); ++iter) {
        const NodeIdType& nodeId = iter->first;
        const NetworkNode& node = *iter->second;

        const ObjectMobilityPosition nodePosition = node.GetCurrentLocation();

        // Don't output stationary nodes.

        if ((lastOutputTime == ZERO_TIME) || (nodePosition.LastMoveTime() > lastOutputTime)) {

            nodePositionOutStream.precision(10);

            nodePositionOutStream << ' ' << nodeId << ' '
                                  << setw(11) << nodePosition.X_PositionMeters() << ' '
                                  << setw(11) << nodePosition.Y_PositionMeters() << ' '
                                  << nodePosition.HeightFromGroundMeters() << ' '
                                  << nodePosition.AttitudeAzimuthFromNorthClockwiseDegrees() << ' '
                                  << nodePosition.AttitudeElevationFromHorizonDegrees();

        }//if//
    }//for//
    nodePositionOutStream.flush();

}//OutputNodePositionsInXY//
Beispiel #7
0
void flowwidget::SaveSVG(std::ostream &data) {
    std::cerr << "[FlowWidget] Request to export recieved, enumerating nodes for size" << std::endl;
    int GenMinimum = INT_MAX;
    int GenExtreme = INT_MIN;
    std::for_each(XMLHandlr->OrphanNodes.begin(), XMLHandlr->OrphanNodes.end(),
                  [&](std::pair<std::string, FlowNode> nodepair) {
        NodeSize ns = getNodeSize(QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult), QFont("sans-serif", BaseFontSize*nodepair.second.FontSizeMult*1.5), nodepair.second);

        if (nodepair.second.CenterPosX - (ns.Width/2) < GenMinimum)
            GenMinimum = nodepair.second.CenterPosX - (ns.Width/2);
        if (nodepair.second.CenterPosY - (ns.Height/2) < GenMinimum)
            GenMinimum = nodepair.second.CenterPosY - (ns.Height/2);
        if (nodepair.second.CenterPosX + (ns.Width/2) > GenExtreme)
            GenExtreme = nodepair.second.CenterPosX + (ns.Width/2);
        if (nodepair.second.CenterPosY + (ns.Height/2) > GenExtreme)
            GenExtreme = nodepair.second.CenterPosY + (ns.Height/2);
    });
    int SVGSize = GenExtreme-GenMinimum;
    std::cerr << "[FlowWidget] Calculated sheet size of " << SVGSize << std::endl;

    QSvgGenerator svgen;
    QIODevice* iodev = new IOStreamBridge(data);
    svgen.setOutputDevice(iodev);
    svgen.setSize(QSize(SVGSize, SVGSize));
    renderFullTree(&svgen, XMLHandlr,
                   LineColor, BaseFontSize, "",
                   SVGSize, SVGSize, PermaScale, 1, 0, 0);
    data.flush();
    std::cerr << "[FlowWidget] Finished export!" << std::endl;
}
Beispiel #8
0
void VistaNewClusterSlave::Debug( std::ostream& oStream ) const
{
	oStream << "[VistaNewClusterSlave]\n"
			<< "    Name             : " << m_sSlaveName << "\n"
			<< "    Config Section   : " << m_sSlaveSectionName << "\n"
			<< "    SlaveId          : " << m_nOwnSlaveID << "\n"
			<< "    Byteswap         : " << (m_bDoByteSwap ? "YES" : "NO") << "\n"
			<< "    DoGLFinish       : " << (m_bDoOglFinish ? "YES" : "NO") << "\n"
			<< "    DataSync Mode    : " << VistaMasterSlave::GetDataSyncModeName( m_nDataSyncMethod ) << "\n"
			<< "    Barrier Mode     : " << VistaMasterSlave::GetBarrierModeName( m_nBarrierWaitMethod ) << "\n"
			<< "    SwapSync Mode    : " << VistaMasterSlave::GetSwapSyncModeName( m_nSwapSyncMethod ) << "\n"
			<< "    SwapSync timeout : " << vstr::formattime( m_nSwapSyncTimeout, 3 ) << "\n"
			<< "    Connected        : " << (m_pConnection ? "YES" : "NO") << "\n";
	if( m_pConnection )
	{
		VistaSocketAddress oOwnAddress = m_pConnection->GetLocalAddress();
		std::string sOwnHostname;
		oOwnAddress.GetIPAddress().GetHostName( sOwnHostname );
		oStream << "    Slave Address    : " << sOwnHostname
							<< ":" << oOwnAddress.GetPortNumber() << "\n"
				<< "    Master Address   : " << m_pConnection->GetPeerName() 
							<< ":" << m_pConnection->GetPeerPort() << "\n";
	}
	oStream.flush();
}
void WalletLegacySerializer::serialize(std::ostream& stream, const std::string& password, bool saveDetailed, const std::string& cache) {
  std::stringstream plainArchive;
  StdOutputStream plainStream(plainArchive);
  CryptoNote::BinaryOutputStreamSerializer serializer(plainStream);
  saveKeys(serializer);

  serializer(saveDetailed, "has_details");

  if (saveDetailed) {
    serializer(transactionsCache, "details");
  }

  serializer.binary(const_cast<std::string&>(cache), "cache");

  std::string plain = plainArchive.str();
  std::string cipher;

  Crypto::chacha_iv iv = encrypt(plain, password, cipher);

  uint32_t version = walletSerializationVersion;
  StdOutputStream output(stream);
  CryptoNote::BinaryOutputStreamSerializer s(output);
  s.beginObject("wallet");
  s(version, "version");
  s(iv, "iv");
  s(cipher, "data");
  s.endObject();

  stream.flush();
}
expected<void> InjectSpanContext(
    const PropagationOptions& /*propagation_options*/, std::ostream& carrier,
    const SpanContextData& span_context_data) {
  auto trace_id = SwapEndianIfBig(span_context_data.trace_id);
  carrier.write(reinterpret_cast<const char*>(&trace_id), sizeof(trace_id));
  auto span_id = SwapEndianIfBig(span_context_data.span_id);
  carrier.write(reinterpret_cast<const char*>(&span_id), sizeof(span_id));

  const uint32_t num_baggage =
      SwapEndianIfBig(static_cast<uint32_t>(span_context_data.baggage.size()));
  carrier.write(reinterpret_cast<const char*>(&num_baggage),
                sizeof(num_baggage));
  for (auto& baggage_item : span_context_data.baggage) {
    WriteString(carrier, baggage_item.first);
    WriteString(carrier, baggage_item.second);
  }

  // Flush so that when we call carrier.good(), we'll get an accurate view of
  // the error state.
  carrier.flush();
  if (!carrier.good()) {
    return opentracing::make_unexpected(
        std::make_error_code(std::errc::io_error));
  }

  return {};
}
Beispiel #11
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();
}
Beispiel #12
0
void Display::reset(std::ostream& os) {
	pthread_mutex_lock(&Display::mutex);
	os.flush();
        os.clear();
        os.seekp(0);
	pthread_mutex_unlock(&Display::mutex);
}
Beispiel #13
0
void Root::dumpQDimacs(std::ostream &out) const {
  auto const  compact = varCompactor();

  // Ouput Header
  out <<
    "c Generated by QBM [https://github.com/preusser/qbm]\n"
    "c   by Thomas B. Preusser <*****@*****.**>\n"
    "p cnf " << compact(m_signalnxt-1) << ' ' << std::count(m_clauses.begin(), m_clauses.end(), 0) << std::endl;

  // Existential: Configuration
  out << "e ";
  for(int  i = FIRST_CONFIG; i < m_confignxt; i++)  out << compact(i) << ' ';
  out << '0' << std::endl;

  // Universal: Inputs
  out << "a ";
  for(int  i = FIRST_INPUT; i < m_inputnxt; i++)  out << compact(i) << ' ';
  out << '0' << std::endl;

  // Existential: Internal and Output Signals
  out << "e ";
  for(int  i = FIRST_SIGNAL; i < m_signalnxt; i++)  out << compact(i) << ' ';
  out << '0' << std::endl;

  // Clauses
  for(int lit : m_clauses) {
    if(lit)  out << compact(lit) << ' ';
    else     out << '0' << std::endl;
  }
  out.flush();
}
Beispiel #14
0
inline int64_t JSONStreamHelper<T>::write(std::ostream& out, bool json_out,
                                          int64_t buf_size) {    
    std::function<bool(T&)> reader = get_read_fn();        
    std::vector<T> buf;
    int64_t total = 0;
    bool good = true;
    std::function<T(size_t)> lambda = [&](size_t i) -> T {return buf[i];};
    while (good) {
        T obj;
        good = reader(obj);
        if (good) {
            buf.push_back(obj);
        }
        if (!good || buf.size() >= buf_size) {
            if (!json_out) {
                stream::write(out, buf.size(), lambda);
            } else {
                for (int i = 0; i < buf.size(); ++i) {
                    out << pb2json(buf[i]);
                }
            }
            total += buf.size();
            buf.clear();
        }
    }
    
    if (!json_out) {
        stream::finish(out);
    }
    
    out.flush();
    return total;
}
Beispiel #15
0
void print_expression (std::ostream & out, const std::vector < double >&coeff2,
                  float min2, float max2,bool noclamp=false)
{
	int order = coeff2.size ();
  if(!noclamp)
    out << "clamp(";
  
  switch(order)
  {
    case 1:
      out << coeff2[0]<<"*A[0]";break;
    case 2:
      out << coeff2[0]<<"*A[0]+"<<coeff2[1];break;
    default:
    for (int i = 0; i < order; i++)
    {
      out << coeff2[i];
      for (int j = 0; j < i; j++)
        out << "*A[0]";
      if (i != (order - 1))
        out << "+";
    }
  }
  if(!noclamp)
    out << "," << min2 << "," << (noclamp?max2*1000:max2) << ")";
  out << std::endl;
  
	out.flush();
}
Beispiel #16
0
bool qr::encode(std::istream& in, uint32_t version, error_recovery_level level,
    encode_mode mode, bool case_sensitive, std::ostream& out)
{
    std::string qr_string;
    getline(in, qr_string);

    const auto qrcode = QRcode_encodeString(qr_string.c_str(), version,
        level, mode, case_sensitive);

    if (qrcode == nullptr)
        return false;

    const auto area = qrcode->width * qrcode->width;
    if ((area == 0) || (qrcode->width > max_int32 / qrcode->width))
        return false;

    auto width_ptr = reinterpret_cast<const uint8_t*>(&qrcode->width);
    auto version_ptr = reinterpret_cast<const uint8_t*>(&qrcode->version);

    // Write out raw format of QRcode structure (defined in qrencode.h).
    // Format written is:
    // int version
    // int width
    // unsigned char* data (of width^2 length)
    ostream_writer sink(out);
    sink.write_bytes(version_ptr, sizeof(int));
    sink.write_bytes(width_ptr, sizeof(int));
    sink.write_bytes(qrcode->data, area);
    out.flush();

    return true;
}
Beispiel #17
0
 void dump(std::ostream& os) const 
     { //os << "OA_ptr(mPtr = " << mPtr << ", *mRefCountPtr="; // IRIX compiler?
       os << "OA_ptr(mPtr = " << ", *mRefCountPtr=";
       os.flush();
       if (mRefCountPtr!=NULL) { os << *mRefCountPtr; }
       else { os << 0; }
       os << ")";
     }
Beispiel #18
0
 // Function: print_get_request
 // Print GET Request sends the request to be generated to the 
 // given stream.
 bool print_get_request(std::ostream& stream) const
 { 
    stream << "GET " << getPath() << " HTTP/1.0\r\n";
    send_headers(stream);
    stream << "\r\n";
    stream.flush();
    return true;
 }
Beispiel #19
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();
}
Beispiel #20
0
void GDynamicPageServer::printSessionIds(std::ostream& stream)
{
	map<unsigned long long, GDynamicPageSession*>::iterator it;
	for(it = m_sessions.begin(); it != m_sessions.end(); it++)
	{
		stream << "	" << it->first << "\n";
	}
	stream.flush();
}
Beispiel #21
0
 // Function: print_post_request
 // Print POST Request sends the request to be generated to the
 // given stream with post data.
 //
 // Parameters:
 // stream - an output stream
 // post_data - data to be included in the body of the request
 bool print_post_request(std::ostream& stream, 
                         const std::string& post_data) const
 { 
    stream << "POST " << getPath() << " HTTP/1.0\r\n";
    send_headers(stream);
    stream << "\r\n" << post_data;
    stream.flush();
    return true;
 }
Beispiel #22
0
 void sendcommand( const command& c )
 {
     if( !m_ostream ) { COMMA_THROW( comma::exception, "cannot write to read-only stream" ); }
     if( m_commandId ) { COMMA_THROW( comma::exception, "got a new command (0x" << std::hex << command::id << "), while waiting for response to 0x" << *m_commandId << std::dec ); }
     commands::packet< command > packet( c );
     m_ostream->write( packet.data(), commands::packet< command >::size );
     m_ostream->flush();
     if( m_ostream->bad() ) { COMMA_THROW( comma::exception, "failed to send command (0x" << std::hex << command::id << std::dec ); }
 }
Beispiel #23
0
void SentenceList::writeNoIds( std::ostream& os ) const
{
  for ( int i=0; i<size(); ++i )
  {
    const Sentence& sentence = operator[](i);
    os << sentence.words << "\n";
  }
  os.flush();
}
	void write(std::ostream& s) {
		std::cout.rdbuf(stdout_orig);
		swrite(s, iden);
		std::ostringstream oss;
		write_content(oss);
		swrite(s, oss.str());
		s.flush();
		std::cout.rdbuf(stdout_redir);
	}
	void print(std::ostream& os, const std::string str){
		//print one character at a time with a specified delay
		std::string::const_iterator it;
		for(it = str.begin(); it != str.end(); ++it){
			os << *it;
			os.flush();
			delay(PRINT_DELAY);
		};
	};
Beispiel #26
0
void tprint(std::ostream& os, const std::string& text) {
    // lock must work
    if(pthread_mutex_lock(&M)) {
        assert(0);
    }
    os << text;
    os.flush();
    pthread_mutex_unlock(&M);
}
inline
void
arma_ostream::print(std::ostream& o, const Mat<eT>& m, const bool modify)
  {
  arma_extra_debug_sigprint();
  
  const arma_ostream_state stream_state(o);
  
  const std::streamsize cell_width = modify ? arma_ostream::modify_stream(o, m.memptr(), m.n_elem) : o.width();
  
  const uword m_n_rows = m.n_rows;
  const uword m_n_cols = m.n_cols;
  
  if(m.is_empty() == false)
    {
    if(m_n_cols > 0)
      {
      if(cell_width > 0)
        {
        for(uword row=0; row < m_n_rows; ++row)
          {
          for(uword col=0; col < m_n_cols; ++col)
            {
            // the cell width appears to be reset after each element is printed,
            // hence we need to restore it
            o.width(cell_width);
            arma_ostream::print_elem(o, m.at(row,col), modify);
            }
        
          o << '\n';
          }
        }
      else
        {
        for(uword row=0; row < m_n_rows; ++row)
          {
          for(uword col=0; col < m_n_cols-1; ++col)
            {
            arma_ostream::print_elem(o, m.at(row,col), modify);
            o << ' ';
            }
        
          arma_ostream::print_elem(o, m.at(row, m_n_cols-1), modify);
          o << '\n';
          }
        }
      }
    }
  else
    {
    o << "[matrix size: " << m_n_rows << 'x' << m_n_cols << "]\n";
    }
  
  o.flush();
  stream_state.restore(o);
  }
Beispiel #28
0
			uint64_t serialize(::std::ostream & out) const
			{
				::libmaus2::autoarray::AutoArray<uint64_t> struc = structureArray();
				::libmaus2::autoarray::AutoArray<int64_t> symb = symbolArray();
				uint64_t s = 0;
				s += struc.serialize(out);
				s += symb.serialize(out);
				out.flush();
				return s;
			}
Beispiel #29
0
void TeamcityBoostLogFormatter::entry_context_finish(std::ostream& out)
{
    out.flush();
    messages.testOutput(
        boost::unit_test_framework::framework::current_test_case().full_name()
      , currentContextDetails
      , flowId
      , TeamcityMessages::StdErr
      );
}
Beispiel #30
0
ProcessActionsEnum NCL2MT::configureBasedOnINI(MTInstance & mInstance,
        ::INIReader & iniReader,
        std::ostream & err) {
    INIValueChecker ivc;
    std::string value = iniReader.Get("action", "action", "LScore");
    ProcessActionsEnum action = ivc.parseActionAction(value);

    err.flush();
    return action;
}