int CinReader::readInt (bool userLimit, int lower, int upper) { string input = ""; string msg = ""; getline (cin, input); input = stripCommas(input); if (userLimit) { while (!testIntInput(input, msg, lower, upper)) { cout << "ERROR: " << msg << "\n"; cout << "Reenter number [" << lower << " to " << upper << "] "; getline (cin, input); } } else { while (!testIntInput(input, msg)) { cout << "ERROR: " << msg << "\n"; cout << "Reenter: "; getline (cin, input); } } return (atoi(input.c_str())); }
Color colorFromString(string s) { static Color s_cLastCol; Color c; if(s == "random_pastel") //Some random pastel color (good for parasprites) { float h, s, v; h = randFloat(0.0, 360.0); s = randFloat(40.0, 100.0); v = 100.0; c = HsvToRgb(h,s,v); c.r /= 100; c.g /= 100; c.b /= 100; s_cLastCol = c; return c; } else if(s == "last") //Last color we got from this function return s_cLastCol; s = stripCommas(s); //Now, parse istringstream iss(s); int r, g, b, a; if(iss >> r >> g >> b) { if(!(iss >> a)) c.from256(r,g,b); else c.from256(r,g,b,a); }
Point pointFromString(string s) { s = stripCommas(s); //Now, parse istringstream iss(s); Point pt; if(!(iss >> pt.x >> pt.y)) pt.SetZero(); return pt; }
Rect rectFromString(string s) { s = stripCommas(s); //Now, parse istringstream iss(s); Rect rc; if(!(iss >> rc.left >> rc.top >> rc.right >> rc.bottom)) rc.set(0,0,0,0); return rc; }
void parsePosition(char *origPos, char **chr, int *s, int *e) /** Parse the coordinate information from the user text */ { /* trying to parse something that looks like chrN:10000-20000 */ char *pos = cloneString(origPos); char *tmp = NULL; char *tmp2 = NULL; tmp = strstr(pos, ":"); if(tmp == NULL) posAbort(origPos); *tmp='\0'; tmp++; *chr = cloneString(pos); tmp2 = strstr(tmp, "-"); if(tmp2 == NULL) posAbort(origPos); *tmp2 = '\0'; tmp2++; *s = atoi(stripCommas(tmp)); *e = atoi(stripCommas(tmp2)); }
float CinReader::readFloat () { string input = ""; getline(cin, input); input = stripCommas(input); while (!testDoubleInput(input)) { cout << "Input is not a float\n"; cout << "Reenter: "; getline(cin, input); } return (atof(input.c_str())); }