Пример #1
0
 bool server_response::write(std::ostream &os) {
     // Set "content-length" header
     auto i=headers.find("content-length");
     if (i==headers.end()) {
         headers.insert(std::make_pair("Content-Length", boost::lexical_cast<std::string>(get_content_length())));
     } else {
         i->second.assign(boost::lexical_cast<std::string>(get_content_length()));
     }
     // Write headers
     if (!write_header(os)) return false;
     // Write body
     os.write(&(raw_body_stream_.vector()[0]), raw_body_stream_.vector().size());
     return !os.eof() && !os.fail() && !os.bad();
 }
Пример #2
0
 bool server_response::write_header(std::ostream &os) {
     std::string ka;
     if (keep_alive) {
         ka="keep-alive";
     } else {
         ka="close";
     }
     auto i=headers.find("connection");
     if (i==headers.end()) {
         headers.insert(std::make_pair("Connection", ka));
     } else {
         i->second.assign(ka);
     }
     if (!common::response::write_header(os)) return false;
     return !os.eof() && !os.fail() && !os.bad();
 }
Пример #3
0
void sintoxml(std::ostream& s, const char* filename, sinparms& sp)
{
  std::ifstream f(filename);
  if (!f.is_open()) {
    throw std::runtime_error("Unable to open SIN file for XML conversion");
  }

  pugi::xml_document doc;
  pugi::xml_node root = doc.append_child();
  root.set_name("philips");

  std::string line;
  const size_t buffer_size = 4096;
  char buffer[buffer_size];
  while (!f.eof()) {
    f.getline(buffer,buffer_size);
    std::string line(buffer);
    std::stringstream s;
    uint16_t idx1, idx2, idx3;
    char tmp;
    std::string parameter_name;
    std::string parameter_value;
    if (line.find(':') != std::string::npos && isdigit(line[1])) {
	  boost::algorithm::trim_right(line);
	  s << line;
	  s >> idx1; s >> idx2; s >> idx3; s >> tmp;
      s >> parameter_name;
      
      pugi::xml_node parm = root.append_child(parameter_name.c_str());
      pugi::xml_attribute attr_idx1 = parm.append_attribute("idx1");
      attr_idx1.set_value(idx1);
      pugi::xml_attribute attr_idx2 = parm.append_attribute("idx2");
      attr_idx2.set_value(idx2);
      pugi::xml_attribute attr_idx3 = parm.append_attribute("idx3");
      attr_idx3.set_value(idx3);
      s >> tmp;

      bool get_nchan = false;
      float pda[2];
      bool get_pda = false;
      int pda_comp = 0;
      if (parameter_name == "enable_pda") {
	sp.ismira = false;
      } else if (parameter_name == "max_measured_channels") {
	get_nchan = true;
      } else if (parameter_name == "nr_measured_channels") {
	get_nchan = true;
      } else if (parameter_name == "pda_ampl_factors") {
	get_pda = true;
      }
      
      while (!s.eof()) {
	s >> parameter_value;

	if (get_nchan) {
	  sp.nchan = std::atoi(parameter_value.c_str());
	}

	if (get_pda) {
	  pda[pda_comp++] = std::atof(parameter_value.c_str());
      
	  if (pda_comp > 1) {
	    sp.pda_amp_factors.push_back(std::complex<float>(pda[0],pda[1]));
	    pda_comp = 0;
	  }
	}

	pugi::xml_node v = parm.append_child("value");
	v.append_child(pugi::node_pcdata).set_value(parameter_value.c_str());
      }
    }
  }