Changeset 333 for cpp/frams/param
- Timestamp:
- 03/01/15 01:19:56 (10 years ago)
- Location:
- cpp/frams/param
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/multiparamload.cpp
r286 r333 21 21 aborting=false; 22 22 emptyparam.setParamTab(empty_paramtab); 23 linenum=0; 23 24 } 24 25 … … 99 100 Param tmp_param; 100 101 ParamInterface *pi=lastobject.getParamInterface(tmp_param); 101 pi->load(file,true,&aborting );102 pi->load(file,true,&aborting,&linenum); 102 103 if ((status!=Finished) && maybeBreak(AfterObject)) 103 104 break; … … 120 121 continue; 121 122 } 123 linenum++; 122 124 if (buf[0]=='#') 123 125 { … … 245 247 Param tmp_param; 246 248 ParamInterface *pi=o.getParamInterface(tmp_param); 247 pi->load(file,warn_unknown_fields,&aborting );249 pi->load(file,warn_unknown_fields,&aborting,&linenum); 248 250 status=AfterObject; 249 251 return 0; -
cpp/frams/param/multiparamload.h
r286 r333 46 46 Param emptyparam; 47 47 bool aborting; 48 int linenum; 48 49 49 50 void init(); -
cpp/frams/param/param.cpp
r326 r333 37 37 static const char *strchrlimit(const char *t, int ch, const char *limit) 38 38 { 39 if (limit <t) return NULL;40 return (const char*)memchr((const void*)t, ch,limit-t);39 if (limit < t) return NULL; 40 return (const char*)memchr((const void*)t, ch, limit - t); 41 41 } 42 42 … … 392 392 } 393 393 394 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable )394 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable, int *linenum) 395 395 { 396 396 SString buf; … … 402 402 while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf)) 403 403 { 404 if (linenum) (*linenum)++; 404 405 const char* t = (const char*)buf; 405 406 p0 = t; while ((*p0 == ' ') || (*p0 == '\t')) p0++; … … 417 418 SString s; 418 419 czytdotyldy(f, s); 420 int lfcount = 1; 421 const char* tmp = s; 422 while (tmp) 423 if ((tmp = strchr(tmp, '\n'))) 424 { 425 lfcount++; tmp++; 426 } 419 427 removeCR(s); 420 428 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 421 429 unquoteTilde(s); 430 if (linenum && (flags(i)&PARAM_LINECOMMENT)) 431 s = SString::sprintf("@line %d\n", *linenum + 1) + s; 422 432 set(i, (const char*)s); 433 if (linenum) 434 (*linenum) += lfcount; 423 435 } 424 436 else … … 440 452 SString s; 441 453 czytdotyldy(f, s); 454 if (linenum) 455 { 456 const char* tmp = s; 457 int lfcount = 1; 458 while (tmp) 459 if ((tmp = strchr(tmp, '\n'))) 460 { 461 lfcount++; tmp++; 462 } 463 (*linenum) += lfcount; 464 } 442 465 int ch; while ((ch = fgetc(f)) != EOF) if (ch == '\n') break; 443 466 } … … 453 476 switch (*(t=type(i))) 454 477 { 455 456 457 458 459 460 461 462 463 464 465 466 467 468 478 case 'd': 479 { 480 for (i=atol(get(i));i>=0;i--) if (t) t=strchr(t+1,'~'); 481 if (t) 482 { 483 t++; 484 char *t2=strchr(t,'~'); 485 if (!t2) t2=t+strlen(t); 486 SString str; 487 strncpy(str.directWrite(t2-t),t,t2-t); 488 str.endWrite(t2-t); 489 return str; 490 } 491 } 469 492 } 470 493 return get(i); … … 502 525 { 503 526 paInt value; 504 if (!ExtValue::parseInt(str, value,false,true))527 if (!ExtValue::parseInt(str, value, false, true)) 505 528 { 506 529 paInt mn, mx, def; … … 517 540 { 518 541 double value; 519 if (!ExtValue::parseDouble(str, value,true))542 if (!ExtValue::parseDouble(str, value, true)) 520 543 { 521 544 double mn, mx, def; … … 538 561 { 539 562 if (v.type == TObj) 563 { 540 564 FMprintf("ParamInterface", "set", FMLV_WARN, "Getting integer value from object reference (%s)", (const char*)v.getString()); 541 return setInt(i, (const char*)v.getString()); 565 return 0; 566 } 567 else 568 return setInt(i, (const char*)v.getString()); 542 569 } 543 570 case 'f': … … 546 573 { 547 574 if (v.type == TObj) 575 { 548 576 FMprintf("ParamInterface", "set", FMLV_WARN, "Getting floating point value from object reference (%s)", (const char*)v.getString()); 549 return setDouble(i, (const char*)v.getString()); 577 return 0; 578 } 579 else 580 return setDouble(i, (const char*)v.getString()); 550 581 } 551 582 case 's': { SString t = v.getString(); return setString(i, t); } … … 995 1026 996 1027 field_end = strchrlimit(t, ',', end); if (!field_end) field_end = end; 997 next_field =field_end;1028 next_field = field_end; 998 1029 while ((field_end>t) && isblank(field_end[-1])) field_end--; 999 1030 quote = strchrlimit(t, '\"', field_end); -
cpp/frams/param/param.h
r319 r333 32 32 #define PARAM_NOISOLATION 4096 //< don't use proxy object in master/slave interactions 33 33 #define PARAM_DEPRECATED 8192 //< this member is deprecated 34 #define PARAM_LINECOMMENT 16384 //< Param::load() adds "@line ..." comment when loading multiline (internal use) 34 35 35 36 typedef int32_t paInt; … … 160 161 int save(VirtFILE*, const char* altname = NULL, bool force = 0); 161 162 int saveprop(VirtFILE*, int i, const char* p, bool force = 0); 162 int load(VirtFILE*, bool warn_unknown_fields=true,bool *abortable=NULL);///< @return the number of fields loaded163 int load(VirtFILE*, bool warn_unknown_fields = true, bool *abortable = NULL, int *linenum = NULL);///< @return the number of fields loaded 163 164 int load2(const SString &, int &);///< @return the number of fields loaded 164 165 -
cpp/frams/param/paramobj.h
r326 r333 15 15 int numfields; 16 16 Param par; 17 #ifdef _MSC_VER 18 #pragma warning(push) 19 #pragma warning(disable: 4200) //Cannot generate copy-ctor or copy-assignment operator when UDT contains a zero-sized array 20 #endif 17 21 ExtValue fields[0]; 22 #ifdef _MSC_VER 23 #pragma warning(pop) 24 #endif 18 25 ParamObject() { numfields = 0; } 19 26 ~ParamObject(); … … 21 28 void* operator new(size_t s, int numfields){ return ::operator new(s + sizeof(ExtValue)*numfields); } 22 29 void* operator new(size_t s){ return ::operator new(s); } 30 void operator delete(void* ptr, int numfields) { ::operator delete(ptr); } 31 void operator delete(void* ptr) { ::operator delete(ptr); } 23 32 ParamObject *clone(); 24 33 static void p_new(void* obj, ExtValue *args, ExtValue *ret);
Note: See TracChangeset
for help on using the changeset viewer.