// A little procedure to read floating point numbers from an input string
double numberize(std::ifstream& input, int &precise)
{
  char c;
  double number = 0;
  bool negative, after;

  precise = 0;
  negative = after = false;
  
  // Pass SPACE-characters
  while (((c = input.get()) == ' ') || (c == '\n'));

  // Read double-type number from input-stream
  if (c == '-') negative = true;
  while((c != ' ') && 
	(c != '\n') && 
	(!input.eof())) {
    if (c == '.') after = true;
    else if ((c < 48) || (c > 57)) number = -1; //return;
    else {
      //  cout << c;
      number = (number * 10) + (c - 48);
      if (after) precise++;
    }
    c = input.get();
  }

  number = number * pow(10,(-precise));
  if (negative) number = -number;
  // cout << "\nNumber is: " << number << endl;
  return number;
}
void Entite_graphique::LoadParameters(std::ifstream &fichier)
{
    char caractere;
    do
    {
        fichier.get(caractere);
        if(caractere == 't')
        {
            fichier.get(caractere);
            if(caractere == 'x')
                fichier>>m_decalage.x;
            if(caractere == 'y')
                fichier>>m_decalage.y;
        }
        if(caractere == 's')
        {
            fichier.get(caractere);
            if(caractere == 'x')
                fichier>>m_scale.x;
            if(caractere == 'y')
                fichier>>m_scale.y;

            if(m_scale.x == 0)
                m_scale.x = 100;
            if(m_scale.y == 0)
                m_scale.y = 100;
        }
Example #3
0
void getNextWord(std::ifstream& inFile, std::string& token, std::string tokenizer, int64_t endOffSet)
{
   token.clear();
   char byte[1];

  while(inFile.good())
  {
     if(inFile.tellg() >= endOffSet)
       return;

     byte[0] =inFile.peek();
     if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
       inFile.get();
     }else{
       break;
     }
  }


  while(inFile.good()){
   byte[0] = inFile.get();   
   if(byte[0]=='\n' || byte[0] == tokenizer.c_str()[0]){
     return;
   }
    token.append(byte,1);
   }
}
Example #4
0
std::string CppLogger::getVar(std::ifstream& file)
{
	std::string result = "";

	while (file.good())
	{
		char c = file.get();
		if (c == '=' || c == '\n')
		{
			break;
		}
		else if (c == '#')
		{
			while (file.good() && file.get() != '\n')
			{
			}
			break;
		}
		else if (c == ' ')
		{
			continue;
		}

		result += c;
	}

	return result;
}
Example #5
0
/******************************************************************************************************
void strip_file(std::ifstream& inStream, std::string fileName)

Description: Opens a input file and strips symbols and outputs to temp file.

Parameters: std::ifstream& inStream, std::string fileName

Pre-Conditions: Input file must be opened.
Post-Conditions: Input file will be stripped of symnbols and output to temp file.
******************************************************************************************************/
void strip_file(std::ifstream& inStream, std::fstream& tempStream)
{
    std::vector<char> lines;//create a vector to hold characters.

    while (inStream)//iterate through each line in file.
    {
	   char ch;
	   int count = 0;
	   ch = inStream.get();//Get character from line.
	   while (ch != EOF)//While not end of line.
	   {
		  if (ch != ',' && ch != '[' && ch != ']')//Do not add these symbols.
		  {
			 lines.push_back(ch);//Push character to vector.
			 count++;//inc count, used to loop through vector.
		  }
		  ch = inStream.get();//get next char in line.
	   }
	   for (int i = 0; i < count; i++)
	   {

		  //std::cout << lines[i];  //Outputs each line in file to console.
		  tempStream << lines[i];//Outputs to temp.txt file

	   }
	   lines.clear();//Clears the vector of all values.
    }
    inStream.clear();//clears the end of file flag (eof).
    inStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.
    tempStream.clear();//clears the end of file flag (eof).
    tempStream.seekg(0L, std::ios::beg);//Move back to the beginning of the input file stream.

}//end strip_file
Example #6
0
AnimatedObjModel::DataCounts AnimatedObjModel::readFileCounts(std::ifstream& _dataStream)
{	
	DataCounts counts;

	char tInput;
	counts.positions = 0;
	counts.texCoords = 0;
	counts.normals = 0;
	counts.faces = 0;
	counts.groups = 0;
	counts.bones = 0;

	_dataStream.get(tInput);
	while(!_dataStream.eof())
	{
		if(tInput == 'v')
		{
			_dataStream.get(tInput);
			if(tInput == ' ') 
			{
				counts.positions++;
			}

			if(tInput == 't')
			{
				counts.texCoords++;
			}

			if(tInput == 'n')
			{
				counts.normals++;
			}
		}

		if(tInput == 'g')
		{
			counts.groups++;
		}

		if(tInput == 'f')
		{
			counts.faces++;
		}

		if (tInput == 'b')
		{
			counts.bones++;
		}

		while(tInput != '\n')
		{
			_dataStream.get(tInput);
		}

		_dataStream.get(tInput);
	}

	return counts;
}
Example #7
0
int
MiscReadCharsAndDoubleFromFile(
  std::ifstream& ifs,
  std::string&   termString,
  double*        termValue,
  bool&          endOfLineAchieved)
{
  int iRC = UQ_OK_RC;
  endOfLineAchieved = false;

  char c = ' ';
  while (c == ' ') {
    ifs.get(c);
    if ((ifs.rdstate() & std::ifstream::failbit)) {
      iRC = UQ_FAILED_READING_FILE_RC;
      break;
    }
  };

  char term[512];
  unsigned int pos = 0;

  if (!iRC) {
    while ((pos < 512) && (c != '\n') && (c != '\0') && (c != ' ')) {
      term[pos++] = c;
      if ((ifs.rdstate() & std::ifstream::failbit)) {
        iRC = UQ_FAILED_READING_FILE_RC;
        break;
      }
      ifs.get(c);
    };
  }

  if (!iRC) {
    if (c == '\n') endOfLineAchieved = true;
    term[pos] = '\0';
    termString = term;
    //std::cout << "Read chars = " << termString << std::endl;
    if (termValue) {
      if (termString == std::string("inf")) {
        *termValue = INFINITY;
      }
      else if (termString == std::string("-inf")) {
        *termValue = -INFINITY;
      }
      else if (termString == std::string("nan")) {
        *termValue = nan("");
      }
      else {
        *termValue = strtod(termString.c_str(),NULL);
      }
    }
  }

  return iRC;
}
	std::string readLine(std::ifstream &in_)
	{
		std::string result = "";
		while (in_.peek() != '\n' && in_.eof() == false)
		{
			result += in_.get();
		}
		in_.get();
		return result;
	}
std::string Get_Rest_Of_File_As_String(std::ifstream & infile){
	std::string data;
	char temp = infile.get();
	while(infile){
		data+=temp;
		temp = infile.get();
	}

	return data;
}
Example #10
0
void state::populate(std::ifstream &file)
{
	char row[50], *p, temp[5];
	char ipSymbol = 'a', ip;
	int s;
	file.get(op);
	file.get();
	file.getline(row, 50);
	p = row;
	while(*p!='\0')
	{
		std::sscanf(p, "%s", temp);
		if(temp[0] == '~')
		{
		}
		else if(temp[0] == 'F')
		{
			finalState = true;
		}
		else
		{
			tCount++;
			ip = ipSymbol;
			s = temp[0] - 48;
			transitionTable = (struct transition *) std::realloc(transitionTable, sizeof(transition) * tCount);
			transitionTable[tCount - 1].ip = ip;
			transitionTable[tCount - 1].t = s + 48;
			/*
			if(s < sCount)		//Transiting to a preceding state
			{
				transitionTable[tCount - 1].t = s + 48;
			}
			else
			{
				refTable = (struct globalRef *) std::realloc(refTable, sizeof(globalRef) * (s+1));
//				refTable[s].addr = new state;
				transitionTable[tCount - 1].t = refTable[s].stateName = s + 48;
			}
			*/
		}

		while(*p != ' ')
		{
			if(*p == '\0')
			{
				p--;
				break;
			}
			p++;
		}
		p++;

		ipSymbol++;
	}
}
Example #11
0
void AnimatedObjModel::loadDataStructures(std::ifstream& _dataStream, const DataCounts& counts)
{
	std::vector<glm::vec3> tVertices;
	std::vector<glm::vec2> tTexCoords;
	std::vector<glm::vec3> tNormals;
	std::vector<FaceType> tFaces;

	char tInput1;
	
	int tVertexIndex = 0;
	int tTexcoordIndex = 0;
	int tNormalIndex = 0;
	int tFaceIndex = 0;
	int tBoneIndex = 0;

	mModel.resize(counts.faces * 3);

	//Initialize the four data structures.
	tVertices.resize(counts.positions);
	tTexCoords.resize(counts.texCoords);
	tNormals.resize(counts.normals);
	tFaces.resize(counts.faces);
	bones.resize(counts.bones);

	while(_dataStream)
	{
		_dataStream.get(tInput1);

		if (tInput1 == '#')
		{
#undef max
			_dataStream.ignore(std::numeric_limits<int>::max(), '\n');
			continue;
		}

		if(tInput1 == 'v')
		{
			_dataStream.get(tInput1);

			//Read in the vertices.
			if(tInput1 == ' ') 
			{ 
				_dataStream >> tVertices[tVertexIndex].x;
				_dataStream >> tVertices[tVertexIndex].y;
				_dataStream >> tVertices[tVertexIndex].z;
				tVertexIndex++; 
			}

			//Read in the texture uv coordinates.
			if(tInput1 == 't') 
			{ 
				_dataStream >> tTexCoords[tTexcoordIndex].x;
				_dataStream >> tTexCoords[tTexcoordIndex].y;
				tTexcoordIndex++; 
			}
//the case if encounter a angle bracket "["
void MDparser::angleBracket(std::string& tobeStored, bool& readyToStore, std::ifstream& myinput, myset<std::string>& allWords, myset<std::string>& allLinks){
	string buffer("");

    char letter=(char)myinput.get();
    while(letter!=']'&& !myinput.fail()){
      buffer=buffer+letter;
      letter=(char)myinput.get();
   }
   buffer+="]";
   //parsing,change bool varibale to false
   for (int i=0;i<(int)buffer.size();i++){
   		letter=buffer[i];
   		if(isLetter(letter)){
   			readyToStore=true;
   			tobeStored+=letter;
   		}
   		else if(!isLetter(letter)&&readyToStore){
   			allWords.insert(tobeStored);
   			tobeStored="";
   			readyToStore=false;
   		}
   		else if(!isLetter(letter)&&!readyToStore){
   			//donothing
   		}
   }

   if(!myinput.fail()){
   	   letter=(char)myinput.get(); //get the next letter after']'
		if(letter=='('){
			buffer="";
			letter=(char)myinput.get();
			while(letter!=')'){
				buffer+=letter;
				letter=(char)myinput.get();
			}
			ifstream my_input(buffer.c_str());
			if(!my_input.fail()){
				allLinks.insert(buffer);				
			}
			my_input.close();
			buffer="";
			readyToStore=false;
		}
		else{
			if(isLetter(letter)){
				readyToStore=true;
				tobeStored+=letter;
			}
			else{
				readyToStore=false;
			}
		}
   }
}
Example #13
0
bool TUtilities::CheckAndCompareFileString(std::ifstream &InFile, AnsiString InString)
//Reads the next item and checks it as a string value up to either the '\0' delimiter
//if there is one, in which case the '\0' is extracted but nothing more, or up to the next '\n',
//in which case the '\n' is extracted.  There may or may not be a '\n' at the start, and if there
//is it is ignored (only one is ignored, a second one is treated as a delimiter).
//The item is then compared with InString and fails if different.
{
char TempChar;
char *Buffer = new char[10000];
int Count = 0;
InFile.get(TempChar);//may or may not be '\n'
if(InFile.fail())
    {
    delete Buffer;
    return false;
    }
if(TempChar == '\n')
    {
    InFile.get(TempChar);//get the next one if first was '\n'
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
while((TempChar != '\0') && (TempChar != '\n'))
    {
    if((TempChar < 32) && (TempChar >= 0))
        {
        delete Buffer;
        return false;
        }
    Buffer[Count] = TempChar;
    Count++;
    InFile.get(TempChar);
    if(InFile.fail())
        {
        delete Buffer;
        return false;
        }
    }
Buffer[Count] = '\0';
Count++;
Buffer[Count] = '\n';
Count++;
if(AnsiString(Buffer) != InString)
    {
    delete Buffer;
    return false;
    }
delete Buffer;
return true;
}
Example #14
0
//---------------------------------------------------------------------------
AnsiString TUtilities::LoadFileString(std::ifstream &InFile)
{//see SaveFileString for use of the '\0' & '\n' characters
char TempChar;
AnsiString TempString = "";
InFile.get(TempChar); //get rid of the previous 'n' character, if not '\n' then use as part of string
if(TempChar == '\n') InFile.get(TempChar);
while(TempChar != '\0')//'\0' is the string delimiter
    {
    TempString = TempString + TempChar;
    InFile.get(TempChar);
    }
return TempString;
}
/*
----------------------------------setSearchData------------------------------
setSearchData - Sets information about an item, from a file formatted
                specifically containing action information.  This does
                not provide full details for a complete YouthBook.  It
                only allows for an item to be created with specific search
                criteria.

PreConditions: A validly formatted input file
PostConditions: Book information is updated from the file.
*/
bool YouthBook::setSearchData(std::ifstream& infile) {
    std::string inputAuthor, inputTitle;

    infile.get();
    getline(infile, inputTitle, FIELD_SEPARATOR);
    infile.get();
    getline(infile, inputAuthor, FIELD_SEPARATOR);
    setAuthor(inputAuthor);
    setName(inputTitle);

    //getline(infile, inputTitle);
    return true;
}
void MD5Model::skipComments(std::ifstream &fin) {
	char c;
	fin.get(c);

	if (c != '/')
		throw Exception("MD5Model::skipComments(): invalid comment, expected //");

	while (!fin.eof() && c != '\n')
		fin.get(c);

	// put back last character read
	fin.putback(c);
}
Example #17
0
Telnum Telnum::read_from(std::ifstream& source){
    Telnum result;
    result.telnr = read_string(source);
    result.fname = read_string(source);
    result.lname = read_string(source);
    result.street = read_string(source);
    source >> result.hnr;
    source.get(); //0-Trennbyte
    source >> result.pc;
    source.get(); //0-Trennbyte
    result.location = read_string(source);
    return result;
}
Example #18
0
int readInt(std::ifstream & fstr) {
	int result = 0;
	unsigned char ic = 0;

	ic = fstr.get();
	result = ic;
	ic = fstr.get();
	result |= ((unsigned int) ic << 8);
	ic = fstr.get();
	result |= ((unsigned int) ic << 16);
	ic = fstr.get();
	result |= ((unsigned int) ic << 24);
	return result;
}
Example #19
0
/**
 *
 *	Determines what are the dimensions of a labyrinth stored in a file.
 *
 *	\param [in] InputFile
 *		The file to read data from
 *
 *	\param [out] RowsCount
 *		A variable which will receive the numbe of rows in the labyrinth.
 *		The variable will be altered only if the file contains valid data.
 *
 *	\param [out] ColsCount
 *		A variable which will receive the numbe of columns in the labyrinth.
 *		The variable will be altered only if the file contains valid data.
 *
 *	\return
 *		true if the file contains valid data and the dimensions were written
 *		to RowsCount and ColsCount. Otherwise the function returns false.
 *
 */
bool Board::GetBoardDimensionsFromFile(std::ifstream & InputFile, int& RowsCount, int& ColsCount)
{
	InputFile.clear();
	InputFile.seekg(0, std::ios::beg);

	int rows = 0; // Number of rows in the board
	int cols = 0; // Number of columns in the board

	char c = 0;
	int counter = 0;
		
	// Find the number of columns in the board
	while (InputFile.get(c) && c != '\n')
		cols++;


	// Find the number of rows in the board and also
	// verify that all rows have the same number of columns
	if (cols > 0)
	{
		rows++; // at leas one row was read from the file

		while (InputFile.get(c))
		{
			if (c == '\n')
			{
				// the number of columns on each line must be the same
				if (cols != counter)
					return false;

				rows++;
				counter = 0;
			}
			else
			{
				counter++;
			}
		}

		// The last row of the labyrinth may or may not be followed by a blank line
		// Thus if we just count the number of new lines, we may count one row less
		if (c != '\n')
			rows++;
	}

	RowsCount = rows;
	ColsCount = cols;

	return true;
}
Example #20
0
// loading strings
static void LoadString ( std::ifstream &s, std::string &val)
{
  uint32 size;
  int8 tmp;

  s >> size;
  tmp = (uint8) s.get();  // skip space

  for( uint32 i=0; i<size; i++)
  {
    tmp = (uint8) s.get();
    val.append( (const char *) &tmp, 1);
  }
}
Example #21
0
/**
* @brief gets the land data from the land record
*/
Land readLandData(std::ifstream& ifs, long rend){
	Land l;

	long subRecSize;
	int count = 0;
	while ( ifs.tellg() < rend ){
		char dataType[5];
		ifs.read(dataType, 4);
		dataType[4] = '\0';
		//cell data

		ifs.read ((char *)&subRecSize, sizeof(long));
		long subRecEnd = subRecSize + ifs.tellg();

		if ( strcmp(dataType, "VNML") == 0 ){
			for ( int x = 0; x < 65; x++ ){
				for ( int y = 0; y < 65; y++){
					ifs.read((char*)&l.normals[x][y], sizeof(Normal));
				}
			}
		}

		 if ( strcmp(dataType, "VHGT") == 0){

			float offset;
			ifs.read ((char *)&offset, sizeof(float));

			for(int y = 0; y < 65; y++) {
				char x;
				ifs.get(x);	
				offset += x;
				l.land[0][y] = offset;

				float pos = offset;

				for(int x = 1; x< 65; x++) {

					char c;
					int tmp = 0;
					ifs.get(c);						
					pos += c;

					l.land[x][y] = pos;
				}
			}
		 }
		 ifs.seekg(subRecEnd);
	}
	return l;
}
Example #22
0
    void read_poly () {
        int number;
        is >> number;

        // poly number is terminated by colon
        is >> std::ws;
        int colon;
        if ((colon = is.get ()) != ':')
            format_error ("PolyFileReader::read_poly: expected colon, got %c", colon);

        // first two vertices
        int initial_vertex;
        is >> initial_vertex;
        // translate POLY vertices into Boundary vertices
        initial_vertex = lookup_vertex (initial_vertex);
        int prev_vertex;
        is >> prev_vertex >> std::ws;
        prev_vertex = lookup_vertex (prev_vertex);

        int initial_edge = b->insert_edge (Boundary::INVALID_EDGE,
                                    initial_vertex, prev_vertex,
                                    Boundary::INVALID_EDGE);

        int prev_edge = initial_edge;
        while (is_digit (is.peek ())) {
            int vertex;
            is >> vertex >> std::ws;
            // translate POLY vertices into Boundary vertices
            vertex = lookup_vertex (vertex);

            int edge = b->insert_edge (prev_edge, prev_vertex,
                                       vertex, Boundary::INVALID_EDGE);
            prev_vertex = vertex;
            prev_edge = edge;
        }

        is >> std::ws;
        int closed_indic = is.peek ();
        if (closed_indic == '<') {
            // extract '<' character
            is.get ();
            // close contour
            b->insert_edge (prev_edge, prev_vertex, initial_vertex, initial_edge);
        } else {
            std::cerr << "WARNING: non-closed contour " << number << ". this is probably not what you want.\n";
        }

        ignore_rest_of_line ();
    }
Example #23
0
void MovingMeshFB::readDummy(std::ifstream& is)
{
  char c;
  for (is.get(c);true;is.get(c)) {
    if (c == '#') {
      while (true) {
	is.get(c);
	if (c == '#') break;
      }
    }
    else if (('0' <= c && c <= '9')||(c == '.')||(c =='-'))
      break;
  }
  is.putback(c);		
}
Example #24
0
Expression::Expression(std::ifstream &in)
{
    in.get(); 
    in >> operation;

    while (isspace(operation))
        in >> operation;
    if (isInvalidOperation(operation))
        throw invalidOperation();

    left = getNode(in);
    right = getNode(in);

    in.get();
}
Example #25
0
uint32_t read_next_number( std::ifstream & is ) {
    uint32_t value = 0;
    
    // Skip whitespace
    char c;
    while( ( is.get(c) ) && (c == ' ' || c == '\t' || c=='\n' || c == '\r' ) );
    while( c >= '0' && c <= '9' ) {
        value *= 10;
        value += ( c - '0' );
        is.get(c);
    }
    is.putback(c);
    
    return value;
}
size_t findInStream(std::ifstream &stream, const std::string &sig)
{
    const size_t start = stream.tellg();

    while(!stream.eof())
    {
        auto it = sig.begin();
        for( size_t s=0 ; it != sig.end() ; it++, s++ )
        {
            char c = stream.get();

            if( sig[s] != c )
                break;
        }

        if( it == sig.end() )
            break;
    }

    size_t pos;

    if(stream.eof())
        pos = std::string::npos;
    else
        pos = stream.tellg();

    stream.seekg(start);

    return pos;
}
Example #27
0
void PpmConsumeWhitespaceAndComments(std::ifstream& bFile)
{
    // TODO: Make a little more general / more efficient
    while( bFile.peek() == ' ' )  bFile.get();
    while( bFile.peek() == '\n' ) bFile.get();
    while( bFile.peek() == '#' )  bFile.ignore(4096, '\n');
}
Example #28
0
int Cliente::transmitirArchivo(std::ifstream& archivo){
      uint32_t  tamanio_recv;
      char *mensaje_recibido, c;
      std::string mensaje_envio;
      int error=1;

      if (this->conectar()==0){
          /* Recibir bienvenida */
          if (this->recibir(&mensaje_recibido,tamanio_recv)==0){
            std::cout << "[SERVIDOR] ";
            Protocolo::imprimirMsg(mensaje_recibido,tamanio_recv);
            delete[] mensaje_recibido;
            /* Enviar mensaje */
            std::cout << "[CLIENTE] Enviando datos..." << std::endl;
            while (!archivo.eof() && archivo.get(c))
                 mensaje_envio.push_back(c);

            if (this->enviar(mensaje_envio.c_str(),mensaje_envio.length())==0){
                  /* Recibir mensaje de recepcion del servidor */
                  if (this->recibir(&mensaje_recibido,tamanio_recv)==0){
                    if (protocolo.validarMensajeRecepcion(mensaje_recibido, \
                        tamanio_recv, (uint32_t)mensaje_envio.length())==0){
                       std::cout << "[SERVIDOR] ";
                       Protocolo::imprimirMsg(mensaje_recibido,tamanio_recv);
                       error=0;
                    }
                  delete[] mensaje_recibido;
                  }
            }
          }
          this->desconectar();
      }
return error;
}
Example #29
0
void Hoffman::archiving(std::ifstream &f,std::ofstream &g,std::map<char,int> &counting)
{
	int sz = counting.size();
	g.write(reinterpret_cast<char *>(&sz), sizeof(sz));
	for (std::map<char, int>::iterator i = counting.begin(); i != counting.end(); ++i)
	{
		char fr = i->first;
		int sc = i->second;
		g.write(reinterpret_cast<char *>(&fr), sizeof(char));
		g.write(reinterpret_cast<char *>(&sc), sizeof(int));
	}
	while((c1=f.get()) != EOF)//считали из файла букву,чтобы входили и пробелы
	{
		std::vector<bool>x=catalogue[c1];//использу¤ ключ мы выводим код
		for(int n=0;n<x.size();n++)
		{
			if(DEBUG) std::cout <<x[n];//выведем на экран
			///////выведем в файл///////
			buf=buf | x[n]<<(7-count);//изначально buf 00000000
			count++;
			if(count==8){count=0;g.put(buf);buf=0;}
		}
		std::cout<<" ";
	}
	if( count > 0) g.put(buf);
	std::cout<<std::endl;
}
// Retrieves the data size of the next block
Uint32 CSaveGameController::getDataSize(std::ifstream &StateFile) {
    Uint32 size=0;
    for(Uint32 i=0 ; i<sizeof(Uint32) ; i++) {
        size += StateFile.get() << (i*8);
    }
    return size;
}