Exemplo n.º 1
0
//os2 type of a header
static bool write_dibheader(int bit_depth)
{

	dib_head dib;
	dib.headsz=12;
	dib.width=w;
	dib.height=h;
	dib.colplanes=1;
	dib.bitsperpix=bit_depth;

	fout.write((char *) &(dib.headsz), sizeof(char) * 4);
	if (!fout.good()) return 0;

	fout.write((char *) &(dib.width), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(dib.height), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(dib.colplanes), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(dib.bitsperpix), sizeof(char) * 2);
	if (!fout.good()) return 0;

	return 1;
}
Exemplo n.º 2
0
static bool write_fileheader(int clrtable_sz)
{
	f_head head;
	head.bmid[0]='B';
	head.bmid[1]='M';
	head.sz=14+12+clrtable_sz+sz;//head size+dib_size+color_table size+bitmap_sz
	head.res1=0;
	head.res2=0;
	head.pixoffset=14+12+clrtable_sz;

	fout.write((char *) (head.bmid), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(head.sz), sizeof(char) * 4);
	if (!fout.good()) return 0;

	fout.write((char *) &(head.res1), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(head.res2), sizeof(char) * 2);
	if (!fout.good()) return 0;

	fout.write((char *) &(head.pixoffset), sizeof(char) * 4);
	if (!fout.good()) return 0;

	return 1;
}
Exemplo n.º 3
0
//====================================================================
// Save network to file
//====================================================================
bool BPNet::save( ofstream &ost ) const
{
	if ( !ost.good() )
		return false;

	int numLayers = _nodeCount.size();
	int numNodes = _nodes.size();
	int numLinks = _links.size();

	ost << numLayers << endl; // num layers
	
	for(int i = 0; i != numLayers; ++i)
		ost << _nodeCount[i] << endl; // number of nodes in each layer
	
	ost << numNodes << endl; // total number of nodes
	ost << numLinks << endl; // total number of links

	// save nodes data
	for(i = 0; i != numNodes; ++i)
		_nodes[i]->save(ost);

	// save links data
	for(i = 0; i != numLinks; ++i)
		_links[i]->save(ost);
	
	if (!ost.good())
		return false;

	return true;
}
Exemplo n.º 4
0
Arquivo: Sorter.C Projeto: BVRoot/TinT
bool DealWithMatch(const vector <string> &LineList, const boost::regex &RegExpress, const DataFile &TypeEntry, ofstream &TableStream,
		   const size_t FilingIndex)
// MAJOR robustness issues here!  See notes in this function.
{
//	cerr << "Going into DealWithMatch()\n";
	bool IsSuccessful;
	const vector <string> Captures = ObtainCaptures(RegExpress, LineList[0], TypeEntry.PatternExplainCount() + 1);
//	cerr << "Got Captures\n";

	const vector <string> Descriptors = GatherInfo(LineList, Captures, TypeEntry.GiveAllPatternExplains(), 
						       TypeEntry.GiveAllAssignExpressions(), IsSuccessful);
//	cerr << "Got Descriptors\n";

	// May need to put in controls of some sort to determine whether something should be quoted or not.
	if (IsSuccessful)
	{
		TableStream << GiveDelimitedList(LineList, ',') << ',' << FilingIndex << ',' << GiveDelimitedList(Descriptors, ',') << "\n";
	}


	// This above segment prints to the appropriate subcatalogue file the following info:
	//	Filename, File Group number, Volume Name, FileSize, FilingIndex, and Date information for the file, and any other descriptor information.
	// there is always DateTime_Info for Descriptors[0]

	return(TableStream.good());
}
Exemplo n.º 5
0
static bool writeFile(const wstring &res, ofstream &fs, bkplong pos)
{
	static unsigned short magic = 0xFEFF;
	//write in Unicode16-LE
	if (!fs.good())
		return false;
	if (pos >= 0)
		fs.seekp(pos, ios_base::beg);
	else
		fs.seekp(pos + 1, ios_base::end);
	fs.write((const char *)&magic, 2);
	u16string result;
	bkplong s = res.size();
	bkplong s2 = s * sizeof(wchar_t) / sizeof(char16_t);
	result.resize(s2);
#ifdef HAVE_CODECVT
	auto& f = use_facet<codecvt<wchar_t, char16_t, mbstate_t>>(locale());
	mbstate_t mb = mbstate_t();
	char16_t* from_next;
	const wchar_t* to_next;
	f.out(mb, &res[0], &res[s], to_next, &result[0], &result[s2], from_next);
#else
	ucs4toutf16((uint16_t *)&result[0], (uint32_t *)&res[0], s);
#endif
	fs.write((const char *)result.c_str(), 2 * result.length());
	return true;
}
Exemplo n.º 6
0
void write_custom_header(ofstream &file){

  // check input file is actually an open ofstream...
  if (!file.good()){
    cerr << "ERROR - problem with file opening. Aborting..." << endl;
    exit(1);
  }
    
  // build variables
  string line;
  string header_content;
  ifstream conf(c_CUSTOM_HEADER_FILE.c_str());
  
  if (!conf){
    cerr << "ERROR: Unable to open configuration file..." << endl
	 << "Aborting!" << endl;
    exit(1);
  }
  
  // read all of the file defined by c_CUSTOM_HEADER_FILE
  while(getline(conf,line)){
      line.append("\n");
      header_content = header_content.append(line);
  }
  
  // write to your new headerfile
  file << header_content;
  
  cout << "Loaded custom header details..." << endl;
}
Exemplo n.º 7
0
bool Serializer::writeChar(ofstream &outfile, char write) {
	outfile.put(write);
	if (!outfile.good())
		return false;
	
	return true;
}
/* Print the BFS tree from a particular vertex. */
void graph_using_AL::print_bfs_tree(string start_vertex, ofstream& fout) {
    /* Check if 'fout' is good. */
    assert(fout.good());

    /* Find the start vertex. */
    map<string, set<string> >::iterator v_itr = find_vertex(start_vertex);
    if(v_itr == data.end()) {
        /* Vertex not found. */
        cerr << "Start Vertex not found." << endl;
        return;
    }

    map<string, string>  parent  ;
    map<string,    int>  distance;

    /* Do the BFS traversal.
     * The 'parent' and the 'distance' containers will be populated by this function.
     */
    BFS_visit(parent, distance, start_vertex);

    /* Printing the parent details. */
    if(debug_flag) clog << "Parent array: " << endl;
    vector<pair<string, string> > vp;
    for(map<string, string>::iterator p_itr = parent.begin(); p_itr != parent.end(); p_itr++) {
        vp.push_back(pair<string, string>(p_itr->first, p_itr->second));
        if(debug_flag) cout << p_itr->first << " <-- " << p_itr->second << endl;
    }

    print_tree_with_edges_colored(vp, "red", fout);

    return;
}
Exemplo n.º 9
0
	void BitString::save(ofstream & out) const
	{
		assert(out.good());
		out.write((char*)&length,sizeof(size_t));
		out.write((char*)&uintLength,sizeof(size_t));
		out.write((char*)data,uintLength*sizeof(uint));
	}
Exemplo n.º 10
0
 void MapperCont::save(ofstream & out) const
 {
     assert(out.good());
     uint wr = MAPPER_CONT_HDR;
     saveValue(out,wr);
     m->save(out);
 }
Exemplo n.º 11
0
bool start_log(const char *filename) {
    event_log.open(filename);
    if(!event_log.good()) {
        std::cout << "Error!: Could not open log file" << endl;
        return false;
    }
    return true;
}
////////////////////////////////////////////////////////////////////////////////
// output_read
//
// Output the given possibly corrected and/or trimmed
// read according to the given options.
////////////////////////////////////////////////////////////////////////////////
static void output_read(ofstream & reads_out, ofstream & corlog_out, int pe_code, string header, string ntseq, string mid, string strqual, string corseq, stats & tstats) {
  if(corseq.size() >= trim_t) {
    // check for changes
    bool corrected = false;
    for(int i = 0; i < corseq.size(); i++) {
      if(corseq[i] != ntseq[i]) {
	// log it
	if(corlog_out.good())
	  corlog_out << (strqual[i]-Read::quality_scale) << "\t" << (i+1) << "\t" << corseq[i] << "\t" << ntseq[i] << endl;
	// note it
	corrected = true;
	// set qual to crap
	strqual[i] = (char)(Read::quality_scale+2);
      }
    }
    if(corrected)
      tstats.corrected++;

    // update header
    if(!orig_headers) {
      if(corrected)
	header += " correct";
      unsigned int trimlen = ntseq.size()-corseq.size();
      if(trimlen > 0) {
	stringstream trim_inter;
	trim_inter << trimlen;
	header += " trim=" + trim_inter.str();
	tstats.trimmed++;
	if(!corrected)
	  tstats.trimmed_only++;
      } else {
	if(!corrected)
	  tstats.validated++;
      }
    }
    // print
    if(contrail_out)
      reads_out << header << "\t" << corseq << endl;
    else
      reads_out << header << endl << corseq << endl << mid << endl << strqual.substr(0,corseq.size()) << endl;
    if(TESTING)
      cerr << header << "\t" << ntseq << "\t" << corseq << endl;
  } else {
    tstats.removed++;
    if(uncorrected_out || pe_code > 0) {
      // update header
      header += " error";

      //print
      if(contrail_out)
	reads_out << header << "\t" << ntseq << endl;
      else
	reads_out << header << endl << ntseq << endl << mid << endl << strqual << endl;	  
    }
    if(TESTING)
      cerr << header << "\t" << ntseq << "\t-" << endl; // or . if it's only trimmed?
  }
}
Exemplo n.º 13
0
void costVec::WriteToFile(ofstream &fout)
{
  assert(fout.is_open() && fout.good());
  
  for(size_t cid = 0; cid < VEC_DIMENSION; cid++)
  {
    fout << ' ' << c[cid];
  }
}
Exemplo n.º 14
0
void AbrirArchivoParaEscribir(ofstream &archivo)
{
    cout << "  Ingrese nombre de archivo: ";
    string opt;
    bool ok = false;
    getline(cin, opt);
    getline(cin, opt);
    archivo.open(opt.c_str());
    ok = archivo.good();

    while (!ok)
    {
        cout << "  Valor incorrecto. Ingrese nombre de archivo: ";
        getline(cin, opt);
        archivo.open(opt.c_str());
        ok = archivo.good();
    }
}
Exemplo n.º 15
0
int openOfstream(ofstream & out, const char * filename)
{
  out.open(filename);
  if(!out.good()){
    std::cerr << "Cannot write to " << filename << std::endl;
    return -1;
  }
  return 0;
}
Exemplo n.º 16
0
static void InitFiles(ofstream& file_c, ofstream& file_h, const ExportParams& params)
{
    std::string name = params.name;
    Chop(name);
    std::string name_cap = name;
    transform(name_cap.begin(), name_cap.end(), name_cap.begin(), (int(*)(int)) std::toupper);

    std::string filename_c = params.name + ".c";
    std::string filename_h = params.name + ".h";

    file_c.open(filename_c.c_str());
    file_h.open(filename_h.c_str());

    if (!file_c.good() || !file_h.good())
    {
        printf("Could not open files for writing\n");
        exit(EXIT_FAILURE);
    }
}
Exemplo n.º 17
0
bool openOutputStream(ofstream &stream, string fileName) {

    stream.open(fileName.c_str());

    if (!stream.good()) {
        return false;
    }

    return true;
}
Exemplo n.º 18
0
void point::sauver(ofstream &fichier)
{
	if (!fichier.is_open()) cout << " Erreur d'ouverture " << endl;
	else
	{
		fichier << x_<<endl;
		fichier << y_<<endl;
		if (!fichier.good()) cout << " Erreur d'écriture" << endl;
		//else cout << " Ecriture terminée " << endl;
	}
}
Exemplo n.º 19
0
	void Framis::destroyClass()
	{
		cout<<"~Famis()"<<endl;
		if (outFile.good())
		{
			outFile<<"~Famis()\n";
		}
		size_t index = (this - pPool) / sizeof(Framis);

		s_data_map[index] = false;

	}
Exemplo n.º 20
0
static bool write_coltable()
{
	rgb_color white,black;

	white.blue=255;
	white.red=255;
	white.green=255;

	black.blue=0;
	black.red=0;
	black.green=0;

	fout.write((char *) &(white.blue), sizeof(char));
	if (!fout.good()) return 0;

	fout.write((char *) &(white.green), sizeof(char));
	if (!fout.good()) return 0;

	fout.write((char *) &(white.red), sizeof(char));
	if (!fout.good()) return 0;

	fout.write((char *) &(black.blue), sizeof(char));
	if (!fout.good()) return 0;

	fout.write((char *) &(black.green), sizeof(char));
	if (!fout.good()) return 0;

	fout.write((char *) &(black.red), sizeof(char));
	if (!fout.good()) return 0;

	//fout.write((char *) &(black.alpha), sizeof(char));
	//if (!fout.good()) return 0;

	return 1;
}
Exemplo n.º 21
0
	void Token::outputIntoFile(ofstream& outputFile){
	//	cout << token->m_lexem<<"  "<<((TokenERROR*)(token))->m_errorBody<<"  "<<token->m_location<<endl;

	if (outputFile.is_open())
	{
		if(outputFile.good())
		{
			outputFile<<this->m_lexem<<"\t"<<this->m_lexemCode<<"\t"<<this->m_location<<endl;
		}


	}
	}
Exemplo n.º 22
0
int HTTPRequest::copyToFile(ofstream& ofs)
{
	size_t contentLength = atoi(getHTTPHeader("Content-Length").c_str());

	if (ofs.good())
	{
		ofs.write(m_requestBody.c_str(), contentLength);
	}

	if (ofs.bad())
		return -1;

	return 0;
}
Exemplo n.º 23
0
/* append P2P message data to CSV file */
static void write_p2p_data( AllData& alldata, ofstream& csvFile,
    const string& csvFileName ) {

    assert( csvFile.good() );

    VerbosePrint( alldata, 2, false,
                  " appending P2P message data to file: %s\n",
                  csvFileName.c_str() );

    static const string LINE_PREFIX= "P2P";

    if ( 0 == alldata.myRank ) {

        /* write headline */
        csvFile << endl << LINE_PREFIX << ';'
                << "Process;Send Invocations;Recv. Invocations;Send Bytes;Recv. Bytes;Duration (s)"
                << endl;

    }

    /* write P2P message data */

    map< uint64_t, MessageData >::iterator it= alldata.messageMapPerRank.begin();
    map< uint64_t, MessageData >::iterator itend= alldata.messageMapPerRank.end();
    while ( itend != it ) {

        const uint64_t& proc_id= it->first;

        const uint64_t& count_send= it->second.count_send.cnt;
        const uint64_t& count_recv= it->second.count_recv.cnt;
        const uint64_t& bytes_send= it->second.bytes_send.sum;
        const uint64_t& bytes_recv= it->second.bytes_recv.sum;
        const double duration= it->second.duration_send.sum / alldata.timerResolution;

        const string& proc_name= alldata.processIdNameMap[ proc_id ];
        assert( 0 != proc_name.length() );

        csvFile << LINE_PREFIX << ';'
                << proc_name << ';'
                << count_send << ';'
                << count_recv << ';'
                << bytes_send << ';'
                << bytes_recv << ';'
                << duration << endl;

        it++;

    }
}
Exemplo n.º 24
0
/* append function data to CSV file */
static void write_func_data( AllData& alldata, ofstream& csvFile,
    const string& csvFileName ) {

    assert( csvFile.good() );

    VerbosePrint( alldata, 2, false,
                  " appending function data to file: %s\n",
                  csvFileName.c_str() );

    static const string LINE_PREFIX= "FUNCTION";

    if ( 0 == alldata.myRank ) {

        /* write headline */
        csvFile << LINE_PREFIX << ';'
                << "Process;Function;Invocations;Excl. Time (s);Incl. Time (s)" << endl;

    }

    /* write function data */

    map< Pair, FunctionData, ltPair >::iterator it= alldata.functionMapPerRank.begin();
    map< Pair, FunctionData, ltPair >::iterator itend= alldata.functionMapPerRank.end();
    while ( itend != it ) {

        const uint64_t& proc_id= it->first.a;
        const uint64_t& func_id= it->first.b;
        const uint64_t& count= it->second.count.cnt;
        const double excl_time= it->second.excl_time.sum / alldata.timerResolution;
        const double incl_time= it->second.incl_time.sum / alldata.timerResolution;

        const string& proc_name= alldata.processIdNameMap[ proc_id ];
        assert( 0 != proc_name.length() );

        const string& func_name= alldata.functionIdNameMap[ func_id ];
        assert( 0 != func_name.length() );

        csvFile << LINE_PREFIX << ';'
                << proc_name << ';'
                << func_name << ';'
                << count << ';'
                << excl_time << ';'
                << incl_time << endl;

        it++;

    }
}
Exemplo n.º 25
0
int main(int argc, char * argv[]){
	
//Local variables for time functions
double wall_time, cpu_time; 

//Open input file
infile.open(argv[1]);
if(!infile.good()){
	cerr << "The input file name was not correct. Please try again." << endl;
	exit(0);
}
//Open output file
outfile.open(argv[2]);
if(!outfile.good()){
	cerr << "The output file name was not correct. Please try again." << endl;
	exit(0);
}

//Init Semaphores
sem_init(&Full,0, 0);
sem_init(&Empty, 0, 10);
sem_init(&Crit,0,1);

//Timing
start_timing();
cout << "Starting timing: " << endl;

//Create Producer and Consumer
pthread_t tProducer; pthread_t tConsumer;
pthread_create(&tProducer, NULL, threadProducer,NULL);
pthread_create(&tConsumer, NULL, threadConsumer,NULL);

pthread_join(tProducer, NULL); pthread_join(tConsumer, NULL); 

stop_timing();
wall_time = get_wall_clock_diff();
cpu_time  = get_CPU_time_diff();
cout << "The time it took as wall time is: " << wall_time << endl;
cout << "The time it took as CPU time is: " << cpu_time << endl;

//Close files, now finished
infile.close(); outfile.close();

//Destory Semaphores
sem_destroy(&Crit); sem_destroy(&Empty); sem_destroy(&Full);
return(0);
}
/* To print the graph into a file in 'dot' graph description language format. */
void graph_using_AL::print_to_file(ofstream& fout) {
    if(empty()) return;
    assert(fout.good());
    string arrow      = ((d_type == directed_graph) ? " -> "    : " -- "   );
    string graph_type = ((d_type == directed_graph) ? "digraph " : "graph ");

    map<string, set<string> >::const_iterator map_itr;
    set<string>  ::const_iterator set_itr;

    fout << graph_type << name << "{" << endl;

    graph_using_AL g_temp = *this;

    set<string> edges;
    ostringstream oss;
    for(map_itr = g_temp.data.begin(); map_itr != g_temp.data.end(); map_itr ++) {
        if(map_itr->second.begin() == map_itr->second.end()) {
            fout << "\t" << "\"" << map_itr->first << "\"" << ";\n";
        }
        else {
            for(set_itr = map_itr->second.begin(); set_itr != map_itr->second.end(); set_itr ++) {
                fout << "\t"
                     << "\"" << map_itr->first  << "\""
                     << arrow
                     << "\"" << *set_itr        << "\"";

                /* For weighted graph, print the individual edge weights. */
                if (w_type == weighted_graph) {
                    fout << "[label=" << get_weight(map_itr->first, *set_itr) << "]";
                }

                fout << "; \n";

                /* Delete the corresponding reverse-edge in the undirected graph. */
                if((d_type == undirected_graph) && (map_itr->first != *set_itr)) {
                    set<string>::iterator itr_temp = g_temp.data.find(*set_itr)->second.find(map_itr->first);
                    g_temp.data.find(*set_itr)->second.erase(itr_temp);
                }
            }
        }
    }

    fout << "}" << endl;

    return;
}
Exemplo n.º 27
0
bool saveSched(ofstream &outfile, char sched[][4], const int &SLOT, 
        const int &DAY, string &pName, bool &isSaved){
    char choice;
    bool isValid = false;
    if(pName == "Jeff"){
        outfile.open("sched_J_001.dat");
    }
    else if(pName == "Ann"){
        outfile.open("sched_E_001.dat");
    }
    cout << "WARNING! By choosing this option, your previous schedule profile will be overwritten.\n";
    while(!isValid){
        cout << "Save all changes(Y/N)? ";
        cin >> choice;
        switch(toupper(choice)){
            case 'Y':{
                for(int slotCT = 0; slotCT < SLOT; slotCT++){
                    for(int dayCT = 0; dayCT < DAY; dayCT++){
                        if(sched[slotCT][dayCT] != 'x') sched[slotCT][dayCT] = '.';
                        outfile << sched[slotCT][dayCT] << " ";
                    }
                    outfile << endl;
                }
                outfile.close();
                if(outfile.good()){
                    cout << "File saved.\n";
                    isValid = true;
                    return true;
                }
            }
            case 'N':{
                cout << "Exit without saving(Y/N)? ";
                cin >> choice;
                if(toupper(choice) == 'Y') return true;
                else if(toupper(choice) == 'N'){
                    cout << "Invalid input! Please try again.\n";
                    isValid = false;
                    break;
                }
            }
            default:{
                cout << "Invalid input! Please try again.\n";
            }
        }
    }
}
Exemplo n.º 28
0
bool openFile( const string fname, ofstream &fobj )
   {
   // vars 
   bool success = false;

   // clear and open
   fobj.clear();
   fobj.open(fname.c_str());

   // check for file opening success
   if( fobj.good() )
     {
     success = true;
     }   

   // return success state
   return success;
   }
Exemplo n.º 29
0
bool Serializer::writeInt(ofstream &outfile, int write) {
	char *buf = new char[4];
	bool negative = write < 0;

	buf[3] = (char)(write / ONE_SHIFT_ZERO);
	buf[2] = (char)(write / ONE_SHIFT_ONE);
	buf[1] = (char)(write / ONE_SHIFT_TWO);
	buf[0] = (char)(write / ONE_SHIFT_THREE);

	if (negative)
		buf[0] &= (char)0x80;
	
	outfile.write(buf, 4);
	if (!outfile.good())
		return false;
	
	return true;
}
void
CollisionDetector::printCollisionsDebug(
	ofstream &ofs )
{
	assert( ofs.good() );

	if( !collisions_.empty() )
	{
		sort( collisions_.begin(), collisions_.end(), 
			willCollideFirst );

		for_each( collisions_.begin(), collisions_.end(),
			[&] ( CollisionInfo& collision )
		{
			ofs << collision << endl;
		} );
		ofs << endl;
	}
}