Esempio n. 1
0
void safeGetline(istream& is, string& t)
{
    t.clear();
    std::istream::sentry se(is, true);
    std::streambuf* sb = is.rdbuf();
    
    while (true)
    {
        int c = sb->sbumpc();
        switch (c)
        {
            case '\n':
                return;
            case '\r':
                if (sb->sgetc() == '\n')
                    sb->sbumpc();
                return;
            case EOF:
                if (t.empty())
                    is.setstate(std::ios::eofbit);
                return;
            default:
                t += (char)c;
        }
    }
}
Esempio n. 2
0
Triangle::Triangle(istream& is) {
    try {
        is >> get<0>(vertices_) >> get<1>(vertices_) >> get<2>(vertices_);
    } catch (string s) {
        is.setstate(ios_base::failbit);
        cout << s << endl;
    }
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
//    Class:			CTime
//	  Method:			void CTime::input(istream& sin)
//	  Description:		input method for CTime objects
//	  Input:			sin
//    Called By:		constructor from DateTime/CTime, mutators, saferead
//    Parameters:		istream& sin - input istream
//    Returns:          n/a
//    History Log:
//                      4/29/15  KG  completed version 1.0
// ----------------------------------------------------------------------------
	void CTime::input(istream& sin)
	{
		int hour = 0;
		int minute = 0;
		int second = 0;
		m_hour = hour;
		m_second = second;
		m_minute = minute;
		char c = ' ';
		sin.get(c);
		if(c == '\n') //checks for no input if datetime
		{
			sin.putback(c);
			return;
		}
		sin.putback(c); //puts back character if normal input
		if(sin >> hour)
		{
			if(hour > MINTIME && hour <= MAXHOUR)
				m_hour = hour;
			sin.get(c);
			if(c == '\n')
			{
				sin.putback(c);
				return;
			}
			if(c == ':')
			{
				if(sin >> minute)
				{
					if(minute > MINTIME && minute < MAXMINSEC)
					{
						m_minute = minute;
					}
					sin.get(c);
					if(c == '\n')
					{
						sin.putback(c);
						return;
					}
					if(c == ':')
					{
						if(sin >> second)
						{
							if(second > MINTIME && second < MAXMINSEC)
							{
								m_second = second;
							}
						}
					}
					else
						sin.setstate(std::ios::failbit);
				}
			}
			else
Esempio n. 4
0
Player Player::OfGtpStream (istream& in) {
  string s;
  in >> s;
  if (!in) return Invalid ();
  if (s == "b" || s == "B" || s == "Black" || s == "BLACK "|| s == "black") { 
    return Black();
  }
  if (s == "w" || s == "W" || s == "White" || s == "WHITE "|| s == "white") {
    return White();
  }
  in.setstate (ios_base::badbit); // TODO undo read?
  return Invalid();
}
void GLUINavigationProgram::ReadDisplaySettings(istream& in)
{
  int dx,dy,dw,dh;
  dx = viewport.x; dy = viewport.y;
  dw = width-viewport.w; dh = height-viewport.h;
  in>>viewport;
  string str;
  in>>str;
  if(str != "ORBITDIST") { in.setstate(ios::badbit); return; }
  in>>camera.dist;

  camera.fromCamera(viewport,camera.dist);
  glutReshapeWindow(viewport.w+dw+dx,viewport.h+dh+dy);
}
void from_string_vec(istream & sstr, vector<T> & vecValue)
{
  T value;
  while (isspace(sstr.peek())) 
    sstr.get();
  int c = sstr.get();
  if (c!='[') {
    sstr.setstate(ios::failbit);
    return;
  }
  while (isspace(sstr.peek())) 
    sstr.get(); 
  c = sstr.peek();
  if (c==']') {
    sstr.get();
    return;    
  }
  sstr >> value; 
  if (!sstr) 
    return;
  vecValue.push_back(value);
  while(true) {
    while (isspace(sstr.peek())) 
      sstr.get();
    c = sstr.get();      
    if (c!=',' && c!=']') {
      sstr.setstate(ios::failbit);
      return;
    }
    if (c==']') 
      return;
    sstr >> value; 
    if (!sstr) 
      return;
    vecValue.push_back(value);      
  }
}
Esempio n. 7
0
	template <> _UCXXEXPORT string _readToken<char, char_traits<char> >(istream & stream)
	{
		string temp;
		char_traits<char>::int_type c;
		while(true){
			c = stream.rdbuf()->sgetc();
			if(c != char_traits<char>::eof() && isspace(c) == false){
				stream.rdbuf()->sbumpc();
				temp.append(1, char_traits<char>::to_char_type(c));
			}else{
				break;
			}
		}
		if (temp.size() == 0)
			stream.setstate(ios_base::eofbit|ios_base::failbit);

		return temp;
        }
Esempio n. 8
0
void ReadOneRecord(istream& in, value& val)

{
  if (in.peek() != '{') { 		// bail if not at record start
    in.setstate(ios::failbit);  	// set stream failure, so we can detect it
    return; 
  }
  
  in.ignore(1024, '\n');
  while (true) {
    string line;
    getline(in, line, '\n');
    istringstream istr(line.c_str());
    if (istr.peek() == '}') break;
    std::pair<string, value> entry;
    ReadFieldname(istr, entry.first);
    ReadValue(istr, entry.second);
    cout << "pair<attribute : value> = <" << entry.first << " : " 
	 << entry.second << ">" << endl;
  }
}
int getMyNum(istream& is,char delim,bool & emptyFlag,bool & delimFlag,bool allowWS=false)  // deliminator is '/' or '\n' 
{
	stringstream ss;
	bool foundFirst=false;
	delimFlag=false;  //ensure it starts out FALSE
	char c='0';
	int myNum=-99; // init number
	is>>ws;  // built in skip leading whitespace
	//while(is.get(c) &&  !(delimFlag=delimFound(c,delim)) && c!=sysEOL)//c!=delim)
	while(is.get(c) &&  !(delimFlag=delimFound(c,delim)) && c!=sysEOL)//c!=delim)
		{
			//cout<<":"<<c<<":"<<endl;
			//cout<<"!"<<is.tellg()<<"!"<<endl;
			if((!foundFirst)&& c=='-') //check for a leading negative
			{
				ss<<c; //first char can b negative (-)
				foundFirst=true;
			}
			else if(!isIntChar(c))
			{
				if(!( allowWS && isWhiteSpaceChar(c))) // TODO could be combined w/ above if?
				
				{
					//TODO do not strip \n
					is.ignore(256,delim); // fails for >256 chars, okay by me
					is.setstate(ios::failbit);
					delimFlag=true;
				}
				
			}
			else
			{
				foundFirst=true; //set found first, if no negative and 
				ss<<c;
			}
		}
	// get size
	/*
	ss.seekg(0,ios::end);
	int size=ss.tellg();
	ss.seekg(0,ios::beg);
	*/
	int size=ss.str().size();
	if( size==0 ||(size=1 && ss.str()=="-")) // check for empty, or single '-'
	{
		emptyFlag=true;
		
	}
	
	
	
	
	ss>> myNum; //stuff result into an int
	/*
	if(is.fail()&& !allowWS) // kluge 12 3/345 doesnt => 12
	{
		cout <<"magic3"<<endl;
		is.unget();
		is.putback(delim);
	}
	*/
	if(delim != sysEOL && is.peek()==sysEOL)  //kluge for 88/<LF>, otherwise grabs next line
	{
		cout <<"Magic2"<<endl;
		is.unget();
	}
		
	if(delim== sysEOL || c== sysEOL) // put back EOL or (c == sysEOL) kinda duplication
	
	//if(c== sysEOL&&(emptyFlag&&delim==sysEOL)) // put back EOL or (c == sysEOL) kinda duplication
		{
			//cout<<"putting LF back"<<endl;
			is.unget();

		}
		
	//kluge
	
	if( emptyFlag && delim == sysEOL) // check for empty, or single '-' for case of 7 <lf>, is.get(c) processed before delimFlag=delimFound...
	{
		is.unget();
		delimFlag=true;
		cout <<"Magic set flag"<<endl;
		myNum=1;
		
	}
	
		is.clear(); //clear all flags
		
	return myNum;
}