// Function to read the input data values // Use is optional, but should be very helpful in parsing. bool Scene::readvals(stringstream &s, const int numvals, float *values) { for (int i = 0 ; i < numvals ; i++) { s >> values[i]; if (s.fail()) { cout << "Failed reading value " << i << " will skip\n"; return false; } } return true; }
// this statement is different than the get_alllabel becuase this just reads // in a string, it does not not check for the inputted string's value // the use of this occurs in the changeR and find commands string get_label (stringstream &ss){ string character; ss >> character; // this check tells us if an input was read if (ss.fail()) { cout << "Error: missing argument" << endl; return "errrrrrrrrrrrrrrrrrrror"; } return character; }
bool raytr::readvals(stringstream &s, const int numvals, double *values) { for (int i = 0; i < numvals; ++i) { s >> values[i]; if (s.fail()) { cerr << "Failed reading value " << i << " skips this line." << endl; return false; } } return true; }
// this function was created to test if more then the desired amount of inputs // were inputted int get_extra (stringstream &ss){ string i; ss >> i; //checks to see if it read an input if (!(ss.fail())) { cout << "Error: too many arguments" << endl; return 1; } return 0; }
bool stringParse( stringstream &s, const int numvals, string* str ) { for( int i = 0; i < numvals; i++ ) { s>>str[i]; if (s.fail()) { cout << "Failed reading value " << i << " will skip\n"; return false; } } }
bool ReadValues(stringstream & s, const int num, float * values) { for(int i = 0; i < num; i++) { s >> values[i]; if(s.fail()) { cerr << "Failed Reading Values " << i << " Will Skip.\n"; return false; } } return true; }
// function for reading the resistance from the stringstream. While it reads the // DOUBLE it tests 3 various errors that can arrive from the user // I set an arbitrary return of -1 for an error occurrence so my function calls // know if it failed, if not it returns the desired input double get_resistance (stringstream &ss){ double i; ss >> i; // check for invalid number my making sure it was read, and also making sure // if the stored type into the variable matches and also checks to make sure // the input is not a double or if a character follows the integer if ((ss.fail() && !(ss.eof()))){ cout << "Error: argument is not a number" <<endl; return -1; } // checks to see if the resistance was negative else if (i < 0.0){ cout << "Error: invalid resistance (negative)" << endl; return -1; } // this check tells us if an input was read else if (ss.fail()) { cout << "Error: missing argument" << endl; return -1; } return i; }
bool treeTrace( stringstream &ss, vector<int> &T, int currSum ) { if( ss.rdbuf()->in_avail() == 0 ) return false; char leftBracket; ss >> leftBracket; int integer; ss >> integer; bool leftTree; if( ss.fail() ) { ss.clear(); char otherBracket; ss >> otherBracket; return false; }
void ShapeArray::translate (stringstream& linestream) { string name; float xShift, yShift, xShape, yShape; linestream >> xShape >> yShape >> xShift >> yShift; if (linestream.fail()) { cout << "Error: invalid arguments\n"; return; } Shape* shape = findShape (xShape, yShape); if (shape == NULL) { cout << "Error: could not find shape at (" << xShape << "," << yShape << ")" << endl; return; } shape->setXcen (shape->getXcen() + xShift); shape->setYcen (shape->getYcen() + yShift); cout << "Success\n"; }
void ShapeArray::scale (stringstream& linestream) { string name; float scaleFac; linestream >> name >> scaleFac; if (linestream.fail()) { cout << "Error: invalid arguments\n"; return; } if (scaleFac < 0) { cout << "Error: scaling factor must be nonnegative\n"; return; } Shape* shape = findShape (name); if (shape == NULL) { cout << "Error: could not find shape with name " << name << endl; return; } shape->scale (scaleFac); cout << "Success\n"; }