Changeset 247 for cpp/frams/vm/classes
- Timestamp:
- 11/07/14 17:51:01 (10 years ago)
- Location:
- cpp/frams/vm/classes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/3dobject.cpp
r241 r247 472 472 {return ExtObject(&getStaticParam(),p);} 473 473 474 ParamEntry* ReferenceObj::getStaticParamtab()475 {476 #define FIELDSTRUCT ReferenceObj477 static ParamEntry paramtab[]=478 {479 {"Ref",1,5,"Ref","Reference objects. Useful for returning things from functions.\n\nExample:\nvar x=111;\nsquare(&x);// '&' creates the Reference object\nSimulator.print(x);//x is now 12321\n\nfunction square(r)\n{r.value=r.value*r.value;}\n//square receives the Reference objects and changes its 'value' field"},480 481 {"value",0,PARAM_NOSTATIC,"value","x",GETSET(value),},482 {"newS",0,0,"create new reference","p",PROCEDURE(p_newS),"(for internal use only) use &variablename to create Ref objects.",},483 {"newO",0,0,"create new reference","p",PROCEDURE(p_newO),"(for internal use only) use &variablename to create Ref objects.",},484 {"copyFrom",0,0,"copy the reference","p(oRef)",PROCEDURE(p_copyFrom),"make the reference point to the same target,"},485 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"textual form","s",GETONLY(toString),},486 {0,0,0,},487 };488 #undef FIELDSTRUCT489 return paramtab;490 }491 492 Param& ReferenceObj::getStaticParam()493 {494 #ifdef __CODEGUARD__495 static ReferenceObj static_referenceobj;496 static Param static_refobjectparam(getStaticParamtab(),&static_referenceobj);497 #else498 static Param static_refobjectparam(getStaticParamtab());499 #endif500 return static_refobjectparam;501 }502 503 void ReferenceObj::p_newS(ExtValue *args,ExtValue *ret)504 {505 *ret=makeDynamicObject(new ReferenceObj((ExtValue*)args->getInt()));506 }507 508 void ReferenceObj::p_newO(ExtValue *args,ExtValue *ret)509 {510 if (args[0].type==TInt)511 *ret=makeDynamicObject(new ReferenceObj(args[1].getObject(),args[0].getInt()));512 else513 *ret=makeDynamicObject(new ReferenceObj(args[1].getObject(),args[0].getString()));514 }515 516 void ReferenceObj::p_copyFrom(ExtValue *args,ExtValue *ret)517 {518 ReferenceObj* other=fromObject(args[0]);519 if (other)520 {521 value=other->value;522 obj=other->obj;523 prop=other->prop;524 }525 }526 527 void ReferenceObj::get_toString(ExtValue *ret)528 {529 SString s="(";530 static SListTempl<ReferenceObj*> trace;531 if (trace.find(this)>=0)532 s+="...";533 else534 {535 trace+=this;536 if (value)537 s+=value->getString();538 else539 {540 ExtValue v;541 Param tmp_param;542 ParamInterface *pi=obj.getParamInterface(tmp_param);543 pi->get(prop,v);544 s+=v.getString();545 }546 trace-=this;547 }548 s+=")";549 ret->setString(s);550 }551 552 void ReferenceObj::get_value(ExtValue *ret)553 {554 if (value)555 *ret=*value;556 else557 {558 Param tmp_param;559 ParamInterface *pi=obj.getParamInterface(tmp_param);560 pi->get(prop,*ret);561 }562 }563 564 int ReferenceObj::set_value(const ExtValue *val)565 {566 if (value)567 *value=*val;568 else569 {570 Param tmp_param;571 ParamInterface *pi=obj.getParamInterface(tmp_param);572 pi->set(prop,*val);573 }574 return PSET_CHANGED;575 }576 577 ReferenceObj::ReferenceObj(const ExtObject &o,const SString &p)578 :value(0),obj(o)579 {580 Param tmp_param;581 ParamInterface *pi=obj.getParamInterface(tmp_param);582 prop=pi->findId(p);583 }584 585 ExtObject ReferenceObj::makeDynamicObject(ReferenceObj* r)586 {return ExtObject(&getStaticParam(),r);}587 588 ReferenceObj* ReferenceObj::fromObject(const ExtValue& v)589 {590 return (ReferenceObj*)v.getObjectTarget(getStaticParam().getName());591 }592 593 474 ///////////// 594 475 -
cpp/frams/vm/classes/3dobject.h
r241 r247 82 82 }; 83 83 84 class ReferenceObj: public DestrBase85 {86 public:87 ExtValue *value;88 ExtObject obj;89 int prop;90 91 ReferenceObj(ExtValue *val):value(val) {}92 ReferenceObj() {}93 ReferenceObj(const ExtObject &o,int p):value(0),obj(o),prop(p) {}94 ReferenceObj(const ExtObject &o,const SString &p);95 #define STATRICKCLASS ReferenceObj96 PARAMPROCDEF(p_newS);97 PARAMPROCDEF(p_newO);98 PARAMPROCDEF(p_copyFrom);99 PARAMGETDEF(toString);100 PARAMGETDEF(value);101 PARAMSETDEF(value);102 #undef STATRICKCLASS103 104 static ParamInterface* getInterface();105 static ExtObject makeDynamicObject(ReferenceObj* r);106 static ReferenceObj* fromObject(const ExtValue& v);107 static Param& getStaticParam();108 static ParamEntry* getStaticParamtab();109 };110 111 84 #endif
Note: See TracChangeset
for help on using the changeset viewer.