Changeset 743 for cpp/frams/param
- Timestamp:
- 02/26/18 19:57:44 (7 years ago)
- Location:
- cpp/frams/param
- Files:
-
- 2 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)) -
cpp/frams/param/param.h
r720 r743 118 118 ExtValue getById(const char* prop); 119 119 120 int setInt (int i, const char* str, bool strict = false);121 int setDouble (int i, const char* str);120 int setIntFromString(int i, const char* str, bool strict = false); 121 int setDoubleFromString(int i, const char* str); 122 122 virtual int setInt(int, paInt) = 0; ///< set long value, you can only use this for "d" type prop 123 123 virtual int setDouble(int, double) = 0; ///< set double value, you can only use this for "f" type prop … … 128 128 int set(int, const ExtValue &);///< most universal set, can be used for every datatype 129 129 130 int set (int, const char*, bool strict = false); ///< oldstyle set, can convert string to long or double130 int setFromString(int, const char*, bool strict = false); ///< oldstyle set, can convert string to long or double 131 131 132 132 int setIntById(const char* prop, paInt);///< set long value, you can only use this for "d" type prop … … 139 139 /** get valid minimum, maximum and default value for property 'prop' 140 140 @return 0 if min/max/def information is not available */ 141 int getMinMax (int prop, paInt& minumum, paInt& maximum, paInt& def);141 int getMinMaxInt(int prop, paInt& minumum, paInt& maximum, paInt& def); 142 142 /** get valid minimum, maximum and default value for property 'prop' 143 143 @return 0 if min/max/def information is not available */ 144 int getMinMax (int prop, double& minumum, double& maximum, double& def);145 int getMinMax (int prop, int& minumum, int& maximum, SString& def);146 static int getMinMax (const char* type, paInt& minumum, paInt& maximum, paInt& def);147 static int getMinMax (const char* type, double& minumum, double& maximum, double& def);148 static int getMinMax (const char* type, int& minumum, int& maximum, SString& def);144 int getMinMaxDouble(int prop, double& minumum, double& maximum, double& def); 145 int getMinMaxString(int prop, int& minumum, int& maximum, SString& def); 146 static int getMinMaxIntFromTypeDef(const char* type, paInt& minumum, paInt& maximum, paInt& def); 147 static int getMinMaxDoubleFromTypeDef(const char* type, double& minumum, double& maximum, double& def); 148 static int getMinMaxStringFromTypeDef(const char* type, int& minumum, int& maximum, SString& def); 149 149 150 150 virtual void setDefault(); … … 156 156 157 157 /** return the human readable description of the given type */ 158 static SString describeType(const char* type);159 SString describeType(int i) { return describeType(type(i)); }158 static SString friendlyTypeDescrFromTypeDef(const char* type); 159 SString friendlyTypeDescr(int i) { return friendlyTypeDescrFromTypeDef(type(i)); } 160 160 161 161 /** copy all property values from other ParamInterface object */
Note: See TracChangeset
for help on using the changeset viewer.