- Timestamp:
- 03/22/16 01:19:47 (9 years ago)
- Location:
- cpp/frams
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/mutableparam.cpp
r348 r478 171 171 ParamEntry *pe=new ParamEntry(); 172 172 pe->fun1=0; pe->fun2=0; 173 pe->group=( short)group;174 pe->flags=( short)(flags | MUTPARAM_ALLOCENTRY);173 pe->group=(paInt)group; 174 pe->flags=(paInt)(flags | MUTPARAM_ALLOCENTRY); 175 175 pe->offset=(intptr_t)data; 176 176 pe->id=strdup(id); -
cpp/frams/param/param.cpp
r464 r478 602 602 if (v.type == TObj) 603 603 { 604 logPrintf("ParamInterface", "set", LOG_ WARN, "Getting integer value from object reference (%s)", v.getString().c_str());604 logPrintf("ParamInterface", "set", LOG_ERROR, "Setting int '%s.%s' from object reference (%s)", getName(), id(i), v.getString().c_str()); 605 605 return 0; 606 606 } … … 614 614 if (v.type == TObj) 615 615 { 616 logPrintf("ParamInterface", "set", LOG_ WARN, "Getting floating point value from object reference (%s)", v.getString().c_str());616 logPrintf("ParamInterface", "set", LOG_ERROR, "Setting float '%s.%s' from object reference (%s)", getName(), id(i), v.getString().c_str()); 617 617 return 0; 618 618 } … … 621 621 } 622 622 case 's': { SString t = v.getString(); return setString(i, t); } 623 case 'o': return setObject(i, v.getObject()); 623 case 'o': 624 if ((v.type!=TUnknown)&&(v.type!=TObj)) 625 logPrintf("ParamInterface", "set", LOG_ERROR, "Setting object '%s.%s' from %s", getName(), id(i), v.typeAndValue().c_str()); 626 else 627 return setObject(i, v.getObject()); 628 break; 624 629 case 'x': return setExtValue(i, v); 625 630 default: logPrintf("ParamInterface", "set", LOG_ERROR, "'%s.%s' is not a field", getName(), id(i)); … … 645 650 if ((after == NULL) || (*after)) 646 651 { 647 logPrintf("ParamInterface", "set", LOG_ WARN, "serialization format mismatch in %s.%s", (getName() ? getName() : "<Unknown>"), id(i));652 logPrintf("ParamInterface", "set", LOG_ERROR, "serialization format mismatch in %s.%s", (getName() ? getName() : "<Unknown>"), id(i)); 648 653 e.setEmpty(); 649 654 } … … 956 961 ParamEntry *pe = entry(i); 957 962 if (pe->flags&PARAM_READONLY) return PSET_RONLY; 963 if (pe->flags&PARAM_OBJECTSET) 964 { 965 ExtObject o=getObject(i); 966 Param tmp; 967 ParamInterface* oif=o.getParamInterface(tmp); 968 int ass; 969 if (oif && ((ass=oif->findId("assign"))>=0)) 970 { 971 ExtValue arg=x; 972 oif->call(ass,&arg,&v); 973 } 974 else 975 logPrintf("SimpleAbstractParam", "setObject", LOG_ERROR, 976 "'%s.%s' is PARAM_OBJECTSET but no 'assign()' in %s", getName(), pe->id, o.interfaceName()); 977 return PSET_CHANGED; 978 } 958 979 ExtObject xcopy = x; //only needed for messageOnExceedRange(): retain original, requested value of x because it may be changed below 959 980 if (pe->fun2) -
cpp/frams/param/param.h
r393 r478 33 33 #define PARAM_DEPRECATED 8192 //< this member is deprecated 34 34 #define PARAM_LINECOMMENT 16384 //< Param::load() adds "@line ..." comment when loading multiline (internal use) 35 #define PARAM_OBJECTSET 32768 //< setting this field is handled by the object's assign(...) function and cannot change the object reference 35 36 36 37 typedef int32_t paInt; … … 216 217 { 217 218 const char *id; 218 short group, flags;219 paInt group, flags; 219 220 const char *name, *type; 220 221 intptr_t offset; … … 227 228 { 228 229 public: 229 ParamEntryConstructor(const char *_id, short _group = 0, short _flags = 0, const char *_name = 0, const char *_type = 0, intptr_t _offset = 0, void *_fun1 = 0, void *_fun2 = 0, const char *_help = 0)230 ParamEntryConstructor(const char *_id, paInt _group = 0, paInt _flags = 0, const char *_name = 0, const char *_type = 0, intptr_t _offset = 0, void *_fun1 = 0, void *_fun2 = 0, const char *_help = 0) 230 231 { 231 232 id = _id; group = _group; flags = _flags; name = _name; type = _type; offset = _offset; fun1 = _fun1; fun2 = _fun2; help = _help; -
cpp/frams/param/paramobj.cpp
r396 r478 41 41 if (addnew) count++; 42 42 t = tab = (ParamEntry*)malloc(sizeof(ParamEntry)*(count + gcount + 1)); 43 t->group = ( short)gcount;44 t->flags = ( short)count;43 t->group = (paInt)gcount; 44 t->flags = (paInt)count; 45 45 t->name = maybedup(dupentries, rename ? rename : pi->getName()); 46 46 t->type = maybedup(dupentries, pi->getDescription()); … … 82 82 offset += sizeof(ExtValue); 83 83 } 84 t->group = ( short)(stripgroups ? 0 : pi->group(i));85 t->flags = ( short)pi->flags(i);84 t->group = (paInt)(stripgroups ? 0 : pi->group(i)); 85 t->flags = (paInt)pi->flags(i); 86 86 if (readonly_into_userreadonly && (t->flags & PARAM_READONLY)) 87 87 t->flags=(t->flags & ~PARAM_READONLY) | PARAM_USERREADONLY; -
cpp/frams/param/paramtabobj.cpp
r286 r478 25 25 memmove(tab+siz-count,p,sizeof(ParamEntry)*count); 26 26 memset(tab+siz,0,sizeof(ParamEntry)); 27 if (siz>0) tab[0].flags=( short)(siz-tab[0].group);27 if (siz>0) tab[0].flags=(paInt)(siz-tab[0].group); 28 28 return siz-1; 29 29 } … … 34 34 resize(siz-count); 35 35 memset(tab+siz,0,sizeof(ParamEntry)); 36 if (siz>0) tab[0].flags=( short)(siz-tab[0].group);36 if (siz>0) tab[0].flags=(paInt)(siz-tab[0].group); 37 37 } 38 38 -
cpp/frams/util/extvalue.cpp
r472 r478 104 104 } 105 105 106 bool ExtObject::callDelegate(const char* delegate,ExtValue *args,ExtValue *ret) 107 { 108 Param tmp; 109 ParamInterface *pi=getParamInterface(tmp); 110 if (pi) 111 { 112 int f=pi->findId(delegate); 113 if (f>=0) 114 { 115 pi->call(f,args,ret); 116 return true; 117 } 118 } 119 logPrintf("Genotype","get", LOG_ERROR, "Could not call delegate '%s.%s'", pi?pi->getName():"NULL",delegate); 120 return false; 121 } 106 122 107 123 SString ExtObject::toString() const … … 644 660 else 645 661 { 646 logPrintf("ExtValue", "divide", LOG_ CRITICAL, "Division by zero: %d/0", idata());662 logPrintf("ExtValue", "divide", LOG_ERROR, "Division by zero: %d/0", idata()); 647 663 setInvalid(); 648 664 } … … 653 669 if (a == 0.0) 654 670 { 655 logPrintf("ExtValue", "divide", LOG_ CRITICAL, "Division by zero: %s/0.0", getString().c_str());671 logPrintf("ExtValue", "divide", LOG_ERROR, "Division by zero: %s/0.0", getString().c_str()); 656 672 setInvalid(); 657 673 } … … 662 678 if (!finite(tmp)) 663 679 { 664 logPrintf("ExtValue", "divide", LOG_ CRITICAL, "Overflow %s/%g", getString().c_str(), a); setInvalid();680 logPrintf("ExtValue", "divide", LOG_ERROR, "Overflow %s/%g", getString().c_str(), a); setInvalid(); 665 681 } 666 682 else … … 868 884 case TString: return getInt(sdata().c_str()); 869 885 case TObj: 870 logPrintf("ExtValue", "getInt", LOG_ WARN, "Getting integer value from object reference (%s)", getString().c_str());886 logPrintf("ExtValue", "getInt", LOG_ERROR, "Getting integer value from object reference (%s)", getString().c_str()); 871 887 return (paInt)(intptr_t)odata().param; 872 888 default:; … … 883 899 case TString: return getDouble(sdata().c_str()); 884 900 case TObj: 885 logPrintf("ExtValue", "getDouble", LOG_ WARN, "Getting floating point value from object reference (%s)", getString().c_str());901 logPrintf("ExtValue", "getDouble", LOG_ERROR, "Getting floating point value from object reference (%s)", getString().c_str()); 886 902 return (double)(intptr_t)odata().param; 887 903 default:; -
cpp/frams/util/extvalue.h
r464 r478 67 67 void* getTarget() const { return (subtype & 1) ? dbobject : object; } 68 68 void* getTarget(const char* classname, bool through_barrier = true, bool warn = true) const; 69 bool callDelegate(const char* delegate,ExtValue *args,ExtValue *ret); 69 70 void setEmpty() { decref(); subtype = 0; param = NULL; object = NULL; } 70 71 int isEmpty() const { return !param; } -
cpp/frams/vm/classes/collectionobj.cpp
r464 r478 49 49 ParamEntry dictionary_paramtab[]= 50 50 { 51 {"Dictionary",1,1 0,"Dictionary","Dictionary associates stored values with string keys "51 {"Dictionary",1,11,"Dictionary","Dictionary associates stored values with string keys " 52 52 "(\"key\" is the first argument in get/set/remove functions). Integer key can be " 53 53 "used to enumerate all elements (note that while iterating, the elements are returned in no particular order).\n" … … 76 76 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"Textual form","s",GETONLY(toString),}, 77 77 {"clone",0,PARAM_NOSTATIC,"Create a clone","p oDictionary()",PROCEDURE(p_clone),"The resulting clone is a shallow copy (contains the same object references as the original). A deep copy can be obtained through serialization: String.deserialize(String.serialize(object));"}, 78 {"assign",0,PARAM_NOSTATIC,"Assign from another object","p(x)",PROCEDURE(p_assign),"Replaces current dictionary with dictionary contents from another object."}, 79 78 80 {0,0,0,}, 79 81 }; … … 372 374 } 373 375 376 ExtValue DictionaryObject::get(SString key) 377 { 378 ExtValue *val=(ExtValue*)hash.get(key); 379 if (val) 380 return *val; 381 return ExtValue::empty(); 382 } 383 384 ExtValue DictionaryObject::get(int index) 385 { 386 HashEntryIterator* iter=getIndexIterator(index); 387 if (iter && (*iter)->value) 388 return *((ExtValue*)(*iter)->value); 389 return ExtValue::empty(); 390 } 391 374 392 void DictionaryObject::p_get(PARAMPROCARGS) 375 393 { 376 394 if ((args->type==TInt)||(args->type==TDouble)) 377 { 378 HashEntryIterator* iter=getIndexIterator(args->getInt()); 379 if (iter && (*iter)->value) 380 { 381 *ret=*((ExtValue*)(*iter)->value); 382 return; 383 } 384 } 385 else 386 { 387 ExtValue *val=(ExtValue*)hash.get(args[0].getString()); 388 if (val) 389 { 390 *ret=*val; 391 return; 392 } 393 } 394 *ret=ExtValue(); 395 *ret=get(args->getInt()); 396 else 397 *ret=get(args[0].getString()); 395 398 } 396 399 … … 406 409 } 407 410 411 ExtValue DictionaryObject::set(SString key,ExtValue new_value) 412 { 413 ExtValue ret; 414 ExtValue *new_ext=(new_value.getType()==TUnknown) ? NULL : new ExtValue(new_value); 415 ExtValue *old_ext=(ExtValue*)hash.put(key,new_ext); 416 if (old_ext) { ret=*old_ext; delete old_ext;} 417 return ret; 418 } 419 408 420 void DictionaryObject::p_set(PARAMPROCARGS) 409 421 { 410 ExtValue *newval=(args[0].getType()==TUnknown)?0:new ExtValue(args[0]); 411 ExtValue *oldval=(ExtValue*)hash.put(args[1].getString(),newval); 412 if (oldval) {*ret=*oldval; delete oldval;} else *ret=ExtValue(); 422 *ret=set(args[1].getString(),args[0]); 413 423 } 414 424 … … 461 471 } 462 472 473 void DictionaryObject::copyFrom(DictionaryObject *other) 474 { 475 for(HashEntryIterator it(other->hash);it.isValid();it++) 476 { 477 ExtValue *v=(ExtValue*)it->value; 478 hash.put(it->key,v?new ExtValue(*v):NULL); 479 } 480 } 481 463 482 void DictionaryObject::p_clone(PARAMPROCARGS) 464 483 { 465 484 DictionaryObject *c=new DictionaryObject; 466 for(HashEntryIterator it(hash);it.isValid();it++) 467 { 468 ExtValue *v=(ExtValue*)it->value; 469 c->hash.put(it->key,v?new ExtValue(*v):NULL); 470 } 485 c->copyFrom(this); 471 486 ret->setObject(ExtObject(&par,c)); 487 } 488 489 void DictionaryObject::p_assign(PARAMPROCARGS) 490 { 491 clear(); 492 DictionaryObject *other=DictionaryObject::fromObject(args[0].getObject(),false); 493 if (other) 494 copyFrom(other); 495 ret->setEmpty(); 472 496 } 473 497 -
cpp/frams/vm/classes/collectionobj.h
r464 r478 72 72 PARAMGETDEF(toString); 73 73 PARAMPROCDEF(p_clone); 74 PARAMPROCDEF(p_assign); 74 75 #undef STATRICKCLASS 76 ExtValue get(SString key); 77 ExtValue get(int index); 78 ExtValue set(SString key,ExtValue new_value); 79 void copyFrom(DictionaryObject *other); 75 80 SString serialize(SerializationFormat format) const; 76 81 static void p_new(void*,ExtValue*args,ExtValue*ret)
Note: See TracChangeset
for help on using the changeset viewer.