Example #1
0
  inline void FileParse::getHead(std::ifstream& fin) {
    if (fin.eof()) return;
    // Create a new head node
    HeadNode *node = new HeadNode;

    // Look for the heading. Ends with ":", or "{". If "{" is encountered, body = true.
    bool body = false;
    getHeading(fin, node->heading, body);

    // Message
    message += (tabs() + "Level " + toStr(level) + ": Heading: [" + node->heading + "]\n");

    // Set node as the current head
    node->parent = currentHead;
    currentHead = node;

    // Look for parameters
    bool newLine = passSpaces(fin);
    
    // Get the parameters - adds them to the current head node
    if (!fin.eof() && !newLine && !body)
      body = getParameters(fin);

    ++level;
    if (body && !fin.eof()) getBody(fin);
    --level;

    // Add this node to the parent node
    node->parent->subHeads.push_back(node);

    // Return to parent node
    currentHead = node->parent;
  }
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 #3
0
InputData::InputData(std::ifstream& input) {
    std::string label;
    input >> label >> name_;
//  std::cout << label << name_ << "\n";
    input >> label >> nirreps_;
//  std::cout << label << " " << nirreps_ << "\n";
    input >> label >> nmo_;
//  std::cout << label << " " << nmo_ << "\n";
    input >> label >> nocc_act_alpha_;
//  std::cout << label << " " << nocc_act_alpha_ << "\n";
    input >> label >> nocc_act_beta_;
//  std::cout << label << " " << nocc_act_beta_ << "\n";
    input >> label >> nvir_act_alpha_;
//  std::cout << label << " " << nvir_act_alpha_ << "\n";
    input >> label >> nvir_act_beta_;
//  std::cout << label << " " << nvir_act_beta_ << "\n";
    input >> label;
//  std::cout << label << "\n";
    obs_mosym_alpha_.resize(nmo_, 0);
    for(obs_mosym::iterator it = obs_mosym_alpha_.begin(); it != obs_mosym_alpha_.end(); ++it) {
        input >> *it;
//    std::cout << *it << "\n";
    }
    input >> label;
//  std::cout << label << "\n";
    obs_mosym_beta_.resize(nmo_, 0);
    for(obs_mosym::iterator it = obs_mosym_beta_.begin(); it != obs_mosym_beta_.end(); ++it) {
        input >> *it;
//    std::cout << *it << "\n";
    }
    std::string line;
    std::getline(input, line);
    std::getline(input, line);
    do {
        line.clear();
        std::getline(input, line);
        if(line.size() == 0ul)
            break;
        std::istringstream iss(line);
        array2d::value_type data;
        iss >> data.first[0] >> data.first[1] >> data.second;
        f_.push_back(data);
//      std::cout << "(" << data.first[0] << ", " << data.first[1] << ") " << data.second << "\n";
    } while(! input.eof());
    do {
        line.clear();
        std::getline(input, line);
        if(line.size() == 0ul)
            break;
        std::istringstream iss(line);
        array4d::value_type data;

        // Note: Input data is in chemist notation order, but we want physicist notation.
        // So we swap index 1 and 2
        iss >> data.first[0] >> data.first[2] >> data.first[1] >> data.first[3] >> data.second;
        v_ab_.push_back(data);
//      std::cout << "(" << data.first[0] << ", " << data.first[1] << ", " << data.first[2]
//          << ", " << data.first[3] << ") " << data.second << "\n";
    } while(! input.eof());
}
Example #4
0
// Load next chromosome
ref_loc_t RefSeq::LoadNextSeq(std::ifstream &fin) {
    char c;
    char ch[1000];
    std::string s;
    fin>>c;
    if (fin.eof()) return 0;
    _length = 0;
    // get name
    fin>>_name;
    fin.getline(ch, 1000);
    // get seq
    while (!fin.eof()) {
        fin>>c;  
        if (fin.eof()) break;
        fin.unget();
        if (c == '>') break;
        fin>>s;
        if (_length + s.size() >= param.max_dbseq_size) {
            if (s.size() > param.append_dbseq_size) {
                param.max_dbseq_size += (s.size() + 10);
            } else { 
                param.max_dbseq_size += param.append_dbseq_size; 
            }
            _seq.resize(param.max_dbseq_size);
        }
        copy(s.begin(), s.end(), _seq.begin() + _length);
        _length += s.size();
    }
    return _length;
}
bool  MeshModel::loadOFF(std::ifstream& infile)
{
	std::string temp;
	infile >> temp;
	unsigned int numVertices,numFaces;
	infile >> numVertices >> numFaces >> temp;

	if (infile.eof())
		return false;

	vertices.resize(numVertices);
	double z;

	for (unsigned int i = 0; i < numVertices; i++) {
		if (infile.eof()) return false;
		infile >> vertices[i].x >> vertices[i].y >> z;
	}


	int three;
	faces->resize(numFaces);

	for (unsigned int i = 0; i < numFaces; i++) {
		if (infile.eof()) return false;
		infile >> three >> (*faces)[i][0] >> (*faces)[i][1] >> (*faces)[i][2];
	}

	identityTexCoords();
	return updateMeshInfo();
}
Example #6
0
void DTMImage::ReadTextImageData( std::ifstream & ifs )
{
  ifs.seekg(0,std::ios::beg);

  SkipUntilNum(ifs);
  int Dimensions[3];
  for ( int i = 0; i < 3; ++i ) ifs >> Dimensions[i];
  this->SetDimensions(Dimensions);
  SkipUntilNum(ifs);
  for ( int i = 0; i < 3; ++i ) ifs >> this->origin[i];
  SkipUntilNum(ifs);
  for ( int i = 0; i < 3; ++i ) ifs >> this->spacing[i];
  SkipUntilNum(ifs);
  for ( int i = 0; i < 3; ++i ) ifs >> this->indexIncrement[i];
  SkipUntilNum(ifs);
  ifs >> this->scalarType;
  // We are assuming that the scalar type is double.
  // When we template the class we will fix all these things.
  this->scalars->resize(this->dimensions[0]*this->dimensions[1]*this->dimensions[2]);
  this->scalars->clear();
  double tmp = 0;
  SkipUntilNum(ifs);
  while( !ifs.eof() )
    {
    ifs >> tmp >> std::skipws;
    if ( !ifs.eof() )
      this->scalars->push_back(tmp);
    }
  if ( this->scalars->size() != (std::size_t)this->pointProduct[2] )
    std::cerr << "The number of scalars read do not match the dimensions.";
}
binary_reader::market_message::market_message( std::ifstream& in )
{
	type_=0u;time_=0u;
	len_=0u;msg_=NULL;
	if(!in.read(reinterpret_cast<char *>(&type_), sizeof(type_))) {
		if (in.eof()) return;
		cerr<<"Input is incorrect type"<<endl;
		return;
	}
    if(!in.read(reinterpret_cast<char *>(&time_), sizeof(time_))) {
		if (in.eof()) return;
		cerr<<"Input is incorrect time"<<endl;
		return;
	}

    if(!in.read(reinterpret_cast<char *>(&len_), sizeof(len_))) {
		if (in.eof()) return;
		cerr<<"Input is incorrect len"<<endl;
		return;
	}
	msg_ = new char[len_+1];
	memset(msg_, 0, len_ +1);
	
	if(!in.read(msg_, len_)) {
		if (in.eof()) return;
		cerr<<"Input is incorrect msg"<<endl;
		return;
	}

}
Example #8
0
 virtual bool read(std::ifstream& in, int n, bool binary)
 {
     resize(n);
     if (binary)
     {
         in.read((char*)data, n * sizeof(T));
         if (in.eof() || in.bad())
         {
             resize(0);
             return false;
         }
     }
     else
     {
         int i = 0;
         std::string line;
         while(i < dataSize && !in.eof() && !in.bad())
         {
             std::getline(in, line);
             std::istringstream ln(line);
             while (i < n && ln >> data[i])
                 ++i;
         }
         if (i < n)
         {
             resize(0);
             return false;
         }
     }
     return true;
 }
Example #9
0
    void load_ref( std::ifstream &is ) {
        size_t num_ref;
        is >> num_ref;
        m_ref_pvecs.resize( num_ref );
        m_ref_aux.resize( num_ref );
        
        for( size_t i = 0; i < m_ref_pvecs.size(); ++i ) {
            size_t len;
            is >> len;
            while( isspace( is.get() ) && !is.eof() ) {}
            is.unget();
            
            if( is.eof() ) {
                throw std::runtime_error( "unexpected end of file" );
            }
            
            m_ref_pvecs[i].resize(len);
            is.read( (char*)&m_ref_pvecs[i][0], len * sizeof(int) );
            
            m_ref_aux[i].resize(len);
            is.read( (char*)&m_ref_aux[i][0], len * sizeof(unsigned int) );
            
//             std::cout << "ref: " << i << " " << m_ref_pvecs[i].size() << "\n";
        }
        
    }
  /**
   * Parse the stream for the characterization file information.
   *
   * @param file The stream to parse.
   * @param wksp The table workspace to fill in.
   */
  void PDLoadCharacterizations::readCharInfo(std::ifstream &file, ITableWorkspace_sptr &wksp)
  {
    // end early if already at the end of the file
    if (file.eof()) return;

    // parse the file
    for (std::string line = Strings::getLine(file); !file.eof(); line = Strings::getLine(file))
    {
      line = Strings::strip(line);

      // skip empty lines and "comments"
      if (line.empty()) continue;
      if (line.substr(0,1) == "#") continue;


      // parse the line
      std::vector<std::string> splitted;
      boost::split(splitted, line, boost::is_any_of("\t "), boost::token_compress_on);
      while (splitted.size() < 10)
        splitted.push_back(ZERO); // extra values default to zero

      // add the row
      API::TableRow row = wksp->appendRow();
      row << boost::lexical_cast<double>(splitted[0]);  // frequency
      row << boost::lexical_cast<double>(splitted[1]);  // wavelength
      row << boost::lexical_cast<int32_t>(splitted[2]); // bank
      row << boost::lexical_cast<int32_t>(splitted[3]); // vanadium
      row << boost::lexical_cast<int32_t>(splitted[4]); // container
      row << boost::lexical_cast<int32_t>(splitted[5]); // empty
      row << splitted[6];                               // d_min
      row << splitted[7];                               // d_max
      row << boost::lexical_cast<double>(splitted[8]);  // tof_min
      row << boost::lexical_cast<double>(splitted[9]);  // tof_max
    }
  }
Example #11
0
void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
{
  if(!in_stream.good())
    EXCEPTION(runtime_error,"ERROR: Input file not good.");

  std::string olds, news;
  
  while(true){
    in_stream >> olds >> news;
    /*
     * a "-1" followed by a number means the beginning of a dataset
     * stop combing at the end of the file
     */
    while( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() ){	  
      olds = news;
      in_stream >> news;
    }
    if(in_stream.eof())
      return;
    for (int i = 0; i < NBGROUP; i++) {
      if (news == _group_labels[i]) {
	ReadGroup(news, in_stream, theDataSet);
      }
    }
  }
}
int insert_signals( T&                  signal,   
                    char *              signal_name, 
                    char *              wu_name,
                    sqlint8_t           sah_result_id,
                    std::ifstream&      result_file, 
                    receiver_config&    receiver_cfg,   
                    int                 appid,
                    int                 max_signals_allowed,
                    list<long>&         qpixlist) {

    int signal_count=0, signal_inserted_count=0, retval=0, qpix;
    sqlint8_t signal_id=0;

    result_file.clear();
    result_file.seekg(0);
    while (!result_file.eof()) {
        result_file >> signal;
        if (!result_file.eof()) {
            signal_count++;
            if (max_signals_allowed == 0 || signal_count <= max_signals_allowed) {
                if (!(signal.rfi_found = check_values(signal, sah_result_id, wu_name))) {
                    // preprocess only if we have good values
                    retval = pre_process(signal, receiver_cfg);  
                    qpixlist.push_back(npix2qpix((long long)signal.q_pix));
                }
                signal.result_id = sah_result_id;
                if (appid == 2) signal.reserved = 1;        // temporary for enhanced rollout
                signal_id = signal.insert();
                if (signal_id) {
                    log_messages.printf(SCHED_MSG_LOG::MSG_DEBUG,
                        "[%s] Inserted %s %"INT8_FMT" for sah result %"INT8_FMT"\n",
                        wu_name, signal_name, INT8_PRINT_CAST(signal_id), INT8_PRINT_CAST(sah_result_id)
                    );
                    signal_inserted_count++;
                } else {
                    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
                                "[%s] Could not insert %s for sah result %"INT8_FMT". SQLCODE is %d. q_pix is %"INT8_FMT"  ra is %lf  decl is %lf .\n",
                                wu_name, signal_name, sah_result_id, sql_last_error_code(), signal.q_pix, signal.ra, signal.decl
                    );
#if 0
                    log_messages.printf(SCHED_MSG_LOG::MSG_CRITICAL,
                                "[%s] Could not insert %s for sah result %ld. SQLCODE is %d.  SQLMSG is %s  q_pix is %"INT8_FMT".\n",
                                wu_name, signal_name, sah_result_id, sql_last_error_code(), sql_error_message(), signal.q_pix
                    );
#endif
                    return -1;
                }  
            }   
        }   
    } 

    log_messages.printf(SCHED_MSG_LOG::MSG_NORMAL,
        "[%s] Inserted %d out of %d %s(s) for sah result %"INT8_FMT" \n",
        wu_name, signal_inserted_count, signal_count, signal_name, INT8_PRINT_CAST(sah_result_id)
    );

}
Example #13
0
bool ParseFoodItem(std::ifstream & infile, FoodItem & item)
{
	if (true == infile.eof())
	{
		return false;
	}

	const int MAX_TOKEN = 256;
	std::string line;
	std::string tokenBuf(MAX_TOKEN, '\0');

	const char * delim = ",\n";

	do
	{
		float calories = 0;

		// read line
		std::getline(infile, line);

		// grab first token
		char * token = nullptr;
		char * nextToken = nullptr;
		token = strtok_s(&line[0], delim, &nextToken);

		std::string tokenStr(token);
		//trim_str(tokenStr);
		String nameToken(ConvertStringToWString(token)); // read name, 1st token
		
		// next token plz
		token = strtok_s(nullptr, delim, &nextToken);

		if (token == nullptr)
		{
			return false;
		}

		// read calories, 2nd token
		calories = (float)atof(token);
		if (calories <= 0)
		{
			return false;
		}

		// read description
		std::string desc;
		std::getline(infile, desc);
		String measurements(ConvertStringToWString(desc));

		item = FoodItem(nameToken, measurements, calories);
		return true;
	} 
	while (false == infile.eof());
	
	return false;
}
Example #14
0
  void ReadScalars(std::ifstream &ifs, size_t pos, std::vector<T> &Scalars)
{
  ifs.seekg(pos,std::ios::beg);
  Scalars.clear();
  while( !ifs.eof() )
    {
    T tmp;
    ifs.read(reinterpret_cast<char *>(&tmp), sizeof(T));
    if ( !ifs.eof() )
      Scalars.push_back(tmp);
    }
}
Example #15
0
// Read the data
//-------------------------------------------------------------------------------------------------
bool PPM::readData(std::ifstream &inFile)
{
	// Read data into r, g and b vectors
	// Note: if << is used data that looks like a white space will be skipped
	char c;
	int length = m_width * m_height;
	for(int i = 0; i < length; ++i)
	{
		// Red
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pR)[i] = (unsigned char)c;

		// Green
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pG)[i] = (unsigned char)c;

		// Blue
		inFile.read(&c, 1); // read a byte
		// Check for eof
		if(inFile.eof())
		{
			std::cerr << "Error in readData: unexpected end of file" << std::endl;
			return false;
		}
		// Set value
		(*m_pB)[i] = (unsigned char)c;
	}

	// Check the data is valid
	if(!checkData())
	{
		std::cerr << "Error in readData: invalid data" << std::cout;
		return false;
	}

	return true;
}
Example #16
0
bool PeekString(std::ifstream & infile, const char * delim, std::string & outStr)
{
	if (true == infile.eof())
	{
		return false;
	}

	std::string line;
	std::streampos pos = infile.tellg();
	std::getline(infile, line);

	char * token = nullptr;
	char * nextToken = nullptr;
	token = strtok_s(&line[0], delim, &nextToken);

	if (token == nullptr)
	{
		return false;
	}

	outStr = std::string(token);

	infile.seekg(pos);

	return true;
}
bool  MeshModel::loadOBJ(std::ifstream& infile)
{
	double x,y,z;
	bool hasUV = false;
	std::string a,b,c;

	while (!infile.eof())
	{
		// get line
		std::string curLine;
		std::getline(infile, curLine);

		// read type of the line
		std::istringstream issLine(curLine);
		std::string linetype;
		issLine >> linetype;

		if (linetype == "v")
		{
			issLine >> x >> y >> z;
			Point2 p(x,y);
			vertices.push_back(p);
			continue;
		}
		if (linetype == "vt")
		{
			hasUV = true;
			issLine >> x >> y;
			Point2 p(x,y);
			texCoords->push_back(p);
			continue;
		}
Example #18
0
static int getNextLine(void)
{
	int i;
	char *p;
  
	nBuffer = 0;
	nTokenStart = -1;
	nTokenNextStart = 0;
	eof = false;

	std::getline(inputFile, buffer);
	if (inputFile.eof())
	{
		eof = true;
		return 1;
	}
	if (inputFile.fail())
	{
		return -1;
	}

	buffer += "\n";
	std::replace(buffer.begin(), buffer.end(), '\t', ' ');

	fileLineMap[currentFileName].push_back(buffer);
	nRow += 1;
	lBuffer = buffer.length();

	return 0;
}
Example #19
0
bool CheatFileParser::Parse() {
	for (line_ = 1; file_ && !file_.eof(); ++line_) {
		std::string line;
		getline(file_, line, '\n');
		line = TrimString(line);

		// Minimum length is set to 5 just to match GetCodesList() function
		// which discards anything shorter when called anyway.
		// It's decided from shortest possible _ lines name of the game "_G N+"
		// and a minimum of 1 displayable character in cheat name string "_C0 1"
		// which both equal to 5 characters.
		if (line.length() >= 5 && line[0] == '_') {
			ParseLine(line);
		} else if (line.length() >= 2 && line[0] == '/' && line[1] == '/') {
			// Comment, ignore.
		} else if (line.length() >= 1 && line[0] == '#') {
			// Comment, ignore.
		} else if (line.length() > 0) {
			errors_.push_back(StringFromFormat("Unrecognized content on line %d: expecting _", line_));
		}
	}

	Flush();

	return errors_.empty();
}
Example #20
0
void ReadWorldTagData( std::ifstream &inStream, UString &tag, UString &data )
{
	char temp[4096];
	tag = "o---o";
	data = "o---o";
	while( !inStream.eof() && !inStream.fail() )
	{
		inStream.getline( temp, 4096 );
		UString sLine( temp );
		sLine = sLine.removeComment().stripWhiteSpace();
		if( !sLine.empty() )
		{
			if( sLine != "o---o" )
			{
				if( sLine.sectionCount( "=" ) == 1 )
				{
					tag		= sLine.section( "=", 0, 0 ).stripWhiteSpace();
					data	= sLine.section( "=", 1 ).stripWhiteSpace();
					break;
				}
			}
			else
				break;
		}
	}
}
Example #21
0
void CopyData ( std::ifstream &fin, std::ofstream &fout ) {
    char line[704];
    while (!fin.eof()) {
        fin.read(line, 704);
        fout.write(line, fin.gcount());
    }
}
Example #22
0
std::string hash_file(HashFunc * hf, std::ifstream& file, std::streampos start)
{
	size_t bs = 16384;
	char * b = new char [bs];
	file.seekg (start, std::ios::beg);
	while (file)
	{
		file.read (b, bs);
		if (file)
		{
			hf->process_bytes(b, bs);
		}
		else if (file.eof())
		{
			// file.gcount() returns an std::streamsize, which is the signed counterpart of std::size_t
			// it only returns a negative value in the constructors of std::strstreambuf, so we can
			// safely cast to size_t (taken from http://en.cppreference.com/w/cpp/io/streamsize)
			hf->process_bytes(b, (size_t)file.gcount());
		}
		else
		{
			hf->reset();
		}
	}
	delete[] b;
	return hf->str();
}
Example #23
0
/** parses the node list */ 
void ReaderTSP::getNodesFromFile(
   std::ifstream&     filedata,           /**< filestream containing the data to extract */
   double*            x_coords,           /**< double array to be filled with the x-coordinates of the nodes */
   double*            y_coords,           /**< same for y-coordinates */
   GRAPH*             graph               /**< the graph which is to be generated by the nodes */
   )
{
   int i = 0;
   int nodenumber;
   GRAPHNODE* node = &(graph->nodes[0]);

   // extract every node out of the filestream
   while ( i < graph->nnodes && !filedata.eof() )
   {
      filedata >> nodenumber >> x_coords[i] >> y_coords[i];

      // assign everything 
      node->id = i;
      if( nodenumber-1 != i)
         cout<<"warning: nodenumber <" <<nodenumber<<"> does not match its index in node list <"<<i+1
             <<">. Node will get number "<<i+1<<" when naming variables and constraints!"<<endl;
      node->x = x_coords[i];
      node->y = y_coords[i];
      node->first_edge = NULL; 
      node++; 
      i++;
   }
   assert( i == graph->nnodes );
} /*lint !e1762*/
Example #24
0
std::string hash_block(HashFunc * hf, std::ifstream& file, unsigned int bs, void (*mod)(char*, unsigned int))
{
	char * b = new char [bs];
	file.seekg (0, std::ios::beg);
	while (file)
	{
		file.read (b, bs);
		if (file)
		{
			if (mod)
			{
				mod(b, bs);
			}
			hf->process_bytes(b, bs);
		}
		else if (file.eof())
		{
			break;
		}
		else
		{
			hf->reset();
		}
	}
	delete[] b;
	return hf->str();
}
void MD5Model::readElements(std::ifstream &fin) {
	while (!fin.eof()) {
		std::string str;
		TOKEN tok = getNextToken(fin, &str);

		// token is TOKEN_INVALID when end of file is reached
		if (TOKEN_INVALID == tok)
			break;

		if (str == "commandline")
			readCommandLineEl(fin);
		else if (str == "numJoints")
			readNumJointsEl(fin);
		else if (str == "numMeshes")
			readNumMeshesEl(fin);
		else if (str == "joints")
			readJointsEl(fin);
		else if (str == "mesh")
			readMeshEl(fin);
		else {
			// invalid element
			throw Exception(std::string("MD5Model::readElements(): unknown element type '") + str + "'");
		}
	} // while ( not EOF )
}
Example #26
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 #27
0
char* solveMoreOfTheProblem() {
    try {
        if (! inFile.eof()) {
            string t = getaline(inFile);
            if (t.size() == 0) {
                inFile.clear();
                inFile.close();
                return error[4];
            } else {
                sprintf(lzbfr, "%s", t.c_str());
            }
            return lzbfr;
        } else {
            inFile.clear();
            inFile.close();
            return error[4];
        }
    } catch (string message) {
        inFile.clear();
        inFile.close();
        throw message;
    } catch (...) {
        inFile.clear();
        inFile.close();
        throw string("More went bad!!");
    }
    return error[3];
}
Example #28
0
// Skip a string s in the stream strm.
//  * Check that the string matches;
//  * Completely ignore whitespace;
//  * ? is a wildcard.
bool skipstring(std::ifstream& strm, const std::string& s)
{
    char c;
    std::string s2(s);

    // Remove whitespace from s
    s2.erase(std::remove(s2.begin(),s2.end(),' '),s2.end());

    // Now skip the string, ignoring whitespace characters
    for (unsigned int i = 0; i < s2.length(); ++i)
    {
        // Read in, do not count whitespace
        do
        {
            strm >> c;
            if (strm.eof()) return false;
            if (c != ' ' && c != s2[i] && s2[i] != '?')
            {
#if 0
                std::cerr << "Can't skip: string " << s;
                std::cerr << " doesn't match.\n";
#endif
                return false;
            }
        }
        while (c == ' ');
    }

    return true;
}
Example #29
0
void STLFile::read_ascii( std::ifstream &ifstr )
{
    // Read first line (header)
    std::string header;
    std::getline( ifstr, header );

    // Read line-by-line
    int linec = 0;
    while( !ifstr.eof() ) {
        
        std::string str;
        std::getline( ifstr, str );
	const char *buf = str.c_str();
        linec++;

	// Skip whitespace
	while( isspace( *buf ) )
	    buf++;

	if( ciscomp( buf, "endsolid", 8 ) )
	    break;

	_tri.push_back( Triangle( ifstr, buf, _filename, linec ) );
    }
}
Example #30
0
bool LccrFeaturizer::ReadOneSentence(std::ifstream &src,
                                     std::vector<std::string> &sentence) {
  if (!src.good()) {
    LOG(INFO) << "stream in bad state";
    return false;
  }

  sentence.clear();
  std::string line;

  std::getline(src, line);
  boost::algorithm::trim(line);
  while (src.good() && (line.size() < 1)) {
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  if ((!src.good()) && (!src.eof())) {
    LOG(FATAL) << "error when read files";
    return false;
  }

  while (src.good() && line.size() > 0) {
    sentence.push_back(line);
    std::getline(src, line);
    boost::algorithm::trim(line);
  }

  return true;
}