Пример #1
0
void GUI::newGame(){
	fin.close();
	fin.clear();
	delete env;
	delete agent;
	delete evaluator;

	fin.open(file_name_input);
	if(fin){
		current_time=0;
		env=new Environment(fin);
		evaluator=new Evaluator(env);
		agent=new Agent();
        dirty_degree = evaluator->DirtyDegree();
        consumed_energy = evaluator->ConsumedEnergy();

		agente_reactivo_btn->enable();
		display_btn->disable();
		busqueda_profundidad_btn->enable();
		busqueda_anchura_btn->enable();
		escalada_btn->enable();
        busqueda_coste_btn->enable();
	}
	else{
		fin.clear();
		char temp[1000]={"map/"};
		strcat(temp,file_name_input);
		fin.open(temp);
		if(fin){
			current_time=0;
			env=new Environment(fin);
			evaluator=new Evaluator(env);
			agent=new Agent();
            dirty_degree = evaluator->DirtyDegree();
            consumed_energy = evaluator->ConsumedEnergy();


			agente_reactivo_btn->enable();
			display_btn->disable();
		    busqueda_profundidad_btn->enable();
			busqueda_anchura_btn->enable();
			escalada_btn->enable();
            busqueda_coste_btn->enable();
		}
		else{
			agente_reactivo_btn->disable();
			display_btn->disable();
		    busqueda_profundidad_btn->disable();
			busqueda_anchura_btn->disable();
            busqueda_coste_btn->disable();
			escalada_btn->disable();
			error_glui=GLUI_Master.create_glui("Error",0,100,100);
				char error_message[1000]="File ";
				strcat(error_message,file_name_input);
				strcat(error_message," can't be open");
				new GLUI_StaticText(error_glui,error_message);
				new_map_ok_btn=new GLUI_Button(error_glui,"OK",ERROR_OK_BTN_ID,control_cb);
		}
	}
}
Пример #2
0
//private function called by load(). Passed parameter is the file (ifstream) as imported by load()
//returns integer of number of columns and rows. Returns negative value if invalid grid
int Grid::getSize(ifstream& sourceFile)
{
	int puzSize=0, rowLength;
	string tempString;

	//count how many rows of text
	while(sourceFile.good()){
		getline(sourceFile, tempString);
		puzSize++;
	}
	
	sourceFile.seekg(0,ios::beg);	//move cursor back to beginning
	sourceFile.clear();				//clear error flags
	
	//go through each line again, checking there are the right number of columns in each row
	while(!sourceFile.eof()){
		getline(sourceFile, tempString);
		rowLength = tempString.length();
		if(rowLength!=puzSize){ //if # of columns does not match # of rows
			cout << "Wrong number of columns in this row: "<<tempString<<endl;
			return -1; //if there is a problem, return negative number (and exit)
		}
	}
	sourceFile.seekg(0,ios::beg);	//when finished, make sure to leave cursor at beginning of file
	sourceFile.clear();				//clear error flags
	return puzSize;
}
Пример #3
0
size_t sprawdz_baze(ifstream &baza_pytan){
    if( !baza_pytan.good() )  {cout << "bazaZla\n"; return -1;}
    baza_pytan.clear();
    baza_pytan.seekg(0, ios::beg);
    baza_pytan.unsetf(std::ios_base::skipws);
    size_t line_count = count(istream_iterator<char>(baza_pytan),istream_iterator<char>(), '\n');
    baza_pytan.clear();
    baza_pytan.seekg(0,ios::beg);
    return line_count;
}
Пример #4
0
size_t FileSize(ifstream& is) {
  const streampos pos = is.tellg();
  is.clear();
  is.seekg(is.beg);
  is.ignore(numeric_limits<streamsize>::max());
  const size_t size = is.gcount();
  is.clear(); //clear EOF (set by ignore)
  is.seekg(pos);
  return size;
}
void beginScheduling(Scheduling& task, list<Process>& proc,ifstream& file, string& schFileName){
	openFile(file,schFileName);
	readResource(file,task);
	file.clear();
	file.close();
	openFile(file,task.ProcFile);
	getProcesses(file,proc);
	file.clear();
	file.close();
}   
Пример #6
0
bool openBinaryFile(string s, ifstream& BIT)
{
  BIT.open(s.c_str(), ios::in|ios::binary);

  char ch[1];
  BIT.read(ch,1);
  bitset<8> b;
  
  b = ch[0];
  bool bfile_SNP_major = false;
  bool v1_bfile = true;
  
  if((b[2]&&b[3]&&b[5]&&b[6]) &&
     !(b[0]||b[1]||b[4]||b[7]))
    {
      BIT.read(ch,1);
      b = ch[0];
      if((b[0]&&b[1]&&b[3]&&b[4])&&
	 !(b[2]||b[5]||b[6]||b[7]))
	{
	  BIT.read(ch,1);
	  b = ch[0];
	  if(b[0]) bfile_SNP_major = true;
	  else bfile_SNP_major = false;
	  
	} else v1_bfile = false;
    } else v1_bfile = false; //end of if b....
  
  if(!v1_bfile)
    {
      BIT.close();
      BIT.clear();
      BIT.open(s.c_str(), ios::in|ios::binary);
      BIT.read(ch,1);
      b = ch[0];
    }

  if((!v1_bfile)&&(b[1]||b[2]||b[3]||b[4]||b[5]||b[6]||b[7]))
    {
      bfile_SNP_major = false;
      BIT.close();
      BIT.clear();
      BIT.open(s.c_str(), ios::in|ios::binary);
    }
  else if(!v1_bfile)
    {
      if(b[0]) bfile_SNP_major = true;
      else bfile_SNP_major = false;
    }

  return bfile_SNP_major;
}
Пример #7
0
/*-------------------------------------------------------
opens files to be used as input and output
Receives: input, output
Returns: nothing
---------------------------------------------------------*/
char openfiles (ifstream &input1, ofstream &output1)
{	
	char infile1[20],
		 outfile1[20];

	// opens the file that will be used as the first input file
	cout << "Enter the name of the first input file to be opened: ";
	cin >> infile1;
	input1.open(infile1, ios::nocreate);
	while (input1.fail())
	{
		input1.clear();
		cout << "Could not open " << infile1 
			 << " please re-enter the file name: " << endl;
		cin >> infile1;
		input1.open(infile1, ios::nocreate);
	}
	
	// opens the file that will be used as the output file
	cout << "Enter the name of output file to be opened: ";
	cin >> outfile1;
	output1.open (outfile1, ios::app);    // creates output file for output

	return infile1[20];
}//end openfiles
Пример #8
0
void GlowNodeGroup::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GlowNodeGroup: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_NodeGroup: break;
      case glow_eSave_NodeGroup_nodeclass_part: 
        GlowNodeClass::open( fp);
        break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowGroup:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
Пример #9
0
void SpecialStack::inicializar(ifstream& file){
    char str[20];
    string linea;
    if (file.is_open()){
        file.clear();
        file.seekg(4, ios::beg);//coloca el offset donde esta el head del availlist en el header
        file.getline(str, 20, ';');
        linea = str;
        int posDisp = cadena2Int(linea);//aqui toma el head del availlist

        while (posDisp != -1){
            cout << "En SpecialStack::inicializar pos que recibe : " << posDisp << endl;
            file.seekg(offsetRegistro+(sizeRegistro * posDisp ));// se va a la poscion en el archvo que indica posDisp
            file.getline(str, 20, ';');
            linea = str;
            availlist.insert(availlist.begin()+0, posDisp);//agrega la poscion al availlist
            VIPList.agregar(posDisp);//agrega la posicion al VIPList que es la lista ordenada de las posciones en el availlist
            posDisp = siguientePosicionDisponible(linea);
        }
        availlist.insert(availlist.begin()+0, posDisp);
        VIPList.agregar(posDisp);
    } else {
        cerr << "ERROR: no se pudo abrir el archivo para lectura de levantar header" << endl;
    }

}
//template <class Object>
void RunList(ifstream& stream){
   char iord;
   int number;
   
   //string dummy;
   //getline(stream, dummy);
  
   char dummy[256];
   stream.getline(dummy, 256); 
   
   List<int> list;
   ListItr<int> listItr = list.zeroth();
   
   while(stream >> iord >> number){
      if(iord == 'i'){
      list.insert(number, listItr);
      listItr.advance();
      //cout << "Inserted " << number << endl;
      }
      
      else /*if(iord == 'd')*/{
      list.remove(number);
      //cout << "Deleted " << number << endl;
      }
   }
   
   stream.clear();
   stream.seekg(0, ios::beg); 
}
void RunSkipList(ifstream& stream){
    char iord;
    int number;

    //string dummy;
    //getline(stream, dummy);
    
    char dummy[256];
    stream.getline(dummy, 256);
    
    SkipList<int> skiplist(1,250000);
    while(stream >> iord >> number){
        if(iord == 'i'){
            skiplist.insert(number);
        }
        else{
            skiplist.deleteNode(number);
        }
    }

    stream.clear();
    stream.seekg(0, ios::beg);


}
Пример #12
0
Файл: GxP.cpp Проект: SCNya/GxP
void create(ifstream &in)
{
    int i(0);
    string s;
    getline(in, s);
    n = new int (s.size());
    m = new int (1);
    while (getline(in, s)) (*m)++;
    mass = new bool*[(*m)];
    for (; i < (*m); i++)
        mass[i] = new bool[(*n)];
    cout << "m= " << *m << endl;
    cout << "n= " << *n << endl;
    *m = 0;
    in.clear();
    in.seekg(0, ios::beg);
    while (getline(in, s))
        {
            for (i = 0; i<(*n); i++)
                if (s[i] == '+') mass[(*m)][i] = true;
                else
                    mass[(*m)][i] = false;
            (*m)++;
        }
}
void RunStackAr(ifstream& stream){
   char iord;
   int number;
   
   //string dummy;
   //getline(stream, dummy);
  
   char dummy[256];
   stream.getline(dummy, 256);

   StackAr<int> stack(250000);

   while(stream >> iord >> number){
      if(iord == 'i'){
        stack.push(number);
      }
      
      else /*if(iord == 'd')*/{
        stack.pop();
        //cout << "Deleted " << number << endl;
      }
   }
   
   stream.clear();
   stream.seekg(0, ios::beg);
}
Пример #14
0
void open_file ( ifstream &in, const string &file_name ) {

	in.close();
	in.clear();
	
	in.open ( file_name.c_str() );
}
Пример #15
0
int main()
{
	infile.open("StkQFile1.txt");
	outfile.open("Result.dat");
	Stack stackTest;

	while (infile)
	{
		stackTest.read();
		stackTest.reverse();
		stackTest.print();
		stackTest.clear();
	}
	infile.clear();
	infile.seekg(0);
	outfile.close();
	outfile.open("Full.dat");

	while (infile)
	{
		stackTest.readFull();
	}
	stackTest.reverse();
	stackTest.printFull();

	system("pause");
	return 0;
}
Пример #16
0
void GrowToolbar::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowToolbar: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowToolbar: break;
      case glow_eSave_GrowToolbar_grownode_part: 
        GrowNode::open( fp);
        break;
	// case glow_eSave_GrowToolbar_nc: 
        // nc = new GlowNodeGroup( ctx, n_name);
        // nc->open( fp);
        // break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowToolbar:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
shared_ptr<LobKo::TaskHolder> LobKo::TaskHolderBuilder::build(ifstream& file_in) {
    shared_ptr<TaskHolder> spBuildThis(new TaskHolder);

    std::string str;

    file_in.clear();
    bool flag = true;
    do {
        std::getline(file_in, str);
        if ( file_in.bad() || file_in.fail() ) {
            break;
        } else if ( file_in.eof() ) {
            flag = false;
        }
        std::istringstream istream(str);

        string res;
        string filepath;

        istream >> res >> filepath;
        if ( res.size() && res[0] != '#' ) {
            if ( filepath.size() ) {
                spBuildThis->addTask(Task(res, filepath));
            }
        }
    } while (flag);


    return spBuildThis;
}
Пример #18
0
void GlowCustomColors::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int 		csize = 0;

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GlowCustomColors: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_CustomColors: break;
      case glow_eSave_CustomColors_colortheme_lightness: fp >> colortheme_lightness; break;
      case glow_eSave_CustomColors_is_default_colortheme: fp >> is_default_colortheme; break;
      case glow_eSave_CustomColors_colors_size: fp >> csize; break;
      case glow_eSave_CustomColors_colors:
	for ( int i = 0; i < csize; i++) {
	  fp >> colors[i][0]; fp >> colors[i][1]; fp  >> colors[i][2];
	}
	break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GlowCustomColors:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
Пример #19
0
string loadSched(ifstream &infile, char sched[][4], const int &SLOT, 
        const int &DAY, const int &MAX_NAME, char choice[], bool &isLoaded){
    do{
        cout << "Enter the profile name to view: ";
        char fName[MAX_NAME];
        cin.get(choice, '\n');
        if(strncmp(choice, "Jeff", MAX_NAME) == 0){
            strncpy(fName, "sched_J_001.dat", MAX_NAME);
        }
        else if(strncmp(choice, "Ann", MAX_NAME) == 0){
            strncpy(fName, "sched_E_001.dat", MAX_NAME);
        }
        infile.open(fName);
        if(infile.good()){
            isLoaded = true;
        }
        else{
            isLoaded = false;
            infile.clear();
        }
    }while(!isLoaded);
    getSched(infile, sched, SLOT, DAY);
    infile.close();
    return choice;
}
Пример #20
0
	//计算单词数
	void wordCount(ifstream &file){
		string s;
		while(getline(file,s)){
			string str="";
			for(int i=0;i<s.length();i++){
				if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){
					str+=s[i];
				}
				else{
					if(str.length()>1){
						sumW++;
					}
					str="";
				}
			}
			if(str.length()>1){
				sumW++;
			}
		}
		file.clear();
		file.seekg(0);
		useW=true;
		if(useC)
			cout<<endl;
		cout<<"文件中的单词数为:"<<sumW;
	}
Пример #21
0
double averageGrade(double sum, char gender, ifstream& file) {

    // Instantiate helper variables
    double avg, count = 0;
    char testGender;

    // While the file is available for reading, take in the
    // gender from each line to 'testGender'. If testGender
    // matches the gender we care about, increment the counter.
    // Finally, ignore the rest of the line.
    while (file >> testGender) {
        if (testGender == gender) {
            count++;
        }
        file.ignore(50, '\n');
    }

    // Reset the readable file back to its initial state so we
    // can read it again later
    file.clear();
    file.seekg(0, ios::beg);

    // Compute and return the average
    avg = sum / count;
    return avg;

}
Пример #22
0
void recreate_log(char* pstr, ifstream& fin) {

	int cnt=0;
	char tmp[100]={0,};

	sprintf(tmp,"%s_rmv.out",pstr);
	FILE* pf = fopen(tmp,"w");
	if(!pf) {
		printf("File open failed : %s\n", tmp);
		return;
	}

	fin.clear();
	fin.seekg(0, ios::beg);

	while(!fin.eof()) {

		fin.getline(tmp,100);
		cnt++;

		vector<int>::iterator it = find(vec_miss.begin(), vec_miss.end(), cnt);
		if(it == vec_miss.end())
			fprintf(pf,"%s\n",tmp);
	}

	fclose(pf);
}
Пример #23
0
// Computes the number of vertices and edges in the network.
void FindStats(int& vertices, long int& edges, ifstream& file)
{
  char* buffer;
  long int entry1 = 0;
  long int entry2 = 0;
  string lineread;

  while(std::getline(file, lineread)) // Read line by line
  {
    buffer = new char [lineread.size()+1];
    strcpy(buffer, lineread.c_str());
    sscanf(buffer, "%ld %ld %*s", &entry1, &entry2); // "%*s" ignores the rest of the line.
    if (entry1 != entry2)
    {
      edges++;
    }
    if (entry1 > vertices)
    {
      vertices = entry1;
    }
    if (entry2 > vertices)
    {
      vertices = entry2;
    }
    delete[] buffer;
  }
  vertices++;
  file.clear();
  file.seekg(0, ios::beg);
  return;
}
Пример #24
0
//Character scan to string
bool modelA::scanStrFile(ifstream& ifoper,string& scanStr)
{
	int i=0;
	  char inchar[256]="\0";
	  char charBuff='\0';
	  while((charBuff!=char(32))&&(charBuff!='\n')&&(!ifoper.eof()))
	  {
           charBuff=ifoper.get();
		  if((charBuff!=char(32))&&(charBuff!='\n'))
		   {
			   inchar[i]=charBuff;
		       ++i;
		   }		   
	  }

	  //Get last read char
	  scanStr=inchar;

	  if(!ifoper.eof())
		  return true;
	  else
	  {
		  ifoper.clear();
		  ifoper.seekg(0,ios_base::beg);
		  return false;
	  }
}
Пример #25
0
void LightObject::readParams(ifstream &file, unsigned int &lineNumber, unsigned int &level)
{
	string line;
	level++;
	readline(file, line, lineNumber);
	if (line.find("{") != 0)
	{
		cout << "*****Invalid start of light object params at line: " << lineNumber << " : expected { found " << line << endl;
		return;
	}
	do
	{
		file.clear();
		string text;
//		text.clear();
		// Read data for this object
		readline(file, line, lineNumber);
		basic_stringstream<char> lineStream;
		lineStream.str(line);
		float fr, fg, fb;
		int r, g, b;
		if (line.find("redf") == 0)
		{
			lineStream >> text >> fr;
			this->l->setRed(int(255.0 * fr));
		}
		else if (line.find("bluef") == 0)
		{
			lineStream >> text >> fb;
			this->l->setBlue(int(255.0 * fb));
		}
Пример #26
0
void SphereObject::readParams(ifstream &file, unsigned int &lineNumber, unsigned int &level) 
{  
	string line;
	level++;
	readline(file, line, lineNumber);
	if (line.find("{") != 0)
	{
		cout << "*****Invalid start of sphere parms at line: " << lineNumber << " : expected { found " << line << endl;
		return;
	}
	//cout << "Reading sphere types num:" << lineNumber << endl;
	do
	{
		file.clear();
		string text;
//		text.clear();
		// Read data for this object
		readline(file, line, lineNumber);
		basic_stringstream<char> lineStream;
		lineStream.str(line);
		if (line.find("radius") == 0)
		{
			lineStream >> text >> this->radius;
		}
		else if (line.find("}") == 0)
		{
			// Leaving this object
		}
	}
void clearStream(ifstream& inputStream)
{
    inputStream.clear();

    // прочитаме останалата част от реда
    inputStream.ignore(MAX_LINE_LENGTH, '\n');
}
void RunStackLi(ifstream& stream){
   char iord;
   int number;

   //string dummy; 
   //getline(stream, dummy); // clears first line in data.txt

   char dummy[256];
   stream.getline(dummy, 256);
   
   StackLi<int> stack;

   while(stream >> iord >> number){
       if(iord == 'i'){
           stack.push(number);
       }

       else{
           stack.pop();
       }
   }

   stream.clear();
   stream.seekg(0, ios::beg);
      
}
Пример #29
0
/*!
  \param fp	Input file.
*/
void GrowXYCurve::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];

  for (;;)
  {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowXYWindow: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowXYCurve: break;
      case glow_eSave_GrowXYCurve_trend_part: 
        GrowTrend::open( fp);
        break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowXYCurve:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}
Пример #30
0
void GrowSlider::open( ifstream& fp)
{
  int		type;
  int 		end_found = 0;
  char		dummy[40];
  int		tmp;

  for (;;) {
    if ( !fp.good()) {
      fp.clear();
      fp.getline( dummy, sizeof(dummy));
      printf( "** Read error GrowSlider: \"%d %s\"\n", type, dummy);      
    }

    fp >> type;
    switch( type) {
      case glow_eSave_GrowSlider: break;
      case glow_eSave_GrowSlider_direction: fp >> tmp; 
	direction = (glow_eDirection)tmp; break;
      case glow_eSave_GrowSlider_max_value: fp >> max_value; break;
      case glow_eSave_GrowSlider_min_value: fp >> min_value; break;
      case glow_eSave_GrowSlider_max_pos: fp >> max_pos; break;
      case glow_eSave_GrowSlider_min_pos: fp >> min_pos; break;
      case glow_eSave_GrowSlider_grownode_part: 
        GrowNode::open( fp);
        break;
      case glow_eSave_End: end_found = 1; break;
      default:
        cout << "GrowSlider:open syntax error" << endl;
        fp.getline( dummy, sizeof(dummy));
    }
    if ( end_found)
      break;
  }
}