Changeset 247 for cpp/frams/vm/classes


Ignore:
Timestamp:
11/07/14 17:51:01 (9 years ago)
Author:
Maciej Komosinski
Message:

Sources support both 32-bit and 64-bit, and more compilers

Location:
cpp/frams/vm/classes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/vm/classes/3dobject.cpp

    r241 r247  
    472472{return ExtObject(&getStaticParam(),p);}
    473473
    474 ParamEntry* ReferenceObj::getStaticParamtab()
    475 {
    476 #define FIELDSTRUCT ReferenceObj
    477 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 FIELDSTRUCT
    489 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 #else
    498 static Param static_refobjectparam(getStaticParamtab());
    499 #endif
    500 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 else
    513         *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 else
    534         {
    535         trace+=this;
    536         if (value)
    537                 s+=value->getString();
    538         else
    539                 {
    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 else
    557         {
    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 else
    569         {
    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 
    593474/////////////
    594475
  • cpp/frams/vm/classes/3dobject.h

    r241 r247  
    8282};
    8383
    84 class ReferenceObj: public DestrBase
    85 {
    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 ReferenceObj
    96 PARAMPROCDEF(p_newS);
    97 PARAMPROCDEF(p_newO);
    98 PARAMPROCDEF(p_copyFrom);
    99 PARAMGETDEF(toString);
    100 PARAMGETDEF(value);
    101 PARAMSETDEF(value);
    102 #undef STATRICKCLASS
    103 
    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 
    11184#endif
Note: See TracChangeset for help on using the changeset viewer.