/** Print a formatted double to the output stream.
 */
void _print_double(std::ostringstream& ss, size_t width, double value) {

  if(long(value) == value) {
    std::string sv = std::to_string(long(value));
    if(sv.size() < width) {
      _print_string(ss, width, sv);
      return;
    }
  }

  ss << ' ';

  size_t start_pos = ss.tellp();

  bool printed_normally = false;

  {
    std::ostringstream ss_buf;
    ss_buf.width(width);
    ss_buf << std::left << value;

    if(size_t(ss_buf.tellp()) <= width) {
      ss << ss_buf.str();
      printed_normally = true;
    }
  }

  if(!printed_normally) {

    // Find a good precision with which to print this; loop until it
    // breaks or we hit 4 decimal places.
    size_t precision = 0;
    for(;precision < 5; ++precision) {

      std::ostringstream ss_buf;
      ss_buf.width(width);
      ss_buf << std::left << std::setprecision(precision) << value;

      if(ss_buf.tellp() > long(width)) {
        precision = (precision == 0) ? 0 : (precision - 1);

        std::ostringstream ss_buf_2;
        ss_buf_2.width(width);
        ss_buf_2 << std::left << std::setprecision(precision) << value;

        ss << ss_buf_2.str();
        break;
      }
    }
  }

  // Add in padding as needed.
  while(size_t(ss.tellp()) < start_pos + width)
    ss << ' ';

  ss << ' ' << '|';
}
Example #2
0
static inline void sd_write_aligned_blob(std::ostringstream &buf, void *b, int b_size,
				 const char *name)
{
	sd_write_name(buf, name);
	/* pad calculation MUST come after name is written */
	size_t pad = align64(buf.tellp() + ((std::streamoff) 5l)) - (buf.tellp() + ((std::streamoff) 5l));
	sd_write8(buf, SD_BLOB);
	sd_write32(buf, b_size + pad);
	buf.write(zeros, pad);
	buf.write((const char *) b, b_size);
}
Example #3
0
Variant ClientBase::sendBuffer(char type, RequestID requestID, std::ostringstream &stream)
{	
	unsigned int size = (unsigned int)stream.tellp();
	size -= sizeof(size);
	stream.seekp(0);
	stream.write((const char*)&size, sizeof(size));

	RequestData rd;
	rd.type = MessageType(type);
	rd.id = requestID;
	rd.data = stream.str();

	if(asyncMode())
	{
		rd.writeCompletePtr.reset(new FutureResult);
		bool empty = m_messageQueue.empty();
		m_messageQueue.push(rd);
		if(empty)
		{
			writeData(m_messageQueue.front().data);			
		}
		return rd.writeCompletePtr;
	}
	else
	{
		writeData(rd.data);	
	}
	return Variant();
}
Example #4
0
std::string to_binary(std::ostringstream &out, const T &t) {
  out.clear();
  out.seekp(0);
  bf::fold(t, 0, app_item(out));
  // because out.str() gives us the contents of the string buffer,
  // not the contents written since clear() was called, we need to
  // chop off any remaining garbage at the end.
  std::string rv = out.str();
  rv.resize(out.tellp());
  return rv;
}
Example #5
0
  //////////////////////////////////////////////////////////////////////
  //  error_handling
  void error_handling(bp::pistream& err, std::ostringstream& os)
  {
    std::string line;

    while (err.good()) {
      std::getline(err, line);
      if (!line.empty()) {
	if (os.tellp() != std::ostream::pos_type(0)) {
	  os <<  '\n';
	}
	os << line;
      }
    }
  }
Example #6
0
 size_t tell()
 {
     return stream.tellp();
 }