Changeset 743 for cpp/frams/param/param.cpp
 Timestamp:
 02/26/18 19:57:44 (5 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

cpp/frams/param/param.cpp
r732 r743 74 74 } 75 75 76 int ParamInterface::getMinMax (int prop, paInt& minumum, paInt& maximum, paInt &def)77 { 78 return getMinMax (type(prop), minumum, maximum, def);79 } 80 81 int ParamInterface::getMinMax (int prop, double& minumum, double& maximum, double& def)82 { 83 return getMinMax (type(prop), minumum, maximum, def);84 } 85 86 int ParamInterface::getMinMax (int prop, int& minumum, int& maximum, SString& def)87 { 88 return getMinMax (type(prop), minumum, maximum, def);89 } 90 91 int ParamInterface::getMinMax (const char* t, paInt& minumum, paInt& maximum, paInt &def)76 int ParamInterface::getMinMaxInt(int prop, paInt& minumum, paInt& maximum, paInt &def) 77 { 78 return getMinMaxIntFromTypeDef(type(prop), minumum, maximum, def); 79 } 80 81 int ParamInterface::getMinMaxDouble(int prop, double& minumum, double& maximum, double& def) 82 { 83 return getMinMaxDoubleFromTypeDef(type(prop), minumum, maximum, def); 84 } 85 86 int ParamInterface::getMinMaxString(int prop, int& minumum, int& maximum, SString& def) 87 { 88 return getMinMaxStringFromTypeDef(type(prop), minumum, maximum, def); 89 } 90 91 int ParamInterface::getMinMaxIntFromTypeDef(const char* t, paInt& minumum, paInt& maximum, paInt &def) 92 92 { 93 93 while (*t) if (*t == ' ') break; else t++; … … 95 95 } 96 96 97 int ParamInterface::getMinMax (const char* t, double& minumum, double& maximum, double& def)97 int ParamInterface::getMinMaxDoubleFromTypeDef(const char* t, double& minumum, double& maximum, double& def) 98 98 { 99 99 while (*t) if (*t == ' ') break; else t++; … … 101 101 } 102 102 103 int ParamInterface::getMinMax (const char* t, int& minumum, int& maximum, SString& def)103 int ParamInterface::getMinMaxStringFromTypeDef(const char* t, int& minumum, int& maximum, SString& def) 104 104 { 105 105 while (*t) if (*t == ' ') break; else t++; … … 154 154 { 155 155 double mn = 0, mx = 0, def = 0; 156 if (getMinMax (t, mn, mx, def) < 3) def = mn;156 if (getMinMaxDoubleFromTypeDef(t, mn, mx, def) < 3) def = mn; 157 157 setDouble(i, def); 158 158 } … … 161 161 { 162 162 paInt mn = 0, mx = 0, def = 0; 163 if (getMinMax (t, mn, mx, def) < 3) def = mn;163 if (getMinMaxIntFromTypeDef(t, mn, mx, def) < 3) def = mn; 164 164 setInt(i, def); 165 165 } … … 168 168 { 169 169 int mn, mx; SString def; 170 getMinMax (t, mn, mx, def);170 getMinMaxStringFromTypeDef(t, mn, mx, def); 171 171 if (*t == 's') 172 172 setString(i, def); … … 191 191 { 192 192 double mn = 0, mx = 0, def = 0; 193 getMinMax (t, mn, mx, def);193 getMinMaxDoubleFromTypeDef(t, mn, mx, def); 194 194 setDouble(i, mn); 195 195 } … … 198 198 { 199 199 paInt mn = 0, mx = 0, def = 0; 200 getMinMax (t, mn, mx, def);200 getMinMaxIntFromTypeDef(t, mn, mx, def); 201 201 setInt(i, mn); 202 202 } 203 203 break; 204 default: set (i, "");204 default: setFromString(i, "", false); 205 205 } 206 206 } … … 214 214 { 215 215 double mn = 0, mx = 0, def = 0; 216 getMinMax (t, mn, mx, def);216 getMinMaxDoubleFromTypeDef(t, mn, mx, def); 217 217 setDouble(i, mx); 218 218 } … … 221 221 { 222 222 paInt mn = 0, mx = 0, def = 0; 223 getMinMax (t, mn, mx, def);223 getMinMaxIntFromTypeDef(t, mn, mx, def); 224 224 setInt(i, mx); 225 225 } 226 226 break; 227 default: set (i, "");227 default: setFromString(i, "", false); 228 228 } 229 229 } … … 549 549 if (options.linenum && (flags(i)&PARAM_LINECOMMENT)) 550 550 s = SString::sprintf("@file %s\n@line %d\n", f>VgetPath(), *options.linenum + 1) + s; 551 set (i, s.c_str());551 setFromString(i, s.c_str(), false); 552 552 if (options.linenum) 553 553 (*options.linenum) += lfcount; … … 555 555 else 556 556 { 557 set (i, p0 + p_len + 1);557 setFromString(i, p0 + p_len + 1, false); 558 558 } 559 559 fields_loaded++; … … 644 644 } 645 645 646 int ParamInterface::setInt (int i, const char* str, bool strict)646 int ParamInterface::setIntFromString(int i, const char* str, bool strict) 647 647 { 648 648 paInt value; … … 650 650 { 651 651 paInt mn, mx, def; 652 if (getMinMax (i, mn, mx, def) >= 3)652 if (getMinMaxInt(i, mn, mx, def) >= 3) 653 653 return setInt(i, def)  PSET_PARSEFAILED; 654 654 else … … 659 659 } 660 660 661 int ParamInterface::setDouble (int i, const char* str)661 int ParamInterface::setDoubleFromString(int i, const char* str) 662 662 { 663 663 double value; … … 665 665 { 666 666 double mn, mx, def; 667 if (getMinMax (i, mn, mx, def) >= 3)667 if (getMinMaxDouble(i, mn, mx, def) >= 3) 668 668 return setDouble(i, def)  PSET_PARSEFAILED; 669 669 else … … 688 688 } 689 689 else 690 return setInt (i, v.getString().c_str());690 return setIntFromString(i, v.getString().c_str(), false); 691 691 } 692 692 case 'f': … … 700 700 } 701 701 else 702 return setDouble (i, v.getString().c_str());702 return setDoubleFromString(i, v.getString().c_str()); 703 703 } 704 704 case 's': { SString t = v.getString(); return setString(i, t); } … … 715 715 } 716 716 717 int ParamInterface::set (int i, const char *v, bool strict)717 int ParamInterface::setFromString(int i, const char *v, bool strict) 718 718 { 719 719 char typ = type(i)[0]; 720 720 switch (typ) 721 721 { 722 case 'd': return setInt (i, v, strict);723 case 'f': return setDouble (i, v);722 case 'd': return setIntFromString(i, v, strict); 723 case 'f': return setDoubleFromString(i, v); 724 724 case 's': { SString t(v); return setString(i, t); } 725 725 case 'x': case 'o': … … 760 760 paInt mn, mx, def; 761 761 int value = getInt(i); 762 if (getMinMax (t, mn, mx, def) >= 2)762 if (getMinMaxIntFromTypeDef(t, mn, mx, def) >= 2) 763 763 { 764 764 if (value > mx) … … 801 801 { 802 802 case 'd': 803 {paInt a, b, c; if (getMinMax (t, a, b, c) == 1) return false; }803 {paInt a, b, c; if (getMinMaxIntFromTypeDef(t, a, b, c) == 1) return false; } 804 804 break; 805 805 case 'f': 806 {double a, b, c; if (getMinMax (t, a, b, c) == 1) return false; }806 {double a, b, c; if (getMinMaxDoubleFromTypeDef(t, a, b, c) == 1) return false; } 807 807 break; 808 808 } … … 810 810 } 811 811 812 SString ParamInterface:: describeType(const char* type)812 SString ParamInterface::friendlyTypeDescrFromTypeDef(const char* type) 813 813 { 814 814 SString t; … … 816 816 { 817 817 case 'd': t += "integer"; 818 {paInt a, b, c; int n = getMinMax (type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %d..%d", a, b); if (n >= 3) t += SString::sprintf(" (default %d)", c); }818 {paInt a, b, c; int n = getMinMaxIntFromTypeDef(type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %d..%d", a, b); if (n >= 3) t += SString::sprintf(" (default %d)", c); } 819 819 break; 820 820 case 'f': t += "float"; 821 {double a, b, c; int n = getMinMax (type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %g..%g", a, b); if (n >= 3) t += SString::sprintf(" (default %g)", c); }821 {double a, b, c; int n = getMinMaxDoubleFromTypeDef(type, a, b, c); if ((n >= 2) && (b >= a)) t += SString::sprintf(" %g..%g", a, b); if (n >= 3) t += SString::sprintf(" (default %g)", c); } 822 822 break; 823 823 case 's': t += "string"; 824 {int a, b; SString c; int n = getMinMax (type, a, b, c); if ((n >= 2) && (b > 0)) t += SString::sprintf(", max %d chars", b); if (n >= 3) t += SString::sprintf(" (default \"%s\")", c.c_str()); }824 {int a, b; SString c; int n = getMinMaxStringFromTypeDef(type, a, b, c); if ((n >= 2) && (b > 0)) t += SString::sprintf(", max %d chars", b); if (n >= 3) t += SString::sprintf(" (default \"%s\")", c.c_str()); } 825 825 break; 826 826 case 'x': t += "untyped value"; break; … … 980 980 paInt mn = 0, mx = 0, de = 0; 981 981 int result = 0; 982 if (getMinMax (pe>type, mn, mx, de) >= 2)982 if (getMinMaxIntFromTypeDef(pe>type, mn, mx, de) >= 2) 983 983 if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking 984 984 { … … 1014 1014 double mn = 0, mx = 0, de = 0; 1015 1015 int result = 0; 1016 if (getMinMax (pe>type, mn, mx, de) >= 2)1016 if (getMinMaxDoubleFromTypeDef(pe>type, mn, mx, de) >= 2) 1017 1017 if (mn <= mx) // else if mn>mx then the min/max constraint makes no sense and there is no checking 1018 1018 { … … 1279 1279 remember = *valstop; 1280 1280 *(char*)valstop = 0; 1281 ret = set (i, value, true);1281 ret = setFromString(i, value, true); 1282 1282 fields_loaded++; 1283 1283 if (ret&(PSET_HITMAX  PSET_HITMIN))
Note: See TracChangeset
for help on using the changeset viewer.