Exemple #1
0
bool OggPage::find_capture_pattern(std::istream& from)
{
	char ch;
	while(from)
	{
		while(from.get(ch) && (ch != 'O'));
		if(from.get(ch) && (ch != 'g'))
		{
			from.putback(ch);
			continue;
		}
		if(from.get(ch) && (ch != 'g'))
		{
			from.putback(ch);
			continue;
		}
		if(from.get(ch) && (ch != 'S'))
		{
			from.putback(ch);
			continue;
		}
		from.putback('S');
		from.putback('g');
		from.putback('g');
		from.putback('O');
		return bool(from);
	}
	return false;
}
Exemple #2
0
void Sistema::cargar(std::istream & is)
{
  std::string non;
  //adelanto hasta el campo
  getline(is, non, '{');
  getline(is, non, '{');
  is.putback('{');
  //cargo el campo
  _campo.cargar(is);

  // cargo todos los drones
  // adelanto hasta encontrar donde empieza cada drone ({) o hasta llegar al ] que
  // es donde termina la lista de drones
  char c;
  while (c != ']') {
    is.get(c);
    if (c == '{') {
      is.putback('{');
      Drone d;
      d.cargar(is);
      _enjambre.push_back(d);
    }
  }

  // despues de los drones obtengo todo hasta el final que son los estados de cultivos
  getline(is, non);
  Secuencia<std::string> estadosCultivosFilas;
  // con el substr saco el " " inicial y el } final!
  estadosCultivosFilas = cargarLista(non.substr(1, non.length()-2), "[", "]");

  // este vector va a tener todos los estados pero "aplanado", todos en hilera
  // y cuando los asigne voy accediendolo como todosEstadosCultivos[n_fila*ancho + posicion en Y]
  Secuencia<std::string> todosEstadosCultivos;

  int n = 0;
  while (n < estadosCultivosFilas.size()) {
    Secuencia<string> tmp = splitBy(estadosCultivosFilas[n].substr(1, estadosCultivosFilas[n].length() - 2), ",");
    todosEstadosCultivos.insert(todosEstadosCultivos.end(), tmp.begin(), tmp.end());
    n++;
  }

  // creo la grilla de estados con las dimensiones correctas
  Dimension dim;
  dim.ancho = estadosCultivosFilas.size();
  dim.largo = todosEstadosCultivos.size() / estadosCultivosFilas.size();
  _estado = Grilla<EstadoCultivo>(dim);

  // asigno todos los estados dentro de la grilla
  int x = 0;
  while (x < dim.ancho) {
    int y = 0;
    while (y < dim.largo) {
      _estado.parcelas[x][y] = dameEstadoCultivoDesdeString(todosEstadosCultivos[x*dim.ancho+y]);
      y++;
    }
    x++;
  }
  //gane :)
}
Exemple #3
0
void partitioning<Grid>::read_partition(std::istream& in)
{ 
 int p;
 partial_mapping<int,int> part_nums(-1);
 CellIterator C = TheGrid().FirstCell();
 
 
 char c;
 in >> c;
 in.putback(c);
 if(isdigit(c)) {
   while(in && ! C.IsDone()) {
     in >> p;
     int np = ranges.size()-1; //NumOfPartitions();
     for( int pp = 0; pp <= p - np; ++pp)
       add_partition();
     // if( part_nums(p) == -1) {
     //  part_nums[p] = add_partition();
     // }
     add_cell(p,*C);
     ++C;
   }
   if(!in && ! C.IsDone()) {
     std::cerr << "partitioning<Grid>::read_partition(): input ended prematurely!\n"
	       << "creating new partition for the remaining cells.\n";
     p = add_partition();
     while(! C.IsDone()) {
       add_cell(p,*C);
       ++C;
     }
   }
 }
 else {
Exemple #4
0
/**
 * Standard input for a Fuzzy SOM
 * Parameter: _is The input stream
 */
void FuzzyMap::readSelf(std::istream& _is, const unsigned _size)
{
    clear();
    int dim;
    std::string layout, str;
    _is >> dim;
    _is >> layout;
    if (layout == "HEXA")
    {
        HEXALayout *tmpLayout = new HEXALayout();
        somLayout = tmpLayout;
    }
    else
    {
        RECTLayout *tmpLayout = new RECTLayout();
        somLayout = tmpLayout;
    }
    _is >> somWidth;
    _is >> somHeight;
    str = integerToString(dim);
    str += " ";
    str += integerToString(somWidth * somHeight);
    str += " ";
    for (int i = str.size() - 1; i >= 0; i--)
        if (_is)
            _is.putback((char) str[i]);
    FuzzyCodeBook::readSelf(_is, _size);

}
Exemple #5
0
			static int getFirstCharacter(std::istream & in)
			{
				int const c = in.peek();
				if ( c >= 0 )
					in.putback(c);
				return c;
			}
Exemple #6
0
std::string Template::readTemplateCommand(std::istream& in)
{
	std::string command;

	readWhiteSpace(in);

	int c = in.get();
	while(c != -1)
	{
		if ( Ascii::isSpace(c) )
			break;

		if ( c == '?' && in.peek() == '>' )
		{
			in.putback(c);
			break;
		}

		if ( c == '=' && command.length() == 0 )
		{
			command = "echo";
			break;
		}

		command += c;

		c = in.get();
	}

	return command;
}
Exemple #7
0
void MessageHeader::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();
	int ch = istr.get();
	while (ch != eof && ch != '\r' && ch != '\n')
	{
		std::string name;
		std::string value;
		while (ch != eof && ch != ':' && ch != '\n' && name.length() < MAX_NAME_LENGTH) { name += ch; ch = istr.get(); }
		if (ch == '\n') { ch = istr.get(); continue; } // ignore invalid header lines
		if (ch != ':') throw MessageException("Field name too long/no colon found");
		if (ch != eof) ch = istr.get(); // ':'
		while (std::isspace(ch)) ch = istr.get();
		while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH) { value += ch; ch = istr.get(); }
		if (ch == '\r') ch = istr.get();
		if (ch == '\n')
			ch = istr.get();
		else if (ch != eof)
			throw MessageException("Field value too long/no CRLF found");
		while (ch == ' ' || ch == '\t') // folding
		{
			while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH) { value += ch; ch = istr.get(); }
			if (ch == '\r') ch = istr.get();
			if (ch == '\n')
				ch = istr.get();
			else if (ch != eof)
				throw MessageException("Folded field value too long/no CRLF found");
		}
		add(name, value);
	}
	istr.putback(ch);
}
void parseExpression(Node *&node, std::istream &in)
{
	char ch = in.get();
	while (!isNumber(ch) && !isOperator(ch) && !in.eof())
	{
		ch = in.get();
	}
	if (in.eof())
	{
		node = createNode('?', true);
		return;
	}
	else
	{
		bool isOperatorCh = isOperator(ch);
		int added = 0;
		if (isOperatorCh)
		{
			added = static_cast<int>(ch);
		}
		else
		{
			in.putback(ch);
			in >> added;
		}
		node = createNode(added, isOperatorCh);
		if (isOperatorCh)
		{
			parseExpression(node->leftChild, in);
			parseExpression(node->rightChild, in);
		}
	}
}
Exemple #9
0
	bool Lexer::readNext( LexToken &tk, std::istream &is ) {
		bool reading = true;
		char ch;
		tk.t_ = T_UNDEFINED;
		tk.s_.clear();

		while( reading ) {
			ch = is.get();
			/*std::cout << "char: " << ch;
			std::cout << " tok: " << tk.t_;
			std::cout << " state: " << state_;
			std::cout << " str: " << tk.s_;
			std::cout << std::endl;*/
			
			
			if( is.bad() || is.eof() ) {
				ch = I_EOF;
				reading = false;
			}

			const Action& a = getAction_(state_,ch);
			switch( a.charAction ) {
				case A_ADD:
					tk.s_ += ch;
					break;
				
				case A_PUTBACK:
					if(ch != I_EOF )
						is.putback(ch);
					break;
				
				case A_IGNORE:
					break;
				
				case A_ERROR:
					tk.t_ = T_UNDEFINED;
					tk.s_.clear();
					reset();
					throw IncorrectTextException();
					break;
			}

			switch( a.bufferAction ) {
				case A_UNCHANGED: break;
				case A_CLEAR: tk.s_.clear(); break;
				case A_RETURN: reading = false; break;
			}

			if( a.newTokenType != T_UNCHANGED )
				tk.t_ = a.newTokenType;

			state_ = a.toState;
		}

		if( ch == I_EOF )
			return false;
		else
			return true;
	}
void setDataToIStream(std::istream& stream, std::string data) {
    int dataSize = data.size();
    const char* rawData = data.c_str();

    for (int i = dataSize; i > 0; i--) {
        stream.putback(rawData[i - 1]);
    }
}
Exemple #11
0
Token tok(std::istream& in) {
  char c;

restart:
  c = in.get();

  if(c == '(') {
    return Token::open();
  }

  if(c == ')') {
    return Token::close();
  }

  if(isnumber(c)) {
    int val = (int)(c - 48);

    c = in.get();

    while(isnumber(c)) {
      val *= 10;
      val += (int)(c - 48);
      c = in.get();
    }

    in.putback(c);

    return Token::number(val);
  }

  if(!isspace(c) && isprint(c)) {
    std::ostringstream ss;

    while(!isspace(c) && isprint(c) && c != '(' && c != ')') {
      ss.put(c);
      c = in.get();
    }

    in.putback(c);
    return Token::sym(ss.str().c_str());
  }

  if(isspace(c)) goto restart;

  return Token::fin();
}
 inline void eatSpaces(std::istream& inStream){
     char c = '\0';
     while(inStream.good()){
         inStream.get(c);
         if(c != ' ' && c != '\t'){
             inStream.putback(c);
             break;
         }
     }
 }
void CdTreeStream::readToDelimiter(std::istream& is, std::string& str)
{
	//str.erase();
	char ch;
	while (is.get(ch) && (!isDelimiter(ch)))
		//if (!isspace((unsigned char) ch))
			str += ch;
	if (isDelimiter(ch))
		is.putback(ch);
}
Exemple #14
0
 // skip_comments(is) utilise la fonction précédente pour sauter zéro, une ou plusieurs lignes
 // de commentaires débutées par '#' et allant jusqu'à '\n'.
 static void skip_comments(std::istream& is)
 {
  char c;
  is.get(c);       // Lire un caractère.
  while(c=='#')    // Tant que c'est un '#'.
   {
    skip_line(is); // On élimine les caractères jusqu'à la fin de ligne,
    is.get(c);     // Et on lit un nouveau caractère.
   }
  is.putback(c);   // On remet le caractère lu puisqu'il n'est pas un '#'.
 }
Exemple #15
0
 void skip_comment_lines( std::istream &in, const char comment_start)
 {
   char c, line[256];
   
   while (in.get(c), c==comment_start) 
     in.getline (line, 255);
   
   // put back first character of
   // first non-comment line
   in.putback (c);
 }
void ObjectFactory::PutBackTag(std::istream& iStream, const std::string& sTag)
{
   std::string realtag = std::string("<") + sTag + std::string(">");

   std::reverse(realtag.begin(), realtag.end());

   for (size_t i=0;i<realtag.length();i++)
   {
      iStream.putback(realtag[i]);
   }
}
void ObjectFactory::PutBackValue(std::istream& iStream, const std::string& sValue)
{
   std::string v = sValue; // copy value to reverse it!

   std::reverse(v.begin(), v.end());

   for (size_t i=0;i<v.length();i++)
   {
      iStream.putback(v[i]);
   }

}
Exemple #18
0
bool putback_test_two(std::istream& is)
{
    try {
        do {
            char buf[chunk_size];
            is.read(buf, chunk_size);
            if (is.gcount() < static_cast<std::streamsize>(chunk_size))
                break;
            is.putback('a');
            is.putback('b');
            is.putback('c');
            is.putback('d');
            if ( is.get() != 'd' || is.get() != 'c' ||
                 is.get() != 'b' || is.get() != 'a' )
            {
                return false;
            }
        } while (!is.eof());
        return true;
    } catch (std::exception&) { return false; }
}
Exemple #19
0
			static bool isGzip(std::istream & in)
			{
				int const b0 = in.get();
				
				if ( b0 < 0 )
					return false;
				
				int const b1 = in.get();
				
				if ( b1 < 0 )
				{
					in.clear();
					in.putback(b0);
					return false;
				}
				
				in.clear();
				in.putback(b1);
				in.putback(b0);
				
				return b0 == libmaus2::lz::GzipHeaderConstantsBase::ID1 &&
				       b1 == libmaus2::lz::GzipHeaderConstantsBase::ID2;
			}
Exemple #20
0
bool utl::ignoreComments (std::istream& is)
{
  int c = ' ';
  while (isspace(c))
    c = is.get();

  while (c == '#')
  {
    is.ignore(256,'\n');
    c = is.get();
  }
  is.putback(c);

  return is.good();
}
std::string getStartingDataWithoutTouchingStream(std::istream& stream, int size) {
    char buffer[size];
    stream.read(buffer, size);

    // it is necessary to remove eofbit flag in the case of when the blockSize_
    // is greather than the total length of input
    stream.clear();

    int lastReadable = (int)stream.gcount();

    for (int i = lastReadable; i > 0; i--) {
        stream.putback(buffer[i - 1]);
    }

    return std::string(buffer, lastReadable);
}
std::string ObjectFactory::GetValue(std::istream& iStream)
{
   char ch = '\0';
   std::string sValue;

   while (ch != '<' && iStream.good())
   {
      iStream.get(ch);
      if (ch!='<')
         sValue += ch;
   }

   if (ch=='<') iStream.putback(ch);

   return sValue;
}
Exemple #23
0
bool simple_parser::parse_token( std::istream& xmlFile,
                                 std::string& token, bool& isComment)
{
   token.clear();
   bool isInTag = false;
   isComment = false;
   char c = 0;

   for(;;)
   {
      c = xmlFile.get();
      if ( xmlFile.eof() )
         break;

      if ( isspace(c) && token.empty() )
         continue;

      if ( c == '<' && !isComment )
      {
         if ( !token.empty() ) // end of a in-token
         {
            xmlFile.putback(c);
            break;
         }

         isInTag = true;
         continue;
      }
      else if ( c == '>' )
      {
         if ( isComment )
         {
            if ( token.substr(token.size()-2,2) == "--" )
               break;
         }
         else
            break;
      }

      token.append(1, c);
      if ( token.size() == 3 && token == "!--" )
         isComment = true;
   }

   return isInTag;
}
Exemple #24
0
bool ASMs1D::read (std::istream& is)
{
  if (shareFE) return true;
  if (curv) delete curv;

  Go::ObjectHeader head;
  curv = new Go::SplineCurve;
  is >> head >> *curv;

  // Eat white-space characters to see if there is more data to read
  char c;
  while (is.get(c))
    if (!isspace(c))
    {
      is.putback(c);
      break;
    }

  if (!is.good() && !is.eof())
  {
    std::cerr <<" *** ASMs1D::read: Failure reading spline data"<< std::endl;
    delete curv;
    curv = nullptr;
    return false;
  }
  else if (curv->dimension() < 1)
  {
    std::cerr <<" *** ASMs1D::read: Invalid spline curve patch, dim="
	      << curv->dimension() << std::endl;
    delete curv;
    curv = nullptr;
    return false;
  }
  else if (curv->dimension() < nsd)
  {
    std::cout <<"  ** ASMs1D::read: The dimension of this curve patch "
	      << curv->dimension() <<" is less than nsd="<< (int)nsd
	      <<".\n                   Resetting nsd to "<< curv->dimension()
	      <<" for this patch."<< std::endl;
    nsd = curv->dimension();
  }

  geo = curv;
  return true;
}
void SceneImporter<real>::SkipBlanks( std::istream& stream )
{
	// Skip spaces
	while( stream && ( ( stream.peek() == ' ' ) ||
						  ( stream.peek() == '\n' ) ||
						  ( stream.peek() == '\r' ) ||
						  ( stream.peek() == '\t' ) ||
						  ( stream.peek() == '/' ) ) )
	{
		if ( stream.peek() == '\n' )
			mCurrentLine++;

		char c = stream.get();

		// Commentary
		if ( ( c == '/' ) && ( stream.peek() == '/' ) )
		{
			// Skip line
			while( stream && ( ( stream.peek() != '\r' ) && ( stream.peek() != '\n' ) ) )
				stream.get();
		}
		else if ( ( c == '/' ) && ( stream.peek() == '*' ) )
		{
			stream.get();

			// Skip to '*/'
			do
			{
				c = stream.get();

				if ( c == '\n' )
					mCurrentLine++;

			} while ( stream && ( ( c != '*' ) || ( stream.get() != '/' ) ) );

			stream.get();
		}
		else if ( c == '/' )
		{
			// Cancel blank skip
			stream.putback( c );
			break;
		}
	}
}
Exemple #26
0
// Try to consume characters from the input stream and match the
// pattern string. Leading whitespaces from the input are ignored if
// ignore_ws is true.
bool match(const std::string& pattern, std::istream& input,
           bool ignore_ws) {
    if (ignore_ws) {
        eat_whitespaces(input);
    }
    std::string::const_iterator cur(pattern.begin());
    char ch(0);
    while(input && !input.eof() && cur != pattern.end()) {
        input.get(ch);
        if (ch != *cur) {
            input.putback(ch);
            return false;
        } else {
            cur++;
        }
    }
    return cur == pattern.end();
}
Exemple #27
0
void readFastaEntry(std::istream& i,
		    std::string& name,
		    std::string& description,
		    std::string& sequence)
  throw (ParseException)
{
    char ch;
    char c[512];

    i.getline(c, 511);
    if (i) {
      if (c[0] != '>') {
	throw ParseException(std::string("FASTA file expected '>', got: '")
			     + c[0] + "'");
      }

      std::string nameDesc = c + 1;
      std::string::size_type spacepos = nameDesc.find(" ");
      name = nameDesc.substr(0, spacepos);
      description = (spacepos == std::string::npos
		     ? ""
		     : nameDesc.substr(spacepos));

      for (ch = i.get(); (ch != EOF) && (ch != '>'); ch = i.get()) {
	if ((ch != '\n') && (ch != '\r') && (ch != ' ')) {
	  if (((ch >= 'a') && (ch <= 'z'))
	      || ((ch >= 'A') && (ch <= 'Z'))
	      || (ch == '-') || (ch == '*')) {
	    sequence += ch;
	  } else {
	    throw ParseException
	      (std::string("Illegal character in FASTA file: '")
	       + (char)ch + "'");
	  }
	}

	if (i.peek() == EOF)
	  break;
      }

      if (ch == '>')
	i.putback(ch);
    }
}
Exemple #28
0
// skip blanks, tabs, line breaks and comment lines
int skip_comment_line (std::istream & in) {
  int c;

  do {
    c = in.get();
    while ( c == '#' ) {
      do {
        c = in.get();
      } while ( c != '\n' );
      c = in.get();
    }
  } while (c == ' ' || c == '\t' || c == '\n');

  if (c == EOF)
    core_io_error_handler("CoreIO::read_from_file()","unexpected end of file.");

  in.putback(c);
  return c;
}
Exemple #29
0
void MessageHeader::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();
	std::streambuf& buf = *istr.rdbuf();

	std::string name;
	std::string value;
	name.reserve(32);
	value.reserve(64);
	int ch = buf.sbumpc();
	int fields = 0;
	while (ch != eof && ch != '\r' && ch != '\n')
	{
		if (_fieldLimit > 0 && fields == _fieldLimit)
			throw MessageException("Too many header fields");
		name.clear();
		value.clear();
		while (ch != eof && ch != ':' && ch != '\n' && name.length() < MAX_NAME_LENGTH) { name += ch; ch = buf.sbumpc(); }
		if (ch == '\n') { ch = buf.sbumpc(); continue; } // ignore invalid header lines
		if (ch != ':') throw MessageException("Field name too long/no colon found");
		if (ch != eof) ch = buf.sbumpc(); // ':'
		while (ch != eof && Poco::Ascii::isSpace(ch) && ch != '\r' && ch != '\n') ch = buf.sbumpc();
		while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH) { value += ch; ch = buf.sbumpc(); }
		if (ch == '\r') ch = buf.sbumpc();
		if (ch == '\n')
			ch = buf.sbumpc();
		else if (ch != eof)
			throw MessageException("Field value too long/no CRLF found");
		while (ch == ' ' || ch == '\t') // folding
		{
			while (ch != eof && ch != '\r' && ch != '\n' && value.length() < MAX_VALUE_LENGTH) { value += ch; ch = buf.sbumpc(); }
			if (ch == '\r') ch = buf.sbumpc();
			if (ch == '\n')
				ch = buf.sbumpc();
			else if (ch != eof)
				throw MessageException("Folded field value too long/no CRLF found");
		}
		Poco::trimRightInPlace(value);
		add(name, value);
		++fields;
	}
	istr.putback(ch);
}
Exemple #30
0
std::string Template::readQuery(std::istream& in)
{
	std::string word;
	int c;
	while((c = in.get()) != -1)
	{
		if ( c == '?' && in.peek() == '>' )
		{
			in.putback(c);
			break;
		}

		if ( Ascii::isSpace(c) )
		{
			break;
		}
		word += c;
	}
	return word;
}