Changeset 144
- Timestamp:
- 02/26/14 20:04:49 (11 years ago)
- Location:
- cpp/frams
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/param.cpp
r124 r144 331 331 } 332 332 333 voidParamInterface::load(VirtFILE* f)333 int ParamInterface::load(VirtFILE* f) 334 334 { 335 335 SString buf; … … 338 338 int p_len; 339 339 bool loaded; 340 int fields_loaded=0; 340 341 while(loadSStringLine(f,buf)) 341 342 { … … 361 362 set(i,p0+p_len+1); 362 363 } 364 fields_loaded++; 363 365 loaded=true; 364 366 } … … 370 372 } 371 373 } 374 return fields_loaded; 372 375 } 373 376 … … 444 447 } 445 448 else 446 return setInt(i, atol(str));449 return setInt(i,ExtValue::getInt(str)); 447 450 } 448 451 … … 458 461 } 459 462 else 460 return setDouble(i, atof(str));463 return setDouble(i,ExtValue::getDouble(str)); 461 464 } 462 465 … … 465 468 switch(type(i)[0]) 466 469 { 467 case 'd': if (v.type!=TObj) return setInt(i,v.getInt()); else return setInt(i,(const char*)v.getString()); 468 case 'f': if (v.type!=TObj) return setDouble(i,v.getDouble()); else return setDouble(i,(const char*)v.getString()); 470 case 'd': 471 if ((v.type==TInt)||(v.type==TDouble)) return setInt(i,v.getInt()); 472 else 473 { 474 if (v.type==TObj) 475 FMprintf("ParamInterface","set",FMLV_WARN,"Getting integer value from object reference (%s)",(const char*)v.getString()); 476 return setInt(i,(const char*)v.getString()); 477 } 478 case 'f': 479 if ((v.type==TInt)||(v.type==TDouble)) return setDouble(i,v.getDouble()); 480 else 481 { 482 if (v.type==TObj) 483 FMprintf("ParamInterface","set",FMLV_WARN,"Getting floating point value from object reference (%s)",(const char*)v.getString()); 484 return setDouble(i,(const char*)v.getString()); 485 } 469 486 case 's': { SString t=v.getString(); return setString(i,t); } 470 487 case 'o': return setObject(i,v.getObject()); 471 488 case 'x': return setExtValue(i,v); 472 default: FMprintf("ParamInterface"," get",FMLV_ERROR,"'%s.%s' is not a field",getName(),id(i));489 default: FMprintf("ParamInterface","set",FMLV_ERROR,"'%s.%s' is not a field",getName(),id(i)); 473 490 } 474 491 return 0; … … 826 843 } 827 844 828 voidParamInterface::load2(const SString &s,int &poz)845 int ParamInterface::load2(const SString &s,int &poz) 829 846 { 830 847 int i; // numer akt. parametru … … 832 849 int len; 833 850 int ret; 851 int fields_loaded=0; 834 852 const char *t,*lin,*end; 835 853 const char *rownasie,*przecinek; … … 838 856 const char *value,*valstop; 839 857 SString tmpvalue; 840 if (poz>=s.len()) return ;858 if (poz>=s.len()) return fields_loaded; 841 859 t=(const char*)s+poz; 842 860 843 861 // na razie wszystko musi byc w jednej linii... 844 862 lin=getline(s,poz,len); 845 if (!len) return ; // pusta linia = koniec863 if (!len) return fields_loaded; // pusta linia = koniec 846 864 i=0; 847 865 end=lin+len; … … 849 867 { 850 868 // przetwarzanie jednego par 851 while (strchr(" \n\r\t",*t)) if (t<end) t++; else return ;869 while (strchr(" \n\r\t",*t)) if (t<end) t++; else return fields_loaded; 852 870 853 871 przecinek=strchrlimit(t,',',end); if (!przecinek) przecinek=end; … … 908 926 *(char*)valstop=0; 909 927 ret=set(i,value); 928 fields_loaded++; 910 929 if (ret&(PSET_HITMAX|PSET_HITMIN)) 911 930 FMprintf("Param","load2",FMLV_WARN,"Adjusted '%s' in '%s' (was too %s)", … … 916 935 if (i>=0) i++; 917 936 #ifdef __CODEGUARD__ 918 if (przecinek<end-1) t=przecinek+1; else return ;937 if (przecinek<end-1) t=przecinek+1; else return fields_loaded; 919 938 #else 920 939 t=przecinek+1; 921 940 #endif 922 941 } 923 return ;942 return fields_loaded; 924 943 } 925 944 -
cpp/frams/param/param.h
r124 r144 154 154 int save(VirtFILE*,const char* altname=NULL,bool force=0); 155 155 int saveprop(VirtFILE*,int i,const char* p,bool force=0); 156 void load(VirtFILE*); 157 void load2(const SString &,int &); 156 int load(VirtFILE*);///< @return number of fields loaded 157 int load2(const SString &,int &);///< @return number of fields loaded 158 158 159 159 static const char* SERIALIZATION_PREFIX; -
cpp/frams/util/extvalue.cpp
r121 r144 250 250 } 251 251 252 static long compareNull(const ExtValue& v) 253 { 254 switch(v.type) 255 { 256 case TDouble: return v.getDouble()!=0.0; 257 case TInt: return v.getInt()?1:0; 258 case TString: return 1; 259 default: return !v.isNull(); 260 } 261 } 262 252 263 long ExtValue::compare(const ExtValue& src) const 253 264 { 254 265 if (type==TUnknown) 255 { 256 if (src.type==TDouble) 257 return (src.getDouble()!=0.0); 258 if (src.type==TString) 259 return 1; 260 return src.getInt()?1:0; 261 } 266 return compareNull(src); 262 267 else if (src.type==TUnknown) 263 { 264 if (type==TDouble) 265 return (getDouble()!=0.0); 266 if (type==TString) 267 return 1; 268 return getInt()?1:0; 269 } 268 return compareNull(*this); 270 269 switch(type) 271 270 { … … 545 544 } 546 545 546 long ExtValue::getInt(const char* s) 547 { 548 if ((s[0]=='0')&&(s[1]=='x')) 549 { 550 long val; 551 sscanf(s+2,"%lx",&val); 552 return val; 553 } 554 else 555 { 556 if (strchr(s,'e')||(strchr(s,'E'))) 557 return (long)atof(s); 558 else 559 return atol(s); 560 } 561 } 562 563 double ExtValue::getDouble(const char* s) 564 { 565 if ((s[0]=='0')&&(s[1]=='x')) 566 { 567 long val; 568 sscanf(s+2,"%lx",&val); 569 return val; 570 } 571 else 572 return atof(s); 573 } 574 547 575 long ExtValue::getInt() const 548 576 { … … 551 579 case TInt: return idata(); 552 580 case TDouble: return (int)ddata(); 553 case TString: 554 { 555 const char* s=(const char*)sdata(); 556 if ((s[0]=='0')&&(s[1]=='x')) 557 { 558 long val; 559 sscanf(s+2,"%lx",&val); 560 return val; 561 } 562 else 563 { 564 if (strchr(s,'e')||(strchr(s,'E'))) 565 return (long)atof(s); 566 else 567 return atol(s); 568 } 569 } 570 case TObj: return (long)odata().param; 581 case TString: return getInt((const char*)sdata()); 582 case TObj: 583 FMprintf("ExtValue","getInt",FMLV_WARN,"Getting integer value from object reference (%s)",(const char*)getString()); 584 return (long)odata().param; 571 585 default:; 572 586 } 573 587 return 0; 574 588 } 589 575 590 double ExtValue::getDouble() const 576 591 { … … 579 594 case TDouble: return ddata(); 580 595 case TInt: return (double)idata(); 581 case TString: 582 { 583 const char* s=(const char*)sdata(); 584 if ((s[0]=='0')&&(s[1]=='x')) 585 { 586 long val; 587 sscanf(s+2,"%lx",&val); 588 return val; 589 } 590 else 591 return atof(s); 592 } 593 case TObj: return (double)(long)odata().param; 596 case TString: return getDouble((const char*)sdata()); 597 case TObj: 598 FMprintf("ExtValue","getDouble",FMLV_WARN,"Getting floating point value from object reference (%s)",(const char*)getString()); 599 return (double)(long)odata().param; 594 600 default:; 595 601 } -
cpp/frams/util/extvalue.h
r121 r144 147 147 void setString(const SString &v) {if (type!=TString) setrs(v); else sdata()=v;} 148 148 void setObject(const ExtObject &src) {if (type!=TObj) setro(src); else odata()=src;} 149 static long getInt(const char* s); 150 static double getDouble(const char* s); 149 151 long getInt() const; 150 152 double getDouble() const; … … 153 155 SString serialize() const; 154 156 ExtObject getObject() const; 157 bool isNull() const {return (type==TUnknown)||((type==TObj)&&odata().isEmpty());} 155 158 const char* parseNumber(const char* in); 156 159 const char* deserialize(const char* in);//< @return first character after the succesfully parsed string or NULL if failed
Note: See TracChangeset
for help on using the changeset viewer.