Changeset 312
- Timestamp:
- 01/26/15 09:18:39 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/param.cpp
r310 r312 52 52 && (*type(i) != 'p')) 53 53 { 54 55 56 57 54 j = src->findId(id(i)); 55 if (j < 0) continue; 56 src->get(j, v); 57 set(i, v); 58 58 } 59 59 } … … 67 67 && (*type(i) != 'p')) 68 68 { 69 70 69 src->get(i, v); 70 set(i, v); 71 71 } 72 72 } … … 90 90 const char* t = type(prop) + 1; 91 91 while (*t) if (*t == ' ') break; else t++; 92 int ret =sscanf(t, "%d %d", &minumum, &maximum);93 def =SString::empty();94 if (ret ==2)95 96 while (*t ==' ') t++;97 for (int skip_fields=2;skip_fields>0;skip_fields--)98 92 int ret = sscanf(t, "%d %d", &minumum, &maximum); 93 def = SString::empty(); 94 if (ret == 2) 95 { 96 while (*t == ' ') t++; 97 for (int skip_fields = 2; skip_fields > 0; skip_fields--) 98 { 99 99 while (*t) if (*t == ' ') break; else t++; 100 while (*t ==' ') t++;101 100 while (*t == ' ') t++; 101 } 102 102 if (*t) 103 104 const char* end =strchr(t,'~');103 { 104 const char* end = strchr(t, '~'); 105 105 if (!end) 106 end =t+strlen(t);107 while ((end >t)&&(end[-1]==' ')) end--;108 def =SString(t,end-t);109 106 end = t + strlen(t); 107 while ((end > t) && (end[-1] == ' ')) end--; 108 def = SString(t, end - t); 109 } 110 110 return 3; 111 111 } 112 112 else 113 113 return ret; … … 151 151 } 152 152 break; 153 154 { 155 int a, b; SString c;156 getMinMax(i, a,b,c);157 if (*t =='s')158 setString(i, c);153 case 's': case 'x': 154 { 155 int a, b; SString c; 156 getMinMax(i, a, b, c); 157 if (*t == 's') 158 setString(i, c); 159 159 else 160 { if (c.len()>0) setExtValue(i,ExtValue(c)); else setExtValue(i,ExtValue::empty()); } 161 } 160 { 161 if (c.len() > 0) setExtValue(i, ExtValue(c)); else setExtValue(i, ExtValue::empty()); 162 } 163 } 162 164 break; 163 165 case 'o': 164 setObject(i, ExtObject::empty());166 setObject(i, ExtObject::empty()); 165 167 break; 166 168 } … … 214 216 215 217 SString ParamInterface::getStringById(const char*prop) 216 {int i=findId(prop); if (i>=0) return getString(i); else return SString();} 218 { 219 int i = findId(prop); if (i >= 0) return getString(i); else return SString(); 220 } 217 221 paInt ParamInterface::getIntById(const char*prop) 218 {int i=findId(prop); if (i>=0) return getInt(i); else return 0;} 222 { 223 int i = findId(prop); if (i >= 0) return getInt(i); else return 0; 224 } 219 225 double ParamInterface::getDoubleById(const char*prop) 220 {int i=findId(prop); if (i>=0) return getDouble(i); else return 0;} 226 { 227 int i = findId(prop); if (i >= 0) return getDouble(i); else return 0; 228 } 221 229 ExtObject ParamInterface::getObjectById(const char*prop) 222 {int i=findId(prop); if (i>=0) return getObject(i); else return ExtObject();} 230 { 231 int i = findId(prop); if (i >= 0) return getObject(i); else return ExtObject(); 232 } 223 233 ExtValue ParamInterface::getExtValueById(const char*prop) 224 {int i=findId(prop); if (i>=0) return getExtValue(i); else return ExtValue();} 225 226 int ParamInterface::setIntById(const char* prop,paInt v) 227 {int i=findId(prop); if (i>=0) return setInt(i,v); else return PSET_NOPROPERTY;} 228 int ParamInterface::setDoubleById(const char* prop,double v) 229 {int i=findId(prop); if (i>=0) return setDouble(i,v); else return PSET_NOPROPERTY;} 230 int ParamInterface::setStringById(const char* prop,const SString &v) 231 {int i=findId(prop); if (i>=0) return setString(i,v); else return PSET_NOPROPERTY;} 232 int ParamInterface::setObjectById(const char* prop,const ExtObject &v) 233 {int i=findId(prop); if (i>=0) return setObject(i,v); else return PSET_NOPROPERTY;} 234 int ParamInterface::setExtValueById(const char* prop,const ExtValue &v) 235 {int i=findId(prop); if (i>=0) return setExtValue(i,v); else return PSET_NOPROPERTY;} 236 int ParamInterface::setById(const char* prop,const ExtValue &v) 237 {int i=findId(prop); if (i>=0) return set(i,v); else return PSET_NOPROPERTY;} 234 { 235 int i = findId(prop); if (i >= 0) return getExtValue(i); else return ExtValue(); 236 } 237 238 int ParamInterface::setIntById(const char* prop, paInt v) 239 { 240 int i = findId(prop); if (i >= 0) return setInt(i, v); else return PSET_NOPROPERTY; 241 } 242 int ParamInterface::setDoubleById(const char* prop, double v) 243 { 244 int i = findId(prop); if (i >= 0) return setDouble(i, v); else return PSET_NOPROPERTY; 245 } 246 int ParamInterface::setStringById(const char* prop, const SString &v) 247 { 248 int i = findId(prop); if (i >= 0) return setString(i, v); else return PSET_NOPROPERTY; 249 } 250 int ParamInterface::setObjectById(const char* prop, const ExtObject &v) 251 { 252 int i = findId(prop); if (i >= 0) return setObject(i, v); else return PSET_NOPROPERTY; 253 } 254 int ParamInterface::setExtValueById(const char* prop, const ExtValue &v) 255 { 256 int i = findId(prop); if (i >= 0) return setExtValue(i, v); else return PSET_NOPROPERTY; 257 } 258 int ParamInterface::setById(const char* prop, const ExtValue &v) 259 { 260 int i = findId(prop); if (i >= 0) return set(i, v); else return PSET_NOPROPERTY; 261 } 238 262 239 263 int ParamInterface::save(VirtFILE* f, const char* altname, bool force) … … 270 294 err |= (fputs(p, f) == EOF); fputc(':', f); 271 295 cr = 0; 272 if ((*typ == 'x') ||(*typ == 'o'))296 if ((*typ == 'x') || (*typ == 'o')) 273 297 { 274 298 ExtValue ex; … … 332 356 if (!((fl = flags(i))&PARAM_DONTSAVE)) 333 357 { 334 335 336 337 338 358 if (defdata && isequal(i, defdata)) 359 needlabel = 1; 360 else 361 { 362 if (!first) t += ", "; 339 363 #ifndef SAVE_ALL_NAMES 340 364 #ifdef SAVE_SELECTED_NAMES 341 365 if (needlabel || all_names || !(fl & PARAM_CANOMITNAME)) 342 366 #else 343 367 if (needlabel) 344 368 #endif 345 369 #endif 370 { 371 t += p; t += "="; needlabel = 0; 372 } 373 if (type(i)[0] == 's') 374 { // string - special case 375 SString str = getString(i); 376 if (strContainsOneOf(str, ", \\\n\r\t\"")) 346 377 { 347 t += p; t += "="; needlabel = 0; 348 } 349 if (type(i)[0] == 's') 350 { // string - special case 351 SString str = getString(i); 352 if (strContainsOneOf(str, ", \\\n\r\t\"")) 353 { 354 t += "\""; 355 sstringQuote(str); 356 t += str; 357 t += "\""; 358 } 359 else 360 t += str; 378 t += "\""; 379 sstringQuote(str); 380 t += str; 381 t += "\""; 361 382 } 362 383 else 363 t += get(i); 364 first = 0; 384 t += str; 365 385 } 386 else 387 t += get(i); 388 first = 0; 389 } 366 390 } 367 391 if (addcr) … … 370 394 } 371 395 372 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields,bool *abortable)396 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable) 373 397 { 374 398 SString buf; … … 378 402 bool loaded; 379 403 int fields_loaded = 0; 380 while ( ((!abortable)||(!*abortable)) && loadSStringLine(f, buf))404 while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf)) 381 405 { 382 406 const char* t = (const char*)buf; 383 407 p0 = t; while ((*p0 == ' ') || (*p0 == '\t')) p0++; 384 408 if (!*p0) break; 385 if (p0[0] =='#') continue;409 if (p0[0] == '#') continue; 386 410 p = strchr(p0, ':'); if (!p) continue; 387 411 p_len = (int)(p - p0); … … 389 413 if (p_len && ((i = findIdn(p0, p_len)) >= 0)) 390 414 { 391 if (!(flags(i)&PARAM_DONTLOAD)) 392 { 393 if (p0[p_len + 1] == '~') 415 if (!(flags(i)&PARAM_DONTLOAD)) 394 416 { 395 SString s; 396 czytdotyldy(f, s); 397 removeCR(s); 398 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 399 unquoteTilde(s); 400 set(i, (const char*)s); 417 if (p0[p_len + 1] == '~') 418 { 419 SString s; 420 czytdotyldy(f, s); 421 removeCR(s); 422 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 423 unquoteTilde(s); 424 set(i, (const char*)s); 425 } 426 else 427 { 428 set(i, p0 + p_len + 1); 429 } 430 fields_loaded++; 431 loaded = true; 401 432 } 402 else403 {404 set(i, p0 + p_len + 1);405 }406 fields_loaded++;407 loaded = true;408 }409 433 } 410 434 else if (warn_unknown_fields) 411 412 SString name(p0, p_len);413 FMprintf("ParamInterface", "load",FMLV_WARN,"Unknown property '%s' while reading object '%s' (ignored)",(const char*)name,getName());414 435 { 436 SString name(p0, p_len); 437 FMprintf("ParamInterface", "load", FMLV_WARN, "Unknown property '%s' while reading object '%s' (ignored)", (const char*)name, getName()); 438 } 415 439 416 440 if ((!loaded) && (p0[p_len + 1] == '~')) … … 430 454 char *t; 431 455 switch (*(t=type(i))) 432 456 { 433 457 case 'd': 434 458 { 435 for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~');436 if (t)437 { 438 t++;439 char *t2=strchr(t,'~');440 if (!t2) t2=t+strlen(t);441 SString str;442 strncpy(str.directWrite(t2-t),t,t2-t);443 str.endWrite(t2-t);444 return str;445 } 446 } 447 459 for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~'); 460 if (t) 461 { 462 t++; 463 char *t2=strchr(t,'~'); 464 if (!t2) t2=t+strlen(t); 465 SString str; 466 strncpy(str.directWrite(t2-t),t,t2-t); 467 str.endWrite(t2-t); 468 return str; 469 } 470 } 471 } 448 472 return get(i); 449 473 } … … 543 567 int ParamInterface::set(int i, const char *v) 544 568 { 545 char typ =type(i)[0];569 char typ = type(i)[0]; 546 570 switch (typ) 547 571 { … … 567 591 e.setString(SString(v)); 568 592 } 569 if (typ =='x')593 if (typ == 'x') 570 594 return setExtValue(i, e); 571 595 else … … 581 605 if ((*(t = type(i))) == 'd') 582 606 { 583 paInt a, b,c;584 int value =getInt(i);585 if (getMinMax(i, a,b,c)>=2)586 587 if (value >b)607 paInt a, b, c; 608 int value = getInt(i); 609 if (getMinMax(i, a, b, c) >= 2) 610 { 611 if (value > b) 588 612 return get(i); 589 value -=a;590 591 if (value <0) return get(i);613 value -= a; 614 } 615 if (value < 0) return get(i); 592 616 for (; value >= 0; value--) if (t) t = strchr(t + 1, '~'); 593 617 if (t) … … 621 645 void SimpleAbstractParam::sanityCheck(int i) 622 646 { 623 ParamEntry *pe=entry(i);624 625 const char* t=pe->type;626 const char* err=NULL;627 628 if (*t=='p')629 { 630 if (pe->fun1==NULL)631 err="no procedure defined";632 } 633 else634 { 635 if (!(pe->flags & PARAM_READONLY))647 ParamEntry *pe=entry(i); 648 649 const char* t=pe->type; 650 const char* err=NULL; 651 652 if (*t=='p') 653 { 654 if (pe->fun1==NULL) 655 err="no procedure defined"; 656 } 657 else 658 { 659 if (!(pe->flags & PARAM_READONLY)) 636 660 { //write access 637 if ((pe->fun2==NULL)&&(pe->offset==PARAM_ILLEGAL_OFFSET))638 err="no field defined (GETONLY without PARAM_READONLY?)";639 } 640 } 641 if (err!=NULL)642 FMprintf("SimpleAbstractParam","sanityCheck", FMLV_ERROR,643 661 if ((pe->fun2==NULL)&&(pe->offset==PARAM_ILLEGAL_OFFSET)) 662 err="no field defined (GETONLY without PARAM_READONLY?)"; 663 } 664 } 665 if (err!=NULL) 666 FMprintf("SimpleAbstractParam","sanityCheck", FMLV_ERROR, 667 "Invalid ParamEntry for %s.%s (%s)", getName(), pe->id, err); 644 668 } 645 669 #endif … … 761 785 if (a <= b) // if max<min then the min/max constraint check is not supported 762 786 { 763 if (x<a) { x = a; result = PSET_HITMIN; }764 else if (x>b) { x = b; result = PSET_HITMAX; }787 if (x < a) { x = a; result = PSET_HITMIN; } 788 else if (x > b) { x = b; result = PSET_HITMAX; } 765 789 } 766 790 … … 797 821 if (a <= b) // if max<min then the min/max constraint check is not supported 798 822 { 799 if (x<a) { x = a; result = PSET_HITMIN; }800 else if (x>b) { x = b; result = PSET_HITMAX; }823 if (x < a) { x = a; result = PSET_HITMIN; } 824 else if (x > b) { x = b; result = PSET_HITMAX; } 801 825 } 802 826 … … 973 997 { 974 998 // processing a single field 975 while (strchr(" \n\r\t", *t)) if (t <end) t++; else return fields_loaded;999 while (strchr(" \n\r\t", *t)) if (t < end) t++; else return fields_loaded; 976 1000 977 1001 comma_sign = strchrlimit(t, ',', end); if (!comma_sign) comma_sign = end; … … 980 1004 { 981 1005 quote2 = skipQuoteString(quote + 1, end); 982 if (quote2 >comma_sign)1006 if (quote2 > comma_sign) 983 1007 { 984 1008 comma_sign = strchrlimit(quote2 + 1, ',', end); … … 1003 1027 i = tmpi; 1004 1028 if (tmpi < 0) 1005 1006 SString name(t, (int)(equals_sign - t));1007 FMprintf("Param", "load2", FMLV_WARN, "Unknown property '%s' while reading object '%s' (ignored)", (const char*)name,getName());1008 1029 { 1030 SString name(t, (int)(equals_sign - t)); 1031 FMprintf("Param", "load2", FMLV_WARN, "Unknown property '%s' while reading object '%s' (ignored)", (const char*)name, getName()); 1032 } 1009 1033 t = equals_sign + 1; // t=value 1010 1034 } … … 1015 1039 #endif 1016 1040 { 1017 1018 1041 FMprintf("Param", "load2", FMLV_WARN, "Missing property name in '%s' (assuming '%s')", 1042 getName(), id(i) ? id(i) : "unknown property?"); 1019 1043 } 1020 1044 #endif
Note: See TracChangeset
for help on using the changeset viewer.