Ejemplo n.º 1
0
void UNVIO::write (const std::string& file_name)
{
  if (file_name.rfind(".gz") < file_name.size())
    {
#ifdef LIBMESH_HAVE_GZSTREAM

      ogzstream out_stream(file_name.c_str());
      this->write_implementation (out_stream);

#else

      libMesh::err << "ERROR:  You must have the zlib.h header "
		    << "files and libraries to read and write "
		    << "compressed streams."
		    << std::endl;
      libmesh_error();

#endif

      return;
    }

  else
    {
      std::ofstream out_stream (file_name.c_str());
      this->write_implementation (out_stream);
      return;
    }
}
Ejemplo n.º 2
0
void PrmNodeScoreModel::write_prm_normalizer_values() const
{
	if (! indNormzlizersInitialized_)
	{
		cout << "Did not write PRM normalizers, models weren't initialized!" << endl;
		return;
	}

	string file_path = config_->get_resource_dir() + "/" + config_->get_model_name() + "_prm_norm.txt";

	ofstream out_stream(file_path.c_str());
	if (! out_stream.good())
	{
		cout << "Error: couldn't open prm_norm file for writing: " << file_path << endl;
		exit(1);
	}

	out_stream << setprecision(3);
	int c;
	for (c=1; c<regional_prm_normalizers.size(); c++)
	{
		if (regional_prm_normalizers[c].size()==0)
			continue;
		int s;
		for (s=0; s<regional_prm_normalizers[c].size(); s++)
		{
			out_stream << c << " " << s << " " << regional_prm_normalizers[c][s].size();
			int r;
			for (r=0; r<regional_prm_normalizers[c][s].size(); r++)
				out_stream << " " << regional_prm_normalizers[c][s][r];
			out_stream << endl;
		}
	}
	out_stream.close();
}
Ejemplo n.º 3
0
void AdvancedScoreModel::write_prm_normalizer_values() const
{
	string file_path = config.get_resource_dir() + "/" + this->model_name + "_prm_norm.txt";

	ofstream out_stream(file_path.c_str());
	if (! out_stream.good())
	{
		cout << "Error: couldn't open prm_norm file for writing: " << file_path << endl;
		exit(1);
	}

	out_stream << setprecision(3);
	int c;
	for (c=1; c<regional_prm_normalizers.size(); c++)
	{
		if (regional_prm_normalizers[c].size()==0)
			continue;
		int s;
		for (s=0; s<regional_prm_normalizers[c].size(); s++)
		{
			out_stream << c << " " << s << " " << regional_prm_normalizers[c][s].size();
			int r;
			for (r=0; r<regional_prm_normalizers[c][s].size(); r++)
				out_stream << " " << regional_prm_normalizers[c][s][r];
			out_stream << endl;
		}
	}
	out_stream.close();
}
Ejemplo n.º 4
0
Archivo: svc.c Proyecto: vonwenm/pbft
void 
svcbyz_recycle(SVCXPRT *xpt, char* in, int in_size, char *out, int out_size) {  
  assert(xpt != 0);

  xdrmem_create(in_stream(xpt), in, in_size, XDR_DECODE);
  xdrmem_create(out_stream(xpt), out, out_size, XDR_ENCODE);
}
Ejemplo n.º 5
0
void* SearchThread::Entry()
{
	const wxString searchescaped = ConvToIRI(m_search_query);


//   std::cout << "Escaped search query: " << m_search_query.ToAscii().data() << std::endl;
	wxHTTP get;
	get.SetTimeout(10);
	get.Connect(_("api.springfiles.com"));
	const wxString query = wxFormat(_("/json.php?nosensitive=on&logical=or&springname=%s&tag=%s"))  % searchescaped % searchescaped;
	wxInputStream * httpStream = get.GetInputStream(query);
	wxString res;
	if ( get.GetError() == wxPROTO_NOERR ) {

		wxStringOutputStream out_stream(&res);
		httpStream->Read(out_stream);


	}
	wxDELETE(httpStream);
	wxCommandEvent notify(SEARCH_FINISHED,ContentDownloadDialog::ID_SEARCH_FINISHED);
	notify.SetInt(0);
	notify.SetString(res);
	wxPostEvent(m_content_dialog,notify);
//   std::cout << "Search finished" << std::endl;
	return NULL;
}
Ejemplo n.º 6
0
Archivo: svc.c Proyecto: vonwenm/pbft
SVCXPRT *
svcbyz_create(char* in, int in_size, char *out, int out_size) {
  register SVCXPRT *xprt;
  struct xp_ops* xops;

  xprt = (SVCXPRT *)malloc(sizeof(SVCXPRT));
  if (xprt == NULL) {
    (void)fprintf(stderr, "svcbyz_create: out of memory\n");
    return (NULL);
  }

  xprt->xp_sock = -1;
  xprt->xp_port = -1;
  xops = (struct xp_ops*) malloc(sizeof(struct xp_ops));
  xops->xp_recv = byz_recv;
  xops->xp_stat = byz_stat;
  xops->xp_getargs = byz_getargs;
  xops->xp_reply = byz_reply;
  xops->xp_freeargs = byz_freeargs;
  xops->xp_destroy = byz_destroy;
  xprt->xp_ops = xops;
  xprt->xp_p1 = malloc(sizeof(XDR));     /* in XDR */
  xprt->xp_p2 = malloc(sizeof(XDR));     /* out XDR */
  xprt->xp_verf.oa_flavor = AUTH_NULL;
  xprt->xp_verf.oa_length = 0;

  xdrmem_create(in_stream(xprt), in, in_size, XDR_DECODE);
  xdrmem_create(out_stream(xprt), out, out_size, XDR_ENCODE);

  return xprt;
}
Ejemplo n.º 7
0
std::string Falcon::PutURL(const std::string& url, const std::string& request, bool logresult)
{
    static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
    wxString res;
    _http.SetMethod("POST");
    _http.SetPostText("application/x-www-form-urlencoded", request);
    wxInputStream *httpStream = _http.GetInputStream(wxString(url));
    logger_base.debug("Making request to falcon '%s'.", (const char *)url.c_str());
    logger_base.debug("    With data '%s'.", (const char *)request.c_str());

    if (_http.GetError() == wxPROTO_NOERR)
    {
        wxStringOutputStream out_stream(&res);
        httpStream->Read(out_stream);

        if (logresult)
        {
            logger_base.debug("Response from falcon '%s'.", (const char *)res.c_str());
        }
    }
    else
    {
        logger_base.error("Unable to connect to falcon '%s'.", (const char *)url.c_str());
        wxMessageBox(_T("Unable to connect!"));
    }
    _http.SetPostText("", "");

    wxDELETE(httpStream);
    return res.ToStdString();
}
Ejemplo n.º 8
0
bool Transcribe::saveText() {
  if (!m_text_file) {
    // This shouldn't happen because of the GUI. We silently ignore it
    return false;
  }

  QSaveFile file(m_text_file->fileName());
  if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
#ifdef Q_OS_ANDROID
    // The on-screen keyboard doesn't actully add the word to the text area
    // until it is committed, normally by a space or period etc. To include it
    // in our saved file, we need to manually commit it.
    qApp->inputMethod()->commit();
#endif
    QTextStream out_stream(&file);
    out_stream << QQmlProperty::read(m_text_area, "text").toString();
    if (file.commit()) {
      setTextDirty(false);
      return true;
    }
  }

  // Notify that the file could not be saved
  QString general_msg =  tr("There was an error saving the text file.\n");
  general_msg         += tr("The latest changes are not saved!");

  errorDetected(general_msg);
  return false;
}
Ejemplo n.º 9
0
 inline void write_file(const std::string& file_name, char* buffer, const std::size_t& buffer_size)
 {
    std::ofstream out_stream(file_name.c_str(),std::ios::binary);
    if (!out_stream) return;
    out_stream.write(buffer,static_cast<std::streamsize>(buffer_size));
    out_stream.close();
 }
Ejemplo n.º 10
0
bool  CModelBaseExportor::exportUVChannelToStreamAsXML(std::wstring mesh_dir , xcomdoc& doc , xMeshData& meshData, int compress_rate)
{
	int nVert = (int)meshData.m_VertexData.m_Positons.size();
	for(int iUVCh = 0 ; iUVCh < meshData.m_VertexData.m_nUVChannes ; ++iUVCh )
	{
		xXmlDocument xml;
		xXmlNode* rootNode = xml.insertNode(L"MeshUV");
		rootNode->setValue(L"nVertex",nVert);
		rootNode->setValue(L"nMapChanel",iUVCh);
		for(int i = 0 ; i <  nVert ; ++i )
		{
			sUVCoord_t & uv = meshData.m_VertexData.m_UVChannels[iUVCh][i];
			wchar_t index[32]={0};swprintf(index , L"idx-%d",i);
			xXmlNode* pUVNode = rootNode->insertNode( index );
			pUVNode->setValue(L"u" , uv.u);
			pUVNode->setValue(L"v" , uv.v);
		}

		wchar_t buf[32];
		swprintf(buf,L"/uv_%d.xml",iUVCh);
		wstring  file_name = mesh_dir + buf;

		xcomdocstream* pUVStream = doc.create_stream(file_name.c_str(),xcddt_common,compress_rate);
		pUVStream->stream_seekw(xcdsd_beg,0);
		xcdstream out_stream(pUVStream);
		xml.setXMLStyle(true);
		xml.save(out_stream);
		out_stream.close();
		doc.close_stream(pUVStream);
	}
	return true;
}
Ejemplo n.º 11
0
bool  CModelBaseExportor::exportDiffuseToStreamAsXML(std::wstring mesh_dir , xcomdoc& doc , xMeshData& meshData, int compress_rate)
{
	int nVert = (int)meshData.m_VertexData.m_Positons.size();
    xXmlDocument xml;
	xXmlNode* rootNode = xml.insertNode(L"MeshColor");
	rootNode->setValue(L"nVertex",nVert);
	for(int i = 0 ; i <  nVert ; ++i )
	{
		sColor_t & cl = meshData.m_VertexData.m_Diffuses[i];
		wchar_t index[32]={0};swprintf(index , L"idx-%d",i);
		xXmlNode* pVecNode = rootNode->insertNode( index );
		pVecNode->setValue(L"r" , cl.r);
		pVecNode->setValue(L"g" , cl.g);
		pVecNode->setValue(L"b" , cl.b);
		pVecNode->setValue(L"a" , cl.a);
	}

	//写入Diffuse
	wstring mesh_diffuse_file = mesh_dir + L"/diffuse.xml";
	xcomdocstream* pdiffuseStream = doc.create_stream(mesh_diffuse_file.c_str(),xcddt_common,compress_rate);
	pdiffuseStream->stream_seekw(xcdsd_beg,0);
	xcdstream out_stream(pdiffuseStream);
	xml.setXMLStyle(true);
	xml.save(out_stream);
	out_stream.close();
	doc.close_stream(pdiffuseStream);
	return true;

}
Ejemplo n.º 12
0
bool  CModelBaseExportor::_export_svectorsAsXML(sVectors_t& vec , xcomdoc& doc , std::wstring mesh_dir , std::wstring stream_name , std::wstring rootNode_name , int compress_rate)
{
	int nVert = (int)vec.size();
	xXmlDocument xml;
	xXmlNode* rootNode = xml.insertNode(rootNode_name.c_str());
	rootNode->setValue(L"nVertex",nVert);
	for(int i = 0 ; i <  nVert ; ++i )
	{
		sVector_t& v = vec[i];
		wchar_t index[32]={0};swprintf(index , L"idx-%d",i);
		xXmlNode* pVecNode = rootNode->insertNode(index);
		pVecNode->setValue(L"x" , v.x);
		pVecNode->setValue(L"y" , v.y);
		pVecNode->setValue(L"z" , v.z);
	}

	//写入Normal
	wstring mesh_vec_file = mesh_dir + L"/" + stream_name + L".xml";
	xcomdocstream* pVecDataStream = doc.create_stream(mesh_vec_file.c_str(),xcddt_common,compress_rate);
	pVecDataStream->stream_seekw(xcdsd_beg,0);
	xcdstream out_stream(pVecDataStream);
	xml.setXMLStyle(true);
	xml.save(out_stream);
	out_stream.close();
	doc.close_stream(pVecDataStream);
	return true;

}
Ejemplo n.º 13
0
  void CSConnectionAcquirer::ServerStateInquire(const Request &request)
  {
    QHash<QByteArray, QUrl> id_to_addr;
    const Id &my_id = GetConnectionManager()->GetId();
    const ConnectionTable &ct = GetConnectionManager()->GetConnectionTable();

    foreach(const PublicIdentity &gc, _group.GetSubgroup()) {
      const Id &gc_id = gc.GetId();
      if(gc_id == my_id) {
        continue;
      }

      QSharedPointer<Connection> con = ct.GetConnection(gc_id);
      if(!con) {
        continue;
      }

      id_to_addr[gc_id.GetByteArray()] =
        con->GetEdge()->GetRemotePersistentAddress().GetUrl();
    }

    QByteArray slm;
    QDataStream out_stream(&slm, QIODevice::WriteOnly);
    out_stream << id_to_addr;

    QVariantHash msg;
    msg["connections"] = ct.GetConnections().size();
    msg["list"] = slm;
    request.Respond(msg);
  }
Ejemplo n.º 14
0
void UCDIO::write_nodal_data(const std::string & fname,
                             const std::vector<Number> & soln,
                             const std::vector<std::string> & names)
{
  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();

  const dof_id_type n_elem = mesh.n_elem();

  // Only processor 0 does the writing
  if (mesh.processor_id())
    return;

  std::ofstream out_stream(fname.c_str());

  // UCD doesn't work in 1D
  libmesh_assert (mesh.mesh_dimension() != 1);

  // Write header
  this->write_header(out_stream,mesh,n_elem,
                     cast_int<unsigned int>(names.size()));

  // Write the node coordinates
  this->write_nodes(out_stream, mesh);

  // Write the elements
  this->write_interior_elems(out_stream, mesh);

  // Write the solution
  this->write_soln(out_stream, mesh, names, soln);
}
Ejemplo n.º 15
0
std::string Falcon::GetURL(const std::string& url, bool logresult)
{
    static log4cpp::Category &logger_base = log4cpp::Category::getInstance(std::string("log_base"));
    wxString res;
    _http.SetMethod("GET");
    wxInputStream *httpStream = _http.GetInputStream(wxString(url));
    logger_base.debug("Making request to falcon '%s'.", (const char *)url.c_str());

    if (_http.GetError() == wxPROTO_NOERR)
    {
        wxStringOutputStream out_stream(&res);
        httpStream->Read(out_stream);

        if (logresult)
        {
            logger_base.debug("Response from falcon '%s'.", (const char *)res.c_str());
        }
    }
    else
    {
        logger_base.error("Unable to connect to falcon '%s'.", (const char *)url.c_str());
        wxMessageBox(_T("Unable to connect!"));
    }

    wxDELETE(httpStream);
    return res.ToStdString();
}
Ejemplo n.º 16
0
int main(){
	string buffer("buffer.txt");
	string solution("solution.txt");
	
	//for (unsigned int test_number = 0; test_number <= 100000000; test_number) {

#ifdef READ
		T w, h;
		ifstream in_stream(buffer);
		in_stream >> w >> h;
		matrix<T> source(w, h);
		for (auto& i : source) {
			in_stream >> i;
		}
		in_stream.close();
#else
		const T w = 1000, h = 1000;
		matrix<T> source = gen_sourse_data(w, h, 5);
#endif
#ifdef WRITE
		ofstream out_stream(buffer);
		out_stream << w << ' ' << h;
		T j = 0;
		for (const auto& i : source) {
			if ((j++ % w) == 0) out_stream << '\n';
			out_stream << i << ' ';
		}
		out_stream.close();
#endif
#ifdef SOLVE
		cout << "w = " << w << "; h = " << h << ";" << endl;
		auto start_time = clock();
		matrix<T> source_copy(source);//эта матрица будет преобразована в такую, что в каждом квадрате 3х3 будет не больше 3 текстур
		matrix< array<pair<T, bool>, 3> > res = get_textures_arrangement(source_copy);
		double time = (clock() - start_time) / double(1000);


		auto source_from_res = res_to_source(res);
		auto diff1 = difference(source, source_from_res);
		auto diff2 = difference(source, source_copy);
		cout << "time is " << time << " second" << endl;
		cout << "full difference is " << diff1 << " = " << (diff1 / (float)(w * h)) * 100 << "%" << endl;
		cout << "difference between source and 3x3 condition source is " << diff2 << " = " << (diff2 / (float)(w * h)) * 100 << "%" << endl << endl;
#ifdef PRINT_SOLUTION
		ofstream solution_stream(solution);
		cout.rdbuf(solution_stream.rdbuf());
		cout << "w = " << w << "; h = " << h << ";" << endl;
		cout << "time is " << time << " second" << endl;
		cout << "full difference is " << diff1 << " = " << (diff1 / (float)(w * h)) * 100 << "%" << endl;
		cout << "difference between source and 3x3 condition source is " << diff2 << " = " << (diff2 / (float)(w * h)) * 100 << "%" << endl << endl;
		print(source, res);
		solution_stream.close();
#endif
#endif

	//}

	system("pause");
}
Ejemplo n.º 17
0
/*-------------------------------------------------------------------------
 * Function:    out_init
 *
 * Purpose:     Initialize output.
 *
 * Return:      void
 *
 * Programmer:  Robb Matzke
 *              [email protected]
 *              Dec 11 1996
 *
 * Modifications:
 *              Robb Matzke, 2000-05-23
 *              The column in which the equal sign appears is 25 percent
 *              of the way across the screen.
 *
 *              Robb Matzke, 2000-06-01
 *              The window size is obtained by ioctl() when possible.
 *
 *              Robb Matzke, 2000-06-28
 *              Signal handlers are registered with sigaction() since its
 *              behavior is more consistent.
 *-------------------------------------------------------------------------
 */
void
out_init (void)
{
    struct sigaction    action;
    
    /* Keep track of terminal size changes */
    out_init_size();
    
    /* Open standard streams */
    OUT_STDOUT = out_stream (stdout);
    OUT_STDERR = out_stream (stderr);

    /* Arrange to handle broken pipes and interrupts */
    action.sa_handler = handle_signals;
    sigemptyset(&action.sa_mask);
    action.sa_flags = SA_RESTART;
    sigaction(SIGPIPE, &action, NULL);
    sigaction(SIGINT, &action, NULL);
}
void test_iostream_iterator() {
  vector<string> text;
  istream_iterator<string> stream_start(cin);
  istream_iterator<string> eof;

  copy(stream_start, eof, back_inserter(text));
  sort(text.begin(), text.end());

  ostream_iterator<string> out_stream(cout, " ");
  copy(text.begin(), text.end(), out_stream);
}
Ejemplo n.º 19
0
 void test_load_stream()
 {
     remove_temp_file();
     {
         std::ifstream in_stream(existing_file, std::ios::binary);
         xlnt::zip_file f(in_stream);
         std::ofstream out_stream(temp_file.GetFilename(), std::ios::binary);
         f.save(out_stream);
     }
     TS_ASSERT(files_equal(existing_file, temp_file.GetFilename()));
     remove_temp_file();
 }
Ejemplo n.º 20
0
vector<string> StreamSorter<Message>::streaming_merge(const vector<string>& temp_files_in, unordered_map<string, size_t>* messages_per_file) {
    
    // What are the names of the merged files we create?
    vector<string> temp_files_out;
    
    // We don't do this loop in parallel because the point of looping is to limit the total currently open files.
    for (size_t start_file = 0; start_file < temp_files_in.size(); start_file += max_fan_in) {
        // For each range of sufficiently few files, starting at start_file and running for file_count
        size_t file_count = min(max_fan_in, temp_files_in.size() - start_file);
    
        // Open up cursors into all the files.
        list<ifstream> temp_ifstreams;
        list<cursor_t> temp_cursors;
        open_all(vector<string>(&temp_files_out[start_file], &temp_files_out[start_file + file_count]), temp_ifstreams, temp_cursors);
        
        // Work out how many messages to expect
        size_t expected_messages = 0;
        if (messages_per_file != nullptr) {
            for (size_t i = start_file; i < start_file + file_count; i++) {
                expected_messages += messages_per_file->at(temp_files_in.at(i));
            }
        }
        
        // Open an output file
        string out_file_name = temp_file::create();
        ofstream out_stream(out_file_name);
        temp_files_out.push_back(out_file_name);
        
        // Make an output emitter
        emitter_t emitter(out_stream);
        
        // Merge the cursors into the emitter
        streaming_merge(temp_cursors, emitter, expected_messages);
        
        // The output file will be flushed and finished automatically when the emitter goes away.
        
        // Clean up the input files we used
        temp_cursors.clear();
        temp_ifstreams.clear();
        for (size_t i = start_file; i < file_count; i++) {
            temp_file::remove(temp_files_in.at(i));
        }
        
        if (messages_per_file != nullptr) {
            // Save the total messages that should be in the created file, in case we need to do another pass
            (*messages_per_file)[out_file_name] = expected_messages;
        }
    }
    
    return temp_files_out;
        
}
Ejemplo n.º 21
0
TestFWParser::TestFWParser(): QObject() {
  test_cases_.append(
    "this is an exam ple of 256 cases being tested -3.14       times\n");
  test_cases_.append(
    "                                                               \n");
  test_cases_.append("this is an ex\n\n");

  QString file_name("TestFW.txt");
  file_name = KStandardDirs::locateLocal("appdata", file_name);

  if (!file_name.isNull()) {
        test_file_.setFileName(file_name);
        if (!test_file_.open(QIODevice::WriteOnly)) {
          kWarning() << QString("Couldn't open(%1)").arg(file_name);
        }
  }

  QTextStream out_stream(&test_file_);
  foreach(const QString &test_case, test_cases_)
    out_stream << test_case;
  test_file_.close();

  //Building the sequence to be used. Includes all available types.
  sequence_.clear();
  sequence_.append(qMakePair(QString("field1"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field2"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field3"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field4"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field5"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field6"), KSParser::D_INT));
  sequence_.append(qMakePair(QString("field7"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field8"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field9"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field10"), KSParser::D_FLOAT));
  sequence_.append(qMakePair(QString("field11"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field12"), KSParser::D_QSTRING));
  widths_.append(5);
  widths_.append(3);
  widths_.append(3);
  widths_.append(9);
  widths_.append(3);
  widths_.append(4);
  widths_.append(6);
  widths_.append(6);
  widths_.append(7);
  widths_.append(6);
  widths_.append(6);  //'repeatedly' doesn't need a width

  QString fname = KStandardDirs::locate( "appdata", file_name );
  test_parser_ = new KSParser(fname, '#', sequence_, widths_);
}
Ejemplo n.º 22
0
void onReturn(const std::string& path) {
	BracExtenssionProviderAPI * api_ptr = brac_extenssion_provider_api;

	if (!api_ptr) {
		return;	
	}

	if (path.empty()) {
		api_ptr->log("No brac file selected, the path is empty ");
		return;
	} else {
		api_ptr->log("brac file selected: " + path);
	}

	std::string root_dir = api_ptr->getExtensionPath();
	#if defined _WIN32
		std::string command = "cd /d \"" + root_dir + "\" & bin\\7za.exe e -y \"" + path + "\" brac.xml";
	#elif defined __APPLE__
		std::string escaped_root_dir = escape_path(root_dir);
		api_ptr->log("brac extension root dir (escaped): " + escaped_root_dir);

		std::string escaped_path = escape_path(path);
		api_ptr->log("selected brac dir (escaped): " + escaped_path);

		std::string command = "cd " + escaped_root_dir + "; bin/7za e -y " + escaped_path + " brac.xml";
	#endif
	api_ptr->systemCall(command);

	std::string content;

	std::string brac_path = root_dir + "/brac.xml";
	pugi::xml_document brac_xml;
	std::stringstream out_stream(std::stringstream::out);
	pugi::xml_parse_result res = brac_xml.load_file(brac_path.c_str());
	if (!res) {
		api_ptr->log("Couldn't load the brac.xml at " + brac_path + ": " + res.description());
		return;
	}
	brac_xml.save(out_stream);
	content = out_stream.str();

	#if defined _WIN32
		command = "del /F /Q \"" + root_dir + "\\brac.xml\"";
	#elif defined __APPLE__
		command = "rm -f " + escaped_root_dir + "/brac.xml";
	#endif
	api_ptr->systemCall(command);

	brac_extenssion_provider_api->fire_bracfileselect(path, content);
	return;
}
Ejemplo n.º 23
0
void PMCSQS_Scorer::write_sqs_models(const char *path) const
{
	ofstream out_stream(path,ios::out);
	if (! out_stream.good())
	{
		cout << "Error: couldn't open pmc model for writing: " << path << endl;
		exit(1);
	}
	int i;

	out_stream << sqs_models.size() << endl;
	out_stream << this->sqsMassThresholds_.size() << setprecision(2) << fixed;
	for (i=0; i<sqsMassThresholds_.size(); i++)
		out_stream << " " << sqsMassThresholds_[i];
	out_stream << endl;
		

	const int numSizes = sqsMassThresholds_.size();

	for (i=0; i<sqs_models.size(); i++)
	{
		out_stream << this->sqs_correction_factors[i].size() << setprecision(4);
		int j;
		for (j=0; j<sqs_correction_factors[i].size(); j++)
			out_stream << " " << sqs_correction_factors[i][j] << " " << sqs_mult_factors[i][j];
		out_stream << endl;
	}
	

	
	// write ME models
	
	for (i=0; i<sqs_models.size(); i++)
	{
		int j;
		for (j=0; j<sqs_models[i].size(); j++)
		{
			int k;
			for (k=0; k<sqs_models[i][j].size(); k++)
			{
				if (sqs_models[i][j][k])
				{
					out_stream << i << " " << j << " " << k << endl;
					sqs_models[i][j][k]->write_regression_model(out_stream);
				}
			}
		}
	}	
	out_stream.close();
}
Ejemplo n.º 24
0
bool WriteMidiFile(const MIDIMultiTrack &src, const char *file, bool use_running_status)
{
    MIDIFileWriteStreamFileName out_stream( file );
    if ( !out_stream.IsValid() )
        return false;

    MIDIFileWriteMultiTrack writer( &src, &out_stream );

    // write midifile with or without running status usage
    writer.UseRunningStatus( use_running_status );

    int tracks_number = src.GetNumTracksWithEvents();
    return writer.Write( tracks_number );
}
Ejemplo n.º 25
0
void finalize_compile(CompilerType& compiler, std::string& output,
                      size_t partition_size = 0) {
  if (partition_size == 0) {
    std::ofstream out_stream(output, std::ios::binary);
    compiler.Compile(callback);
    compiler.Write(out_stream);
    out_stream.close();
  } else {
    std::string output_part_zero = output + ".0";
    int partition_number = 1;
    std::ofstream out_stream(output_part_zero, std::ios::binary);

    while (compiler.CompileNext(partition_size, out_stream, 2, callback)) {
      std::cout << "Finalize partition " << partition_number << std::endl;

      out_stream.close();
      out_stream.open(output + "." + std::to_string(partition_number),
                      std::ios::binary);
      ++partition_number;
    }

    out_stream.close();
  }
}
Ejemplo n.º 26
0
int main(int argc, char* argv[])
{
  google::InitGoogleLogging(argv[0]);

  std::string corpus_filepath("/data/Corpus/wikipedia_dump/de_wiki_sen_tokenized_lower_per_line.txt");
  int wordvec_dim = 100;
  int window_size = 11;
  float learning_rate = 0.025;
  int skipgram = 1;
  int hs = 1;
  int negative = 10;
  float sample = 1e-5;

  int num_iters = 10;
  int num_threads = 4;

  int verbose = 1;

  Corpus &corpus = Corpus::getCorpus(corpus_filepath);

  try{
    /*
    corpus.build_vocab();
		corpus.save_vocab(std::string("cbow_vocab.txt"));
    */
		corpus.load_vocab(std::string("cbow_vocab.txt"));
    corpus.create_huffman_tree();
  } catch (std::exception& e) {
    LOG(FATAL) << e.what();
  }

  Word2Vec model(corpus, wordvec_dim, window_size, learning_rate, skipgram, hs, negative, sample, num_iters, num_threads, verbose);
  model.start_train();

	LOG(INFO) << "Training done!";

  {
    const char* name = "word2vec_sg_trained_model.bin";
    std::ofstream out_stream(name);
    boost::archive::binary_oarchive oar(out_stream);
    oar << model;
    out_stream.close();
  }

	model.export_vectors(std::string("cbow_word_vectors_save.bin"));

  return 0;
}
Ejemplo n.º 27
0
      virtual void VerifyInnerCiphertext()
      {
        Random &rand = Random::GetInstance();
        if((rand.GetInt(0, 1024) / 1024.0) > N) {
          ShuffleRound::VerifyInnerCiphertext();
          return;
        }

        SetTriggered();

        QByteArray msg;
        QDataStream out_stream(&msg, QIODevice::WriteOnly);
        out_stream << GO_MESSAGE << GetRoundId() << false;
        VerifiableBroadcast(msg);
        _state_machine.StateComplete();
      }
Ejemplo n.º 28
0
	virtual bool createDiff(CourgetteBufferI* oldBuffer, CourgetteBufferI* newBuffer, CourgetteCallbackI* callback)
	{
		if (!callback || !oldBuffer || !newBuffer)
			return false;

		courgette::SourceStream old_stream;
		courgette::SourceStream new_stream;

		old_stream.Init(oldBuffer->getBuffer(), oldBuffer->getSize());
		new_stream.Init(newBuffer->getBuffer(), newBuffer->getSize());

		SinkStream out_stream(callback);

		courgette::Status status = courgette::GenerateEnsemblePatch(&old_stream, &new_stream, &out_stream);

		return (status == courgette::C_OK);
	}
Ejemplo n.º 29
0
void TestFWParser::initTestCase() {
  test_cases_.append(
    "this is an exam ple of 256 cases being tested -3.14       times\n");
  test_cases_.append(
    "                                                               \n");
  test_cases_.append("this is an ex\n\n");

  KTemporaryFile temp_file;
  temp_file.setPrefix(QDir::tempPath() + "/");
  temp_file.setSuffix(".txt");
  temp_file.setAutoRemove(false);
  QVERIFY(temp_file.open());
  test_file_name_ = temp_file.fileName();
  QTextStream out_stream(&temp_file);
  foreach(const QString &test_case, test_cases_)
    out_stream << test_case;
  temp_file.close();

  //Building the sequence to be used. Includes all available types.
  sequence_.clear();
  sequence_.append(qMakePair(QString("field1"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field2"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field3"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field4"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field5"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field6"), KSParser::D_INT));
  sequence_.append(qMakePair(QString("field7"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field8"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field9"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field10"), KSParser::D_FLOAT));
  sequence_.append(qMakePair(QString("field11"), KSParser::D_QSTRING));
  sequence_.append(qMakePair(QString("field12"), KSParser::D_QSTRING));
  widths_.append(5);
  widths_.append(3);
  widths_.append(3);
  widths_.append(9);
  widths_.append(3);
  widths_.append(4);
  widths_.append(6);
  widths_.append(6);
  widths_.append(7);
  widths_.append(6);
  widths_.append(6);  //'repeatedly' doesn't need a width

  test_parser_ = new KSParser(test_file_name_, '#', sequence_, widths_);
}
Ejemplo n.º 30
0
void ShuffleRound::Shuffle()
{
    qDebug() << _group.GetIndex(_local_id) << ": shuffling";
    _state = Shuffling;

    for(int idx = 0; idx < _shuffle_data.count(); idx++) {
        for(int jdx = 0; jdx < _shuffle_data.count(); jdx++) {
            if(idx == jdx) {
                continue;
            }
            if(_shuffle_data[idx] != _shuffle_data[jdx]) {
                continue;
            }
            qWarning() << "Found duplicate cipher texts... blaming";
            // blame ?
            return;
        }
    }

    QVector<QByteArray> out_data;
    int blame = OnionEncryptor::GetInstance().Decrypt(_outer_key, _shuffle_data, out_data);
    if (blame != -1) {
        qWarning() << _group.GetIndex(_local_id) << _local_id.ToString() <<
                   ": failed to decrypt layer due to block at index" << blame;
        // blame ?
        return;
    }

    const Id &next = _group.Next(_local_id);
    MessageType mtype = (next == Id::Zero) ? EncryptedData : ShuffleData;

    QByteArray msg;
    QDataStream out_stream(&msg, QIODevice::WriteOnly);
    out_stream << mtype << GetId().GetByteArray() << out_data;

    _state = ShuffleDone;

    if(mtype == EncryptedData) {
        Broadcast(msg);
        _encrypted_data = out_data;
        Verify();
    } else {
        Send(msg, next);
    }
}