Legend:
- Unmodified
- Added
- Removed
-
cpp/gdk/param.cpp
r81 r93 1 1 // This file is a part of the Framsticks GDK library. 2 // Copyright (C) 2002-201 1Szymon Ulatowski. See LICENSE.txt for details.2 // Copyright (C) 2002-2013 Szymon Ulatowski. See LICENSE.txt for details. 3 3 // Refer to http://www.framsticks.com/ for further information. 4 4 … … 209 209 int ParamInterface::setExtValueById(const char* prop,const ExtValue &v) 210 210 {int i=findId(prop); if (i>=0) return setExtValue(i,v); else return PSET_NOPROPERTY;} 211 int ParamInterface::setById(const char* prop,const ExtValue &v) 212 {int i=findId(prop); if (i>=0) return set(i,v); else return PSET_NOPROPERTY;} 211 213 212 214 int ParamInterface::save(VirtFILE* f,const SString* altname,bool force) … … 339 341 int p_len; 340 342 bool eol,loaded; 341 int ret;342 343 while(fgets0(t,100,f,eol)) 343 344 { … … 355 356 int ch; while((ch=fgetc(f))!=EOF) if (ch=='\n') break; 356 357 unquoteTilde(s); 357 ret=set(i,(const char*)s);358 set(i,(const char*)s); 358 359 } 359 360 else 360 361 { 361 362 if (eol) 362 ret=set(i,p0+p_len+1);363 set(i,p0+p_len+1); 363 364 else 364 365 { … … 369 370 tmp+=t; 370 371 } 371 ret=set(i,(const char*)tmp);372 set(i,(const char*)tmp); 372 373 } 373 374 } 374 if (ret & (PSET_HITMIN | PSET_HITMAX))375 FMprintf("Param","load2",FMLV_WARN,"Adjusted '%s' in '%s' (was too %s)",376 id(i),getName(),(ret&PSET_HITMAX)?"big":"small");377 375 loaded=true; 378 376 } … … 654 652 ParamEntry *pe=entry(i); 655 653 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 656 long a=0,b=0,result=0; 654 long xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below 655 long a=0,b=0; 656 int result=0; 657 657 const char* t=pe->type+1; 658 658 while(*t) if (*t==' ') break; else t++; … … 667 667 { 668 668 v.setInt(x); 669 re turn result |(*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v);669 result |= (*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v); 670 670 } 671 671 else … … 677 677 *((long*)target)=x; 678 678 } 679 } 680 messageOnExceedRange(i,result,xcopy); 679 681 return result; 680 }681 682 } 682 683 … … 686 687 ParamEntry *pe=entry(i); 687 688 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 688 double a=0,b=0; int result=0; 689 double xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below 690 double a=0,b=0; 691 int result=0; 689 692 const char* t=pe->type+1; 690 693 while(*t) if (*t==' ') break; else t++; … … 699 702 { 700 703 v.setDouble(x); 701 re turn result |(*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v);704 result |= (*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v); 702 705 } 703 706 else … … 709 712 *((double*)target)=x; 710 713 } 714 } 715 messageOnExceedRange(i,result,xcopy); 711 716 return result; 712 }713 717 } 714 718 … … 720 724 ParamEntry *pe=entry(i); 721 725 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 726 SString xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below 722 727 const char* t=pe->type+1; 723 728 while(*t) if (*t==' ') break; else t++; 724 long a=0,b=0,result=0; 729 long a=0,b=0; 730 int result=0; 725 731 if (sscanf(t,"%ld %ld",&a,&b)==2) 726 732 { … … 736 742 { 737 743 v.setString(*xx); 738 re turn result |(*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v);744 result |= (*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v); 739 745 } 740 746 else … … 746 752 *((SString*)target)=x; 747 753 } 754 } 755 messageOnExceedRange(i,result,xcopy); 748 756 return result; 749 }750 757 } 751 758 … … 755 762 ParamEntry *pe=entry(i); 756 763 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 764 ExtObject xcopy=x; //only needed for helpful printed messages: retain original, requested value of x because it may be changed below 757 765 if (pe->fun2) 758 766 { 759 767 v.setObject(x); 760 return (*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v); 768 int result=(*(int(*)(void*,const ExtValue*))pe->fun2)(object,&v); 769 messageOnExceedRange(i,result,xcopy); 770 return result; 761 771 } 762 772 else … … 772 782 ParamEntry *pe=entry(i); 773 783 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 784 ExtValue xcopy=x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 774 785 if (pe->fun2) 775 786 { 776 return (*(int(*)(void*,const ExtValue*))pe->fun2)(object,&x); 787 int result=(*(int(*)(void*,const ExtValue*))pe->fun2)(object,&x); 788 messageOnExceedRange(i,result,xcopy); 789 return result; 777 790 } 778 791 else … … 793 806 { 794 807 FMprintf("SimpleAbstractParam","call",FMLV_ERROR, 795 (*pe->type!='p')?"'%s.%s' is not a function":" internal error - undefined function pointer for '%s.%s'",getName(),pe->id);808 (*pe->type!='p')?"'%s.%s' is not a function":"Internal error - undefined function pointer for '%s.%s'",getName(),pe->id); 796 809 } 797 810 } … … 942 955 return -9999; 943 956 } 957 -
cpp/gdk/param.h
r81 r93 11 11 #include "statrick.h" 12 12 #include "virtfile.h" 13 #include "framsg.h" 13 14 14 15 class ExtValue; … … 118 119 int setStringById(const char* prop,const SString &);///< set string value, you can only use this for "s" type prop 119 120 int setObjectById(const char* prop,const ExtObject &);///< set object reference, you can only use this for "o" type prop 120 121 int set ExtValueById(const char* prop,const ExtValue &); ///< 4 in 1121 int setExtValueById(const char* prop,const ExtValue &); ///< for ExtValue types only 122 int setById(const char* prop,const ExtValue &);///< can be used for all property types 122 123 123 124 /** get valid minimum, maximum and default value for property 'prop' … … 239 240 ExtValue getExtValue(int); 240 241 242 template<typename T> void messageOnExceedRange(int i,int setflags, T valuetoset) ///< prints a warning when setflags indicates that allowed param range has been exceeded during set 243 { 244 if (setflags & (PSET_HITMIN | PSET_HITMAX)) 245 { 246 SString svaluetoset=SString::valueOf(valuetoset); //converts any type to SString 247 SString actual=get(i); 248 FMprintf("Param","set",FMLV_WARN,"Setting '%s.%s = %s' exceeded allowed range (too %s). Adjusted to %s.", 249 getName(),id(i),(const char*)svaluetoset,(setflags&PSET_HITMAX)?"big":"small",(const char*)actual); 250 } 251 } 252 241 253 int setInt(int,long); 242 254 int setDouble(int,double);
Note: See TracChangeset
for help on using the changeset viewer.