Esempio n. 1
0
bool Order::receive(istream& is){
	bool error = false;
	int a = 0;
	while (!error){
		cout << "Quantity (0  to quit): ";
		is >> a;
		is.clear();
		is.ignore();
		if (!is){
			is.clear();
			is.ignore(2000, '\n');
			cerr << "Error try again" << endl;
		}else if (a == 0){
			error = true;
			cerr << "No delivery recorded" << endl;
			return false;
		}else if (a < 0){
			cerr << "Please enter positive value" << endl;
		}
		else if (a > qtyOrder){
			cerr << a << " not on order.  Only " << qtyOrder << " are on order.  Try again" << endl;
		}else{
			qtyDeliver = qtyDeliver + a;
			return true;
		}
	}
}
Esempio n. 2
0
void Employee::setFromKeyboardByName(istream& in)
{
	string EGN;

	in >> EGN;
	while (!validateEGN(EGN))
	{
		in.clear();
		in.ignore(10000, '\n');
		in >> EGN;
	}
	this->EGN = EGN;

	in.clear();
	in.ignore(1);
	string address;
	getline(in, address);
	this->address = address;

	string hiredWhen;
	getline(in, hiredWhen);
	this->hiredWhen = hiredWhen;

	string boss;
	getline(in, boss);
	this->boss = boss;

	string projectName;
	getline(in, projectName);
	this->projectName = projectName;
}
Esempio n. 3
0
bool t_dir_graph::read_format2(istream& input, const string first_line){
	vector<t_vertex> verts;
	int adj;
	t_vertex v;
	uint datas = atoi(first_line.c_str());

	while(input.peek() == '\n') input.ignore(1); // read the '\n'
	// read vertices
	for(uint i = 0; i < datas; i++){
		input >> v;
		verts.push_back(v);
		while(input.peek() == '\n') input.ignore(1); // read the '\n'
	}
	for(uint i=0; i < verts.size(); i++) insert_vertex(verts[i]);
	// read adjacency matrix
	for(uint i=0; i < verts.size(); i++){
		for(uint j=0; j < verts.size(); j++){
			input >> adj;
			if(adj > 0)
				insert_arc(t_arc(verts[i], verts[j]));
			while(input.peek() == ' ') input.ignore(1); // read the ' '
			while(input.peek() == '\n') input.ignore(1); // read the '\n'
		}
	}
	return true;
}
Esempio n. 4
0
//---------------------------------------------------------------------------------
// Function:	getCoord()
// Title:	Get Coordinates 
// Description:
//		Returns a cell with coordinates set by user
// Programmer:	Paul Bladek
// 
// Date:	9/12/06
//
// Version:	1.0
// 
// Environment: Hardware: i3 
//              Software: OS: Windows 7; 
//              Compiles under Microsoft Visual C++ 2012
//
// Input:	cell coordinates (in the form "A13" from sin
//
// Output:	prompts to cout
//
// Calls:	none
//
// Called By:	main()
//		setships()
//
// Parameters:	sin: istream&;	the stream to read from
//		size: char;	'S' or 'L'
// 
// Returns:	Cell location -- a cell containing the input coordinates
//
// History Log: 
//				9/12/06 PB comleted v 1.0
//				1/20/15 KG % HN completed v 1.1
//     
//---------------------------------------------------------------------------------
Cell getCoord(istream& sin, char size)
{
	cin.clear();
	fflush(stdin);
	short numberOfRows = (toupper(size)=='L') ? LARGEROWS : SMALLROWS;
	short numberOfCols = (toupper(size)=='L') ? LARGECOLS : SMALLCOLS;
	char highChar = static_cast<char>(numberOfRows - 1) + 'A';
	char row  = 'A';
	short col = 0;
	Cell location = {0, 0};
	do
	{
		col = 0;
		cout << "Row must be a letter from A to " << highChar 
			<< " and column must be  from 1 to "  << numberOfCols << ": ";
		while((row = toupper(sin.get())) < 'A' || row  > highChar)
		{
			sin.ignore(BUFFER_SIZE, '\n');
			cout << "Row must be a letter from A to " << highChar 
				<< " and column must be  from 1 to "  << numberOfCols << ": ";
		}
		sin >> col;
		if(!sin)
			sin.clear();
		sin.ignore(BUFFER_SIZE, '\n');
	}
	while(col < 1 || col > numberOfCols);
	location.m_col = col - 1;
	location.m_row = static_cast<short>(row - 'A');
	return location;
}
Esempio n. 5
0
void Employee::set(istream& in, ostream& out)
{
	string name;
	in.clear();
	in.ignore(1);
	while (true)
	{
		getline(in, name);
		if (validateName(name))
		{
			this->name = name;
			break;
		}
		out << "Try again..." << endl;
	}

	string EGN;


	while (true)
	{
		in >> EGN;
		if (!validateEGN(EGN))
		{
			out << "Inavlid EGN" << endl;
			continue;
		}
		break;
	} 

	this->EGN = EGN;

	in.clear();
	in.ignore(1);
	string address;
	getline(in, address);
	this->address = address;

	string hiredWhen;
	getline(in, hiredWhen);
	this->hiredWhen = hiredWhen;

	string boss;
	getline(in, boss);
	this->boss = boss;

	this->position = (Position)0;

	string projectName;
	getline(in, projectName);
	this->projectName = projectName;
}
Esempio n. 6
0
vector<tag> getHtml(istream& input, int htmlLines){

    vector<tag> html;
    stack<tag> holdTag;



    for (size_t i = 0; i < htmlLines; i++) {
        tag temp;

        input.ignore(LINESIZE, '<');

        if (input.peek() == '/') {

            tag hold = holdTag.top();
            holdTag.pop();
            if (holdTag.empty()) {
                html.push_back(hold);
            }else{
                holdTag.top().children.push_back(hold);
            }

            input.ignore(LINESIZE, '\n');
        }else{

            holdTag.push(tag());
            input >> holdTag.top().tagName;

            if(holdTag.top().tagName.back() == '>'){
                holdTag.top().tagName.erase(holdTag.top().tagName.end()-1);
                input.unget();
                //remove the last char if the > char is found there
            }

            while(input.peek() != '>'){
                string key, val;
                input.get();
                getline(input, key, ' ');
                input.ignore(LINESIZE, '\"');
                getline(input, val, '\"');
                holdTag.top().attributes.insert(make_pair(key, val));

            }
        }




    }
    return html;
}
Esempio n. 7
0
void run(exploder & e, istream& in)
{
   // any larger, and we may try to write to a multi_frame that never has enough space
   static const int BUF_SIZE = multi_frame::MAX_SIZE - frame::FRAME_SIZE;
   scoped_array<char> buffer(new char[BUF_SIZE]);

   ios::sync_with_stdio(false); // makes a big difference on buffered i/o

   for (int line = 1; !in.eof(); ++line)
   {
      in.getline(buffer.get(), BUF_SIZE - 1); // leave 1 for us to inject back the newline
      if (buffer[0] == '\0')
         continue;
      if (in.fail()) // line was too long?
      {
         cerr << "Skipping line <" << line << ">: line is probably too long" << endl;
         in.clear(); // clear state
         in.ignore(numeric_limits<streamsize>::max(), '\n');
         continue;
      }
      buffer[in.gcount() - 1] = '\n'; // inject back the newline
      buffer[in.gcount()] = '\0';
      e << buffer.get();
   }
}
Esempio n. 8
0
//read coefficients from a stream. This assumes pairs of bitstring and values, e.g.
//010100 1.232
//101011 65.432
int hypercube_lowd::read_func_labeled(istream &in)
{
	int i=0, count;
	char gt[dim+2];
	if (in.bad())
	{
		cerr <<"hypercube_lowd::read_func_labeled: bad stream\n";
		return HC_BADARG;
	}
	count=0;
	while(in.good() && count<(1<<dim))
	{
		i=0;
		in >>gt;
		for (int k=0; k<dim; k++)
			if (gt[k]=='1') i+=1<<k;
		in >>func[i];
		count++;
		in.ignore(100, '\n');
	}
	if (count<(1<<dim))
	{
		cerr <<"hypercube_lowd::read_func: file end reached after "<<i<<" values!\n";
		return HC_BADARG;
	}
	return 0;
}
Esempio n. 9
0
/*
 * A modifier that receives a reference to an istream object and increases 
 * the number of copies to be ordered based upon data received from input stream is
 */
int Order::order(istream& is){
    bool flag = false;
    bool continueGoing = true; 
    bool isChanged = false;
    int iStream;

    while (continueGoing){
        cout << "Quantity (0 to quit) : ";
        is >> iStream;
        if (!is){
             is.clear();
             is.ignore(2000, '\n');
             cerr << "Error. Try Again " << endl;
        }
        else if(iStream == 0){
             cerr << "**No delivery recorded!" << endl; 
             continueGoing = false;
        }
        else if(iStream < 0){ 
             cerr << "Enter a positive number.  Try again." << endl; 
        }
        else{
             ordered = ordered + iStream;
             isChanged = true;
             continueGoing = false;
        }  
    }
    if(isChanged) 
        flag = true;
    return flag;
}
Esempio n. 10
0
bool SkipSpaces (istream& is, Coordinates& xy, Coordinates& pos)
{
	while (is.peek() == ' ' || is.peek() == '\n' || is.peek() == '\t' || is.peek() == '{')
	{
		if (is.peek() == '{')
		{
			char c='{';
			pos = xy;
			while (c != '}')
			{
				c = GetSymb(is, xy);
				if (c == EOF)
					return false;
			}
		}
		if (is.peek() == '\n')
		{
			xy.first = 1;
			++xy.second;
		}
		else
			if (is.peek() == '\t')
				xy.first += 8;
			else
				++xy.first;
		is.ignore();
	}
	return true;
}
Esempio n. 11
0
static void password_command(ostream &out, istream &in)
{
   char username[200] ;
   char oldpwd[200] ;
   char newpwd[200] ;
   
   out << "User name: " << flush ;
   in.ignore(1000,'\n') ;
   in.getline(username,sizeof(username)) ;
   out << "Old password: "******"New password: "******"Unknown username!" ;
      return ;
      }
   if (set_user_password(oldpwd,newpwd,userinfo))
      {
      cout << "Successfully set password." << endl ;
      if (!store_userinfo())
	 cout << "....but error updating user information file!" << endl ;
      }
   else
      cout << "Password update failed!" << endl ;
}
Esempio n. 12
0
bool SquareMaze::SquareMazeNode::readXY (istream& inData,int *x,int *y)
{
  char ch;
  // skip leading spaces, which are legit
  while (1) {
    inData.get(ch);
    if (ch!=' ') {
      break;
    }
  }
  if (ch!='(') {
    // not valid - probably a newline
    return false;
  }

  inData >> *x;
  if (inData.fail()) {
    inData.clear();
    cout << "WARNING: Solution seems to have a bad format\n";
    // a bit of random, defensive programming
    inData.ignore(100000,'\n'); // make sure we don't just keep reading the same thing
    return false;
  }
  inData.get(ch);
  inData >> *y;
  inData.get(ch);

  return true;
}
Esempio n. 13
0
void MidiPlugin::StreamIn(istream &s) 
{
	int version;
	s>>version;
		
	switch (version)
	{
		case 1:	s>>m_DeviceNum>>m_NoteCut; break;
		
		case 2:
		{
			s>>m_DeviceNum>>m_NoteCut; 
			
			int Num;
			s>>Num;
			
			for (int n=0; n<Num; n++)
			{
				int Control;
				s>>Control;
				
				char Buf[4096];	
				int size;		
				s>>size;
				s.ignore(1);
				s.get(Buf,size+1);								
				
				AddControl(Control, Buf);
			}			
		}
	}
}
void simulator::read(istream &in){
	const size_t n=input.size(), p=input[0].size()-1, s=result[0].size();

	for(size_t K=0; K<n; ++K){
		for(size_t L=0; L<p; ++L){
			in >> input[K][L];
			in.ignore(); //csv o ssv funciona
		}
		input[K][p] = 1; //entrada extendida
		
		for(size_t L=0; L<s; ++L){
			in >> result[K][L];
			in.ignore(); //csv o ssv funciona
		}
	}
}
Esempio n. 15
0
static void rmuser_command(ostream &out, istream &in)
{
   if (get_access_level() < ADMIN_ACCESS_LEVEL)
      {
      cout << "You must be logged in with administrator privileges\n"
	      "(access level " << ADMIN_ACCESS_LEVEL
	    << " or higher) to add users." << endl ;
      return ;
      }
   char username[200] ;

   out << "Name of user to remove: " << flush ;
   in.ignore(1000,'\n') ;
   in.getline(username,sizeof(username)) ;
   if (!retrieve_userinfo(username))
      {
      cout << "No such user!" ;
      return ;
      }
   if (remove_user(username))
      cout << "User information file updated." << endl ;
   else
      cout << "User information file update failed!" << endl ;
   return ;
}
Esempio n. 16
0
/*
 * A modifier that receives a reference to an istream object 
 * and records receipt of copies based upon data from the input stream
 */
int Order::receive(istream& is){
    bool flag = false;
    bool continueGoing = true; 
    bool isChanged = false;
    int iStream;
 
    while (continueGoing){
        cout << "Quantity (0 to quit) : ";
        is >> iStream;
        if (!is) {
            is.clear();
            is.ignore(2000, '\n');
            cerr << "Error. Try Again " << endl;
        }
        else if (iStream == 0){
            continueGoing = false;
        }
        else if (iStream < 0){
            cerr << "Positive value only. Try again." << endl;
        }
        else if (iStream > ordered){
            cerr << iStream << " not on order. Only " << ordered << " are on order. Try again. " << endl;
        }
        else{
            delivered = delivered + iStream;
            isChanged = true;
            continueGoing = false;
        }
         
    }
    if (isChanged) 
        flag = true;
    return flag;
}
Esempio n. 17
0
void Simulation::checkpoint (istream& stream, int checkpointNum) {
    util::checkpoint::header (stream);
    util::CommandLine::staticCheckpoint (stream);
    Population::staticCheckpoint (stream);
    Surveys & stream;
    
    Global::simulationTime & stream;
    Global::timeStep & stream;
    simPeriodEnd & stream;
    totalSimDuration & stream;
    phase & stream;
    (*_population) & stream;
    
    // read last, because other loads may use random numbers:
    util::random::checkpoint (stream, checkpointNum);
    
    // Check scenario.xml and checkpoint files correspond:
    int oldWUID(workUnitIdentifier);
    util::Checksum oldCksum(cksum);
    workUnitIdentifier & stream;
    cksum & stream;
    if (workUnitIdentifier != oldWUID || cksum != oldCksum)
	throw util::checkpoint_error ("mismatched checkpoint");
    
    stream.ignore (numeric_limits<streamsize>::max()-1);	// skip to end of file
    if (stream.gcount () != 0) {
	ostringstream msg;
	msg << "Checkpointing file has " << stream.gcount() << " bytes remaining." << endl;
	throw util::checkpoint_error (msg.str());
    } else if (stream.fail())
	throw util::checkpoint_error ("stream read error");
}
Esempio n. 18
0
void
SpatialDomain::ignoreCrLf(istream &in) {
  char c = in.peek();
  while (c == 10 || c == 13) {
    in.ignore();
    c = in.peek();
  }
}
Esempio n. 19
0
// Initialize a JSON object from a stream (presumably creating a whole
// hierarchy)
//
// This is the big one. :)  The expectation is that the first character
// will be a '{' and the function will run until if finds a matching '}'
// char.  Along the way, it may create nested objects and/or arrays
// (which means it may be called recursively - by way of
// initValueFromStream())
// Note: The function will consume the closing brace from the stream
void initFromStream(JSONObject &obj, istream &istr) {
  char nextChar;
  istr >> nextChar;
  checkChar(nextChar, '{'); // sanity check
  skipWhiteSpace(istr);

  // Check for empty object (and make sure we consume the })
  nextChar = static_cast<char>(istr.peek());
  if (nextChar == '}') {
    istr.ignore();
  }

  while (nextChar != '}') // process the stream
  {
    // Quick sanity check
    if (istr.eof()) {
      throw JSONParseException("Unexpected end of data stream");
    }

    // We expect to start the loop with the stream pointing to the opening quote
    // of the key
    nextChar = static_cast<char>(istr.peek());
    checkChar(nextChar, '"');

    string key = readString(istr);
    istr >> nextChar;         // >> operator automatically skips white space
    checkChar(nextChar, ':'); // the separator between the key and the value

    skipWhiteSpace(istr);

    // Now. we're at the start of the value.
    // Add the key and value to our object
    obj[key] = initValueFromStream(istr);
    istr >> nextChar;
    // nextChar is guaranteed to be either a comma, close brace or close
    // bracket.
    //(If it was anything else, initValueFromStream() would have thrown an
    // exception.)
    // A bracket is an error, a brace means the object is done (and will be
    // checked at
    // the start of the while loop) and a comma needs to be thrown out (along
    // with any
    // following whitespace) to position us for the next key/value pair
    if (nextChar == ']')
      throw JSONParseException(
          "Invalid closing bracket while initializing object");
    else if (nextChar == ',') {
      skipWhiteSpace(istr);
      // Check to see if another key/value pair really follows the comma
      // (because if one doesn't, the parser will get screwed up and may not
      // actually detect the problem).
      if (istr.peek() != '"') {
        throw JSONParseException(
            "Invalid comma (no key/value pair following it)");
      }
    }
  }
}
Esempio n. 20
0
bool isbadinput(istream& in) {
	if (in.fail()) {
		cout << "Bad input\n";
		in.clear();
		in.ignore();
		return true;
	}
	return false;
}
/*跳過stream中的換行字元序列的函式*/
short skipEOLsequence(istream& file_stream)
{
  /*用來測試的字元*/
  char test;

  /*guess first character, may be '\r'(MS-DOS later or MAC) or '\n'(Unix)*/
  test = file_stream.peek();

  switch(test){
  case '\n':
    /*if is Unix...eat it and done*/
#ifdef DEBUG
    cout << DEBUG_TAG << "吃掉[LF]" << endl;
#endif
    file_stream.ignore(1);
    /*return Unix*/
    return 1;
    break;
  case '\r':
    /*maybe MS-DOS or Mac...ignore it and peek next*/
    file_stream.ignore(1);
    test = file_stream.peek();
    if(test == '\n'){
#ifdef DEBUG
      cout << DEBUG_TAG << "吃掉[CR][LF]" << endl;
#endif
      file_stream.ignore(1);
      /*return Windows*/
      return 2;
    }
    /*return Mac*/
#ifdef DEBUG
    cout << DEBUG_TAG << "吃掉[CR]" << endl;
#endif
    return 3;
    break;
  default:
    /*shouldn't be EOL else...*/
    return -1;
    break;
  }

}
Esempio n. 22
0
//------------------------------------------------------------------------------------------------------------------------------------------
///
bool SyncRecordManager::istreamSkipPastEOL( istream &is, int howMany )
{
	int err = 0;
	for( int i = 0 ; i < howMany ; ++i ) if( !is.eof() && is.good() ) is.ignore( numeric_limits<streamsize>::max(), '\n' ); else ++err;
	if( err ){
		cerr << "SyncRecordManager::istreamSkipPastEOL(): tried to skip past " << howMany << " line ends but encountered " << err << " errors" << endl;
		return false;
	}
	return true;
}
//process the input stream from the file
void MeshImporter::readStream(istream& is) {
  char str[256];
  for (;is;) {
    is >> ws;
    is.get(str,sizeof(str));
    if (!is) break;
    is.ignore(9999,'\n');
    readLine(str);
  }
}
void
SCCircuitDocument::ReadFile
	(
	istream& input
	)
{
	assert( itsExprList->IsEmpty() && itsPlotList->IsEmpty() );

	input.ignore(kDataFileSignatureLength);

	JFileVersion vers;
	input >> vers;
	assert( vers <= kCurrentMainFileVersion );

	JString netlistText;
	input >> netlistText;
	itsNetlistText->SetText(netlistText);

	delete itsVarList;
	delete itsCircuit;

	itsCircuit = new SCCircuit(input, vers);
	assert( itsCircuit != NULL );

	itsVarList = new SCCircuitVarList(input, vers);
	assert( itsVarList != NULL );

	ListenTo(itsVarList);
	itsVarListDir->SetVarList(itsVarList);

	(GetWindow())->ReadGeometry(input);
	itsVarListDir->ReadSetup(input, vers);

	itsIgnoreNewDirectorFlag = kJTrue;

	JSize exprCount;
	input >> exprCount;

	for (JIndex i=1; i<=exprCount; i++)
		{
		SCDirectorBase* dir = SCDirectorBase::StreamIn(input, vers, this);
		dir->Activate();
		}

	if (vers >= 1)
		{
		JSize plotCount;
		input >> plotCount;

		for (JIndex i=1; i<=plotCount; i++)
			{
			SCPlotDirector* dir = new SCPlotDirector(input, vers, this);
			dir->Activate();
			}
		}
Esempio n. 25
0
void read_var_(istream& sf, int& fl, double& var, double* same_var, int& i)
{
  i = 0;
  double tmp = HUGE_VAL;
  sf >> ws;
  if (sf.peek() == '*')
  {
    fl = series::fixed;
    sf.ignore();
  }
  else if (sf.peek() == '#')
  {
    fl = series::same;
    sf.ignore();
    if (isdigit(sf.peek()))
    {
      sf >> i;
      if (i >= nvar) i = 0;
      sf.clear();
    }
Esempio n. 26
0
//Read the contents of a poll(gender, age, year, studies)
//Receives as parameter the stream from which it reads
Poll read_poll(istream& list_students) {
  char current_studies[SIZE];
  Poll current_poll;
  
  //Set gender as 1 if it is male and 0 otherwise
  current_poll.gender = (list_students.get() == 'M' ? 1 : 0);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.age;
  list_students.ignore(1); //Skip the ','
  
  list_students.get(current_studies, SIZE, ',');
  current_poll.studies = string(current_studies);
  list_students.ignore(1); //Skip the ','
  
  list_students >> current_poll.year;
  list_students.ignore(1); //Skip the '\n'
  
  return current_poll;
}
Esempio n. 27
0
bool isValidInput(istream& in){
	if(in.fail())
	{
		cout <<"Only numbers are accepted" << endl;
	    in.clear();
	    in.ignore(numeric_limits<streamsize>::max(), '\n'); //skip bad input
	    return false;
	}else
	{
		return true;
	}
}
Esempio n. 28
0
// eats up a comment, stream must start with "/*", eats everything until "*/"
void skip_comment(istream& in) {
    int i = in.get();
    int j = in.get();
    if (i != '/' || j != '*') {
        throw BadInputException("Bad comment start!");
    }
    while (in.good()) {
        in.ignore(numeric_limits<streamsize>::max(), '*'); //ignore everything until next '*'
        i = in.get();
        if (in.good() && i == '/') return; // successfully skipped comment
    }
    throw BadInputException("Incomplete comment!");
}
Esempio n. 29
0
bool readSurvey(istream &stream, std::vector<Question> &qList) {
  int count = 0;
  stream >> count;                      // See how many questions there are
  stream.ignore();                      // Skip past newline
  qList = vector< Question >(count);

  // Parse each question.
  for (unsigned int q = 0; q < qList.size(); q++ ) {
    getline(stream, qList[q].qText);    // Get the text of the question

    count = 0;
    stream >> count;                    // Read number of responses
    stream.ignore();                    // Skip past newline

    // Initialize the response list and populate it.
    qList[q].rList = vector< string >(count);
    for (unsigned int r = 0; r < qList[q].rList.size(); r++)
      getline(stream, qList[q].rList[r]);
  }

  return stream;                        // Return true if stream is still good
}
Esempio n. 30
0
/// Helper func to read a string, whitespace delimited but possibly quoted
string Properties::readString(istream& is)
{
  static const char quote('\"');
  string retval;

  ws(is); // strip leading whitespace

  if (is.peek() == quote)
  {
    is.ignore(); // skip opening quote

    getline(is, retval, quote);

    is.ignore(); // skip closing quote
  }
  else
  {
    is >> retval;
  }

  return retval;
}