Exemplo n.º 1
0
void FileLoader::readFace(std::istream& is, Mesh& object)
{
    GLuint in;

    while(is.good())
    {
        // read index of geometry vertex
        while(is >> in) object.v_f.push_back(in-1);
        if(is.fail())
        {
            is.clear();
            char sign;
            is >> sign;
            if(sign == '/')
            {
                // read index of texture vertex
                if(is >> in) object.vt_f.push_back(in-1);
                if(is.fail())
                {
                    is.clear();
                    char sign;
                    is >> sign;
                    if(sign == '/')
                    {
                        // read index of normal vertex
                        if(is >> in) object.vn_f.push_back(in-1);
                    }
                }
            }
        }
Exemplo n.º 2
0
std::string ReadValueStr(std::string prompt /*= std::string()*/, std::istream& in /*= std::cin*/, std::ostream* out /*= &std::cout*/)
{
    if (out)
        (*out) << prompt;

    std::string input;
    bool success = false;

    while (!success)
    {
        std::getline(in, input);

        if (in.fail())
        {
            if (in.eof())
            {
                in.clear();
                throw EOFCharacterValue();
            }
            else
            {
                in.clear();
                if (out)
                    (*out) << "Invalid value. Please try again." << std::endl;
                else
                    throw InvalidValue("ReadValue: Invalid value found with no out stream.");
                continue;
            }
        }
        success = true;
    }

    return input;
}
Exemplo n.º 3
0
	int Cluster::numLines(std::istream & in)
		{
	
	 		//save position of file pointer  
			int pos = in.tellg();
	
	 		// account for possible eof bit 
	 		in.clear();
	
	 		// move file pointer to beginning of file 
	 		in.seekg(0);
	
	 		std::string aString;			//holds unused information 
	 		int lines = 0;					//counts lines 
	
	 		while (getline(in, aString))
	 			lines++;
	
			// clear eof bit 
			in.clear();
		
			// recover previous position in file 
			in.seekg(pos);
	
			return lines;
	}
Exemplo n.º 4
0
// public function: documentation in corresponding .h file
readEleFile::readEleFile(std::istream &input) {
	// read number of elements
	int numElements = -1;
	input >> numElements;

	// guard: check for invalid input
	if (!input.good() || numElements < 0) {
		throw readEleNumberOfElementsIncorrectException();
	}

	// drop 2 integer values
	int drop;
	input >> drop >> drop;

	// initialize duplicate-check-array
	bool *defined = new bool[numElements];
	for (int i = 0; i < numElements; i++) {
		defined[i] = false;
	}

	// create array and fill it
	m_elements = new tetrahedron[numElements];
	for (int i = 0; i < numElements; i++) {
		// read index
		int index;
		input >> index;
		// guard: check for invalid index
		if (!input.good() || index < 1 || index > numElements) {
			input.clear(); // repair stream so that it can tell us its position
			throw readEleElementIndexIncorrectException(input.tellg(), numElements);
		}

		// guard: check, if element already defined
		if (defined[index - 1]) {
			throw readEleElementAlreadyDefinedException(input.tellg(), index);
		}

		// read tetrahedron
		input >> m_elements[index - 1];
		defined[index - 1] = true;
		// guard: check for invalid points
		if (!input.good() || m_elements[index - 1].m_cornerA < 1 || m_elements[index - 1].m_cornerB < 1
			|| m_elements[index - 1].m_cornerC < 1 || m_elements[index - 1].m_cornerD < 1) {
			input.clear(); // repair stream so that it can tell us its position
			throw readElePointIndicesIncorrectException(input.tellg(), index);
		}

		// adapt indices (with tetgen they start at 1)
		m_elements[index - 1].m_cornerA--;
		m_elements[index - 1].m_cornerB--;
		m_elements[index - 1].m_cornerC--;
		m_elements[index - 1].m_cornerD--;
	}

	m_elementsReader = new staticArrayReader<tetrahedron>(m_elements, numElements);

	delete[] defined;
}
Exemplo n.º 5
0
 static uint64_t readBlocks(std::istream & in, uint64_t const indexpos)
 {
     in.clear();
     in.seekg(indexpos,std::ios::cur);
     uint64_t blocks;
     libmaus::serialize::Serialize<uint64_t>::deserialize(in,&blocks);
     in.clear();
     in.seekg(-static_cast<int64_t>(sizeof(uint64_t)),std::ios::cur);
     in.seekg(-static_cast<int64_t>(indexpos),std::ios::cur);
     return blocks;
 }
Exemplo n.º 6
0
void Polynomial<T>::input(std::istream &in)
{
	T coef;
	int data;
	in.clear();
	in>>coef>>data;
	while(in.good())
	{
		operator+=(Polynomial(coef,data));
		in>>coef>>data;
	}
	in.clear();
	in.get();
}
Exemplo n.º 7
0
int
GA3DBinaryStringGenome::read(std::istream & is)
{
  static char c;
  unsigned int i=0, j=0, k=0;
  do{
    is >> c;
    if(isdigit(c)){
      gene(i++, j, k, ((c == '0') ? 0 : 1));
      if(i >= nx){
	i=0;
	j++;
      }
      if(j >= ny){
	j=0;
	k++;
      }
    }
  } while(!is.fail() && !is.eof() && k < nz);

  _evaluated = gaFalse;

  if(is.eof() && 
     ((k < nz) ||		// didn't get some lines
      (j < ny && j != 0) ||	// didn't get some lines
      (i < nx && i != 0))){	// didn't get some lines
    GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
    is.clear(std::ios::badbit | is.rdstate());
    return 1;
  }

  return 0;
}
Exemplo n.º 8
0
void reader_utility::ignoreCommentLines(std::istream& stream, const std::string& lineHead)
{
    if (stream.fail() || stream.eof()) return;

    std::istream::pos_type pos = stream.tellg();

    std::string peekStr;
    while (stream >> peekStr) {
        int strSize = lineHead.size();
        bool commentFound = (static_cast<int>(peekStr.size()) >= strSize &&
                             peekStr.substr(0, strSize) == lineHead);
        if (commentFound) {
            ignoreLine(stream);
            pos = stream.tellg();
        }
        else {
            stream.seekg(pos, std::ios_base::beg);
            return;
        }
    }

    if (stream.eof()) {
        stream.clear();
        stream.seekg(pos, std::ios_base::beg);
    }
}
Exemplo n.º 9
0
void SymbolTable::Read(std::istream& i, bool quiet)
{
    // get entries from stream
    // assume POSIX nm format: <sym> <type> <addr> <size(opt)>

    size_t nread = 0;
    while (!i.eof()) 
    {
        MemAddr addr;
        size_t sz;
        string sym, ty;
        i.clear();
        i >> sym >> ty >> hex >> addr;
        if (!i.good()) break;
        i >> sz;
        if (!i.good()) sz = 0;

        m_entries.push_back(make_pair(addr, make_pair(sz, sym)));
        ++nread;
    }

    if (!quiet)
    {
        if (!nread)
            cerr << "Warning: symbol table is empty (no symbols read)." << endl;
        else
            clog << "Symbol table: " << dec << nread << " symbols loaded." << endl;
    }

    sort(m_entries.begin(), m_entries.end());
    m_cache.clear();
}
Exemplo n.º 10
0
 void seek(size_t pos)
 {
   inf->clear();
   inf->seekg(pos);
   if(inf->fail())
     fail("seek error");
 }
Exemplo n.º 11
0
			static uint64_t getSparseCount(std::istream & CIS)
			{
				CIS.clear();
				CIS.seekg(0,std::ios::end);
				uint64_t const n = CIS.tellg() / (2*sizeof(uint64_t));
				return n;
			}
Exemplo n.º 12
0
std::string huffmanEncode(std::istream &inFile, std::map<char, long long> &char_freq, int *validBitsLastByte) {
	char value;
	int buffCnt;
	stringstream ssFileEncoded;
	vector<char> codeVector;
	MyIOBitStream bitStream;

	inFile.clear(); inFile.seekg(0, inFile.beg);
	(*validBitsLastByte) = 8; 			// default : last byte has 8 bits
	buffCnt = 0;
	while (inFile.get(value)) {
		codeVector = char_codeVector[value];
		// for each bit of the code
		for (int i = 0; i < codeVector.size(); i++) {
			if (codeVector[i] & 1) {
				bitStream.appendBit(true);
			}
			else {
				bitStream.appendBit(false);
			}
			buffCnt++;
			if (buffCnt == SIZEBUFFER) { // Record the buffer into the output file
				ssFileEncoded << bitStream.getString();
				buffCnt = 0;
			}
		}
	}
	if (buffCnt > 0) {
		(*validBitsLastByte) = bitStream.getBitsWriteCounter() ? : 8;
		ssFileEncoded << bitStream.getString();
	}
Exemplo n.º 13
0
 void cparse(ConfigurationHolder & configuration_holder, std::istream & ifs) {
     const size_t maxlen = 1024;
     char line[maxlen];
     char context[512] = { 0 };
     bool truncated = false;
     while (ifs.good()) {
         ifs.getline(line, maxlen);
         if (ifs.fail() && ifs.gcount() == (maxlen-1)) {
             if (!truncated) {
                 LOG(LOG_INFO, "Line too long in configuration file");
                 hexdump(line, maxlen-1);
             }
             ifs.clear();
             truncated = true;
             continue;
         }
         if (truncated) {
             truncated = false;
             continue;
         }
         char * tmp_line = line;
         while (isspace(*tmp_line)) tmp_line++;
         if (*tmp_line == '#') continue;
         char * last_char_ptr = tmp_line + strlen(tmp_line) - 1;
         while ((last_char_ptr >= tmp_line) && isspace(*last_char_ptr)) last_char_ptr--;
         if (last_char_ptr < tmp_line) continue;
         *(last_char_ptr + 1) = '\0';
         //LOG(LOG_INFO, "Line='%s'", tmp_line);
         this->parseline(configuration_holder, tmp_line, context);
     };
 }
Exemplo n.º 14
0
std::streamsize fullread(
	std::istream& istr,
	char* buf,
	std::streamsize requested)
{
	std::streamsize got;
	std::streamsize total = 0;

	istr.read(buf, requested);	 /*Flawfinder: ignore*/
	got = istr.gcount();
	total += got;
	while(got && total < requested)
	{
		if(istr.fail())
		{
			// If bad is true, not much we can doo -- it implies loss
			// of stream integrity. Bail in that case, and otherwise
			// clear and attempt to continue.
			if(istr.bad()) return total;
			istr.clear();
		}
		istr.read(buf + total, requested - total);	 /*Flawfinder: ignore*/
		got = istr.gcount();
		total += got;
	}
	return total;
}
Exemplo n.º 15
0
			IndexEntry readEntry(std::istream & indexistr, uint64_t const entryid) const
			{
				uint64_t const entrybitpos = getEntryBitPos(entryid);
				uint64_t const entrybytepos = entrybitpos>>3;
				uint64_t const entrybitoff = entrybitpos - (entrybytepos<<3);

				// seek to index position
				indexistr.clear();
				indexistr.seekg(entrybytepos,std::ios::beg);
				if ( static_cast<int64_t>(indexistr.tellg()) != static_cast<int64_t>(entrybytepos) )
				{
					::libmaus2::exception::LibMausException se;
					se.getStream() << "Failed to seek to index position " << entrybytepos << " in file " << filename << " of size "
						<< ::libmaus2::util::GetFileSize::getFileSize(filename) << std::endl;
					se.finish();
					throw se;
				}
				::libmaus2::bitio::StreamBitInputStream SBIS(indexistr);

				SBIS.read(entrybitoff);

				uint64_t const pos = SBIS.read(posbits);
				uint64_t const kcnt = SBIS.read(kbits);
				uint64_t const vcnt = SBIS.read(vbits);

				return IndexEntry(pos,kcnt,vcnt);
			}
Exemplo n.º 16
0
/*!
 * \brief Check for a failure during the last stream input.
 *
 * If the last stream input did not succeed, throws an exception with
 * details on the stream position where this occurred.
 */
void check_failedload(std::istream &is)
   {
   if (is.fail())
      {
      std::ios::iostate state = is.rdstate();
      is.clear();
      std::ostringstream sout;
      sout << "Failure loading object at position " << is.tellg()
            << ", next line:" << std::endl;
      std::string s;
      getline(is, s);
      sout << s;
      is.clear(state);
      throw load_error(sout.str());
      }
   }
Exemplo n.º 17
0
std::string getDataFromIStream(std::istream& stream) {
    std::stringstream data;
    data << stream.rdbuf();

    stream.clear();

    return data.str();
}
 inline void
 AsciiXmlParser::returnToBeginningOfText()
 // this sets whichever stream textToParse is pointing at to start reading
 // again from its start.
 {
   resetContent();
   textStream->clear();
   textStream->seekg( std::ios::beg );
 }
Exemplo n.º 19
0
/*!
 * \brief
 * Initializes three aspects of the Gene Ontology using OBO structure and GO annotation files.
 * 
 * \param istmOntology
 * Stream from which OBO structure file is read.
 * 
 * \param istmAnnotations
 * Stream from which gene annotation file is read.
 * 
 * \param Genome
 * Genome into which genes are inserted or read during annotation parsing.
 * 
 * \param OntoBP
 * Ontology initialized with GO's biological process aspect.
 * 
 * \param OntoMF
 * Ontology initialized with GO's molecular function aspect.
 * 
 * \param OntoCC
 * Ontology initialized with GO's cellular compartment aspect.
 * 
 * \param fDatabaseIDs
 * If true, use annotation database IDs as primary gene names.
 * 
 * \param fSynonyms
 * If true, use first gene synonym (if present) as primary gene names.
 * 
 * \returns
 * True if the ontologies were successfully initialized.
 * 
 * Equivalent to calling COntologyOBO::Open three times for the three GO aspects.
 */
bool COntologyOBO::Open( std::istream& istmOntology, std::istream& istmAnnotations, CGenome& Genome,
	COntologyOBO& OntoBP, COntologyOBO& OntoMF, COntologyOBO& OntoCC, bool fDatabaseIDs, bool fSynonyms ) {

	if( !OntoBP.Open( istmOntology, istmAnnotations, Genome, c_szBiologicalProcess, fDatabaseIDs, fSynonyms ) )
		return false;

	istmOntology.clear( );
	istmOntology.seekg( 0, ios_base::beg );
	istmAnnotations.clear( );
	istmAnnotations.seekg( 0, ios_base::beg );
	if( !OntoCC.Open( istmOntology, istmAnnotations, Genome, c_szCellularComponent, fDatabaseIDs, fSynonyms ) )
		return false;

	istmOntology.clear( );
	istmOntology.seekg( 0, ios_base::beg );
	istmAnnotations.clear( );
	istmAnnotations.seekg( 0, ios_base::beg );
	return OntoMF.Open( istmOntology, istmAnnotations, Genome, c_szMolecularFunction, fDatabaseIDs, fSynonyms ); }
void HandleInvalidInput(std::istream &inputStream)
{
	inputStream.clear();
	std::cout << "Invalid option, please try again." << std::endl;
	while(inputStream.get() != '\n')
	{
		continue;
	}
}
Exemplo n.º 21
0
 static uint64_t readAtWordOffset(std::istream & in, uint64_t const pos)
 {
     in.clear();
     in.seekg( static_cast<int64_t>(pos * sizeof(uint64_t)), std::ios::cur);
     uint64_t const v = libmaus::util::NumberSerialisation::deserialiseNumber(in);
     in.seekg(-static_cast<int64_t>(  1 * sizeof(uint64_t)), std::ios::cur);
     in.seekg(-static_cast<int64_t>(pos * sizeof(uint64_t)), std::ios::cur);
     return v;
 }
Exemplo n.º 22
0
void Huffman::encode(std::istream &fin, bit::oBaseStream &bout, 
	std::map<char, std::vector<bool>>& coding) {
	fin.clear();
	fin.seekg(0, fin.beg);
	char c;
	while (fin >> c)
		for (auto b: coding[c])
			bout << b;
}
const std::string StreamToString( std::istream& iss )
{
    std::stringstream ss;
    iss.clear();
    std::copy( std::istreambuf_iterator<char>(iss),
               std::istreambuf_iterator<char>(),
               std::ostreambuf_iterator<char>(ss));
    return ss.str();
}
Exemplo n.º 24
0
	// flush cin stream
	// this is used in a cin >> non-string-variable situation
	const std::string bh_flush_cin(std::istream & os)
	{
		if (!os) {
			os.clear();
			std::string buffer;
			os >> buffer;
			os.get();
			return buffer;
		}
Exemplo n.º 25
0
std::string Token::toString(std::istream &input) {
  std::string s;

  input.clear();
  input.seekg(position, std::istream::beg);
  for (int i = 0; i < length; i++)
    s += char(input.get());

  return s;
}
Exemplo n.º 26
0
void OthelloScheduler::provideData(std::istream& input)
{
    input.clear();
    input.seekg(0);
    input >>_commonSeed;
    input >>_repetitions;
    vector<Field> playfield;
    OthelloHelper::readPlayfieldFromStream(input, playfield);
    _state = State(playfield, DEFAULT_PLAYER);
}
Exemplo n.º 27
0
std::string get_input_line(std::istream& stream, std::streampos position)
{
    static std::vector<char> line_buffer(1024, 0);

    stream.clear();
    stream.seekg(position);
    stream.getline(&line_buffer[0], line_buffer.size());

    return std::string(&line_buffer[0], &line_buffer[static_cast<std::size_t>(stream.gcount())]);
}
Exemplo n.º 28
0
void property_tree::from_unknown_seekable( std::istream& stream, boost::property_tree::ptree& ptree, property_tree::path_value::check_repeated_paths check_type, char equal_sign, char delimiter, bool use_index )
{
    if( !is_seekable( stream ) ) {
        COMMA_THROW( comma::exception, "input stream is not seekable" );
    }
    try
    {
        stream.clear();
        stream.seekg( 0, std::ios::beg );
        boost::property_tree::read_json( stream, ptree );
        return;
    }
    catch( const boost::property_tree::ptree_error&  ex ) {}
    catch(...) {
        throw;
    }
    try
    {
        stream.clear();
        stream.seekg( 0, std::ios::beg );
        comma::property_tree::read_xml( stream, ptree );
        return;
    }
    catch( const boost::property_tree::ptree_error&  ex ) {}
    catch(...) {
        throw;
    }
    try
    {
        stream.clear();
        stream.seekg( 0, std::ios::beg );
        comma::property_tree::from_path_value( stream, ptree, check_type, equal_sign, delimiter, use_index );
        return;
    }
    catch( const boost::property_tree::ptree_error&  ex ) {}
    catch( const comma::exception&  ex ) {}
    catch(...) {
        throw;
    }
    // TODO: add try for ini format (currently the problem is that path-value treats ini sections and comments as valid entries; possible solution: make path-value parser stricter)
    COMMA_THROW( comma::exception, "failed to guess format" );
}
Exemplo n.º 29
0
	std::string PTXParser::getLinesNearCurrentLocation( std::istream& input )
	{
		if( !input.good() )
		{
			input.clear();
		}

		input.seekg( 0, std::ios::beg );
		
		unsigned int beginLine = 0;
		
		if(!state.statements.empty())
		{
			beginLine = state.statements.back().line;
		}
		
		const unsigned int offset = 10;

		if(beginLine > offset) beginLine -= offset;
		
		unsigned int endLine = beginLine + 2 * offset;
		
		unsigned int currentLine = 0;
		
		while(input.good())
		{
			if(currentLine == beginLine) break;

			char n = input.get();
			
			if(n == '\n')
			{
				++currentLine;
			}
		}
		
		std::string result;
		
		while(input.good())
		{
			if(currentLine >= endLine) break;

			char n = input.get();
			
			result += n;
			
			if(n == '\n')
			{
				++currentLine;
			}
		}
		
		return hydrazine::addLineNumbers(result, beginLine + 1);
	}
Exemplo n.º 30
0
			libmaus::autoarray::AutoArray<char> readSequence(std::istream & in, int64_t const seqid) const
			{
				if ( seqid < 0 || seqid >= static_cast<int64_t>(sequences.size()) )
				{
					libmaus::exception::LibMausException lme;
					lme.getStream() << "FastAIndexEntry::readSequence(): sequence id " << seqid << " is out of range" << std::endl;
					lme.finish();
					throw lme;				
				}
				
				libmaus::fastx::FastAIndexEntry const entry = sequences.at(seqid);
				uint64_t const lineskip = entry.bytesperline-entry.basesperline;
			
				libmaus::autoarray::AutoArray<char> A(entry.length,false);
				char * cur = A.begin();
				
				uint64_t todo = entry.length;
				
				in.clear();
				in.seekg(entry.offset,std::ios::beg);
				
				while ( todo )
				{
					uint64_t const re = std::min(todo,entry.basesperline);
					
					in.read(cur,re);
					
					if ( in.gcount() != static_cast<int64_t>(re) )
					{
						libmaus::exception::LibMausException lme;
						lme.getStream() << "FastAIndexEntry::readSequence(): failed to read sequence " << entry.name << std::endl;
						lme.finish();
						throw lme;					
					}

					cur += re;
					todo -= re;
					
					if ( todo )
					{
						in.ignore(lineskip);

						if ( in.gcount() != static_cast<int64_t>(lineskip) )
						{
							libmaus::exception::LibMausException lme;
							lme.getStream() << "FastAIndexEntry::readSequence(): failed to read sequence " << entry.name << std::endl;
							lme.finish();
							throw lme;				
						}	
					}				
				}
				
				return A;
			}