bool Point3Dot::load(istream &in){ coords.resize(3); int start = in.tellg(); for(int i = 0; i < 3; i++){ in >> coords[i]; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } } in >> theta; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } in >> phi; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } int typeInt; in >> typeInt; type = (Type)typeInt; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } return true; }
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; } } }
// clears the file input buffer void fileHandler::flushinput(istream & is) { is.clear(); char nextChar; while( (nextChar = is.get()) != '\n' && nextChar != EOF) { } is.clear(); }
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; }
int FixedLengthBuffer::read(istream& stream){ int recAddr = stream.tellg(); stream.clear(); this->clear(); this->packing = 0; //FALSE stream.read(this->buffer, this->bufferSize); if(!stream.good()){ stream.clear(); return recAddr; } return recAddr; }
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; }
// no skip of WS const string ReadComplexElement(istream& is) { SkipWS( is); string buf; char c = is.get(); if ( (is.rdstate() & ifstream::failbit ) != 0 ) { if ( (is.rdstate() & ifstream::eofbit ) != 0 ) throw GDLIOException( "End of file encountered. "+ StreamInfo( &is)); if ( (is.rdstate() & ifstream::badbit ) != 0 ) throw GDLIOException( "Error reading stream. "+ StreamInfo( &is)); is.clear(); return buf; } bool brace = (c == '('); if( !brace) { is.unget(); return ReadElement( is); } buf.push_back( c); for(;;) { c = is.get(); if ( (is.rdstate() & ifstream::failbit ) != 0 ) { if ( (is.rdstate() & ifstream::badbit ) != 0 ) throw GDLIOException( "Error reading line. "+ StreamInfo( &is)); is.clear(); return buf; } if( c == '\n') return buf; buf.push_back( c); if( c == ')') return buf; } }
// EOFまたは終了インジゲータが検出されるまでistからvに整数を読み取る void fill_vector(istream& ist, vector<int>& v, char terminator){ int i = 0; while(ist >> i) v.push_back(i); if(ist.eof()) return; // OK: EOFが検出された if(ist.fail()){ // できるだけ後始末をし、問題を報告する ist.clear(); // ストリームの状態をクリアし、終了インジゲータを調査できるようにする char c; ist >> c; // 文字を読み取る(終了インジゲータでありますように) if(c != terminator){ // 予想外の文字 ist.unget(); ist.clear(ios_base::failbit); // 状態をfailに設定する } }
void Point::read(istream& is) { char ch; is >> ch; if (is.fail()) return; if (ch != '(') { is.clear(ios::failbit); return; } is >> _x; is >> ch; if (is.fail()) return; if (ch != ',') { is.clear(ios::failbit); return; } is >> _y; is >> ch; if (is.fail()) return; if (ch != ')') { is.clear(ios::failbit); return; } }
int GetString(string&strFound,istream&ifs) { strFound = ""; DFAEdge*ptDfa = &dfa; set<DFAEdge>::iterator edgeIt; int iChr; //skip leading WS while (true) { iChr=ifs.peek(); if (iChr == char_traits<char>::eof()) { ifs.clear(); break; } switch (iChr) { case '\r': case '\n': case '\t': case ' ': ifs.get(); continue; } break; } while (true) { char ch; if ((iChr=ifs.peek()) == char_traits<char>::eof()) { ifs.clear(); ch = '\0'; } else { ch = (char)iChr; } edgeIt = ptDfa->edges.find(ch); if (edgeIt == ptDfa->edges.end()) { return ptDfa->id; } strFound += ch; ifs.get(); ptDfa = &(*edgeIt); } return 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; }
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(); } }
//--------------------------------------------------------------------------- unique_ptr<Expression> ExpressionParser::parseSingleExpression(istream& input, ExpressionType lastExpression, Environment& environment) { // read harriet::skipWhiteSpace(input); char a = input.get(); if(!input.good()) return nullptr; // other single letter operators if(a == '(') return make_unique<OpeningPharentesis>(); if(a == ')') return make_unique<ClosingPharentesis>(); if(a == '+') return make_unique<PlusOperator>(); if(a == '-') { if(lastExpression==ExpressionType::TBinaryOperator || lastExpression==ExpressionType::TUnaryOperator || lastExpression==ExpressionType::TOpeningPharentesis) return make_unique<UnaryMinusOperator>(); else return make_unique<MinusOperator>(); } if(a == '*') return make_unique<MultiplicationOperator>(); if(a == '/') return make_unique<DivisionOperator>(); if(a == '%') return make_unique<ModuloOperator>(); if(a == '^') return make_unique<ExponentiationOperator>(); if(a == '&') return make_unique<AndOperator>(); if(a == '|') return make_unique<OrOperator>(); if(a=='>' && input.peek()!='=') return make_unique<GreaterOperator>(); if(a=='<' && input.peek()!='=') return make_unique<LessOperator>(); if(a=='!' && input.peek()!='=') return make_unique<NotOperator>(); if(a=='=' && input.peek()!='=') return make_unique<AssignmentOperator>(); // check for string char b = input.get(); if(a=='"') { string result; while(b!='"' && a!='\\') { if(!input.good()) throw harriet::Exception{"unterminated string expression"}; result.push_back(b); a = b; b = input.get(); } return make_unique<StringValue>(result); } // check for two signed letters if(input.good()) { if(a=='=' && b=='=') return make_unique<EqualOperator>(); if(a=='>' && b=='=') return make_unique<GreaterEqualOperator>(); if(a=='<' && b=='=') return make_unique<LessEqualOperator>(); if(a=='!' && b=='=') return make_unique<NotEqualOperator>(); input.unget(); } else { input.clear(); } // check for a number input.unget(); if(isdigit(a)) { int32_t intNum; input >> intNum; if(input.peek()=='.' && input.good()) { float floatNum; input >> floatNum; return make_unique<FloatValue>(floatNum+intNum); } else { return make_unique<IntegerValue>(intNum);
void Frond::load(FrondGroup *group, istream &in) { string line; float x, y; in >> x; in >> y; move(coord_t(x, y)); setEnable(true); for(;;) { int id = -1; in >> id; if (!in.good() || id == -1) { in.clear(); break; } Frond *p = group->getFrond(id); if (p == NULL) { p = new Frond(id, NULL); group->addFrond(p); } addPeer(p); } }
/* * 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; }
void end_of_loop(istream& ist, char term, const string& message) { if(ist.fail()) { ist.clear(); char ch; if(ist >> ch && ch==term) return; error(message); }
void ClearInputStream(istream &s) // Function used to clear the input stream. { char c; s.clear(); while(s.get(c) && c != '\n') { ; } }
bool _check_idlabel_title(istream &s, string &title) { title.clear(); if (!s.good()) return false; bool hv = false; while (1) { string line0; getline(s, line0); if (!allSpace(line0)) { string line = removeLeadSpace2(line0); if (line.length() <= 1 || !( (line.front() == '"' && line.back() == '"') || (line.front() == '\'' && line.back() == '\'') || (line.front() == '(' && line.back() == ')') )) { if (!s.eof()) s.putback('\n'); s.clear(); strputback(s, line0); return hv; } title = line.substr(1, line.length() - 2); return true; } if (s.eof() || hv) break; hv = true; } return true; }
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; }
/* * 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; }
void read_delimited(istream& is, string& s) /* PURPOSE: Read a "" delimited string (including spaces) from a stream. Embedded " and \ are quoted by \ */ { char ch; s = ""; is >> ch; if (ch != '"') { is.clear(ios::failbit); return; } const int BUFSIZE = 80; char buffer[BUFSIZE]; int i = 0; for(;;) { ch = is.get(); if (is.fail()) return; // expect closing " if (ch == '"') { buffer[i] = 0; s += buffer; return; } if (ch == '\\') { ch = is.get(); // \ is escape for embedded " if (is.fail()) return; // expect escapee } buffer[i] = ch; i++; if (i >= BUFSIZE - 1) { buffer[i] = 0; s += buffer; i = 0; } } }
void ClearInputStream(istream &s) // Used to clear istream { char c; s.clear(); while(s.get(c) && c != '\n') { ; } }
void SkipWS( istream& is) { if( is.eof()) throw GDLIOException( "End of file encountered. "+ StreamInfo( &is)); char c; do { c = is.get(); if ( (is.rdstate() & ifstream::failbit ) != 0 ) { if ( (is.rdstate() & ifstream::eofbit ) != 0 ) throw GDLIOException( "End of file encountered. "+ StreamInfo( &is)); if ( (is.rdstate() & ifstream::badbit ) != 0 ) throw GDLIOException( "Error reading stream. "+ StreamInfo( &is)); is.clear(); return ; } } while( c == ' ' || c == '\t' || c == '\n'); is.unget(); }
ChrString _Bitsxstr(istream& Is_, Subscript Num_) { Boolean Changed_ = FALSE; ChrString Str_('\0', Num_); if (Num_ == PTRDIFFT_MAX) --Num_; if (_Ipfx(Is_)) { int ch; while (0 < Num_ && (ch = Is_.rdbuf()->sbumpc()) != EOF) if (ch != '0' && ch != '1') { Is_.rdbuf()->sputbackc(ch); break; } else { Str_ += ch; Changed_ = TRUE; --Num_; } } if (!Changed_) Is_.clear(ios::failbit); if (!_Ipfx(Is_)) THROW (FallibleBase::IOFailureErr()); return Str_; }
void fill_vector(istream& ist, vector<int>& v, char terminator) // read integers from ist into v until we reach eof() or terminator { int i = 0; while (ist >> i) v.push_back(i); if (ist.eof()) return; // fine: we found the end of file // not good() and not bad() and not eof(), ist must be fail() ist.clear(); // clear stream state char c; ist>>c; // read a character, hopefully terminator if (c != terminator) { // ouch: not the terminator, so we must fail ist.unget(); // maybe my caller can use that character ist.clear(ios_base::failbit); // set the state to fail() } }
void clean_up_stream(istream &in) { in.clear(); //Reset the stream error flags, i.e. put stream in back to good state //Extract the non-valid input from the stream’s buffer string trash; getline(in,trash); }
static double read_double (istream &is) { is.clear(); double v; is >> v; if (is.fail()) throw SpecialException("number expected"); return v; }
/** * Parses the given input stream and returns a DOM Document. * A NULL pointer will be returned if errors occurred */ nsresult txDriver::parse(istream& aInputStream, const nsAString& aUri) { mErrorString.Truncate(); if (!aInputStream) { mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered."); return NS_ERROR_FAILURE; } static const XML_Memory_Handling_Suite memsuite = { (void *(*)(size_t))PR_Malloc, (void *(*)(void *, size_t))PR_Realloc, PR_Free }; static const PRUnichar expatSeparator = kExpatSeparatorChar; mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator); if (!mExpatParser) { return NS_ERROR_OUT_OF_MEMORY; } XML_SetReturnNSTriplet(mExpatParser, XML_TRUE); XML_SetUserData(mExpatParser, this); XML_SetElementHandler(mExpatParser, startElement, endElement); XML_SetCharacterDataHandler(mExpatParser, charData); #ifdef XML_DTD XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS); #endif XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler); XML_SetExternalEntityRefHandlerArg(mExpatParser, this); XML_SetBase(mExpatParser, (const XML_Char*)(PromiseFlatString(aUri).get())); const int bufferSize = 1024; char buf[bufferSize]; PRBool done; int success; mRV = NS_OK; do { aInputStream.read(buf, bufferSize); done = aInputStream.eof(); success = XML_Parse(mExpatParser, buf, aInputStream.gcount(), done); // mRV is set in onDoneCompiling in case of an error if (!success || NS_FAILED(mRV)) { createErrorString(); done = MB_TRUE; } } while (!done); aInputStream.clear(); // clean up XML_ParserFree(mExpatParser); mCompiler->doneLoading(); if (!success) { return NS_ERROR_FAILURE; } return mRV; }
bool isbadinput(istream& in) { if (in.fail()) { cout << "Bad input\n"; in.clear(); in.ignore(); return true; } return false; }
bool Point2Do::load(istream &in){ coords.resize(3); int start = in.tellg(); for(int i = 0; i < 2; i++){ in >> coords[i]; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } } in >> theta; if(in.fail()){ in.clear(); in.seekg(start+1); //????????? Why that one return false; } return true; }