Changeset 171


Ignore:
Timestamp:
03/13/14 01:00:33 (6 years ago)
Author:
sz
Message:

getObjectTarget is now the recommended way to retrieve object from ExtValue?, can post the standard warning message about missing object

Location:
cpp/frams
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/_demos/serial_test.cpp

    r121 r171  
    4444                        return;
    4545                        }
    46                 VectorObject *vec=VectorObject::fromObject(v->getObject());
     46                VectorObject *vec=VectorObject::fromObject(v->getObject(),false);
    4747                if (vec)
    4848                        {
     
    5252                        return;
    5353                        }
    54                 DictionaryObject *dict=DictionaryObject::fromObject(v->getObject());
     54                DictionaryObject *dict=DictionaryObject::fromObject(v->getObject(),false);
    5555                if (dict)
    5656                        {
  • cpp/frams/util/extvalue.cpp

    r144 r171  
    5656if (!(subtype&1)) return false;
    5757if (dbobject->refcount==1) return false;
    58 VectorObject* v=VectorObject::fromObject(*this);
     58VectorObject* v=VectorObject::fromObject(*this,false);
    5959if (v)
    6060        {
     
    7272}
    7373
    74 void* ExtObject::getTarget(const char* classname, bool through_barrier) const
     74void* ExtObject::getTarget(const char* classname, bool through_barrier, bool warn) const
    7575{
    7676if (!strcmp(interfaceName(),classname))
     
    8181        BarrierObject *bo=BarrierObject::fromObject(*this);
    8282        if (bo)
    83                 return bo->getSourceObject().getTarget(classname);
     83                return bo->getSourceObject().getTarget(classname,true,warn);
    8484        }
    8585#endif
     86
     87if (warn)
     88        {
     89        FMprintf("ExtValue","getObjectTarget",FMLV_WARN,"%s object expected, %s found",classname,interfaceName());
     90        }
     91
    8692return NULL;
    8793}
     
    173179
    174180if (isEmpty()) return SString();
    175 VectorObject *vec=VectorObject::fromObject(*this);
     181VectorObject *vec=VectorObject::fromObject(*this,false);
    176182if (vec)
    177183        return vec->serialize();
    178 DictionaryObject *dic=DictionaryObject::fromObject(*this);
     184DictionaryObject *dic=DictionaryObject::fromObject(*this,false);
    179185if (dic)
    180186        return dic->serialize();
     
    215221///////////////////////////////////////
    216222
     223void *ExtValue::getObjectTarget(const char* classname,bool warn) const
     224{
     225if (type!=TObj)
     226        {
     227        if (warn)
     228                {
     229                SString tmp=getString();
     230                if (tmp.len()>30) tmp=tmp.substr(0,30)+"...";
     231                if (type==TString) tmp=SString("\"")+tmp+SString("\"");
     232                FMprintf("ExtValue","getObjectTarget",FMLV_WARN,"%s object expected, %s found",classname,(const char*)tmp);
     233                }
     234        return NULL;
     235        }
     236
     237return getObject().getTarget(classname,true,warn);
     238}
     239
    217240void ExtValue::set(const ExtValue& src)
    218241{
     
    326349        case TObj:
    327350                {
    328                 VectorObject *vec=VectorObject::fromObject(getObject());
    329                 VectorObject *vec2=VectorObject::fromObject(src.getObject());
     351                VectorObject *vec=VectorObject::fromObject(getObject(),false);
     352                VectorObject *vec2=VectorObject::fromObject(src.getObject(),false);
    330353                if (vec && vec2)
    331354                        {
     
    368391        case TObj:
    369392                {
    370                 VectorObject *vec=VectorObject::fromObject(getObject());
     393                VectorObject *vec=VectorObject::fromObject(getObject(),false);
    371394                if (vec)
    372395                        {
     
    532555        case TString:
    533556        {
    534         VectorObject *vec=VectorObject::fromObject(src.getObject());
     557        VectorObject *vec=VectorObject::fromObject(src.getObject(),false);
    535558        if (vec)
    536559                sdata()=format(sdata(),(const ExtValue**)&vec->data.getref(0),vec->data.size());
     
    815838        if (cls && (tmp.getType()!=TUnknown) && (tmp.getType()!=TInvalid))
    816839                {
    817                 VectorObject *vec=VectorObject::fromObject(tmp.getObject());
     840                VectorObject *vec=VectorObject::fromObject(tmp.getObject(),false);
    818841                if (vec)
    819842                        {
     
    826849                                }
    827850                        }
    828                 DictionaryObject *dic=DictionaryObject::fromObject(tmp.getObject());
     851                DictionaryObject *dic=DictionaryObject::fromObject(tmp.getObject(),false);
    829852                if (dic)
    830853                        {
  • cpp/frams/util/extvalue.h

    r144 r171  
    5858bool matchesInterfaceName(ParamInterface* pi) const {return !strcmp(interfaceName(),pi->getName());}
    5959void* getTarget() const {return (subtype&1)?dbobject:object;}
    60 void* getTarget(const char* classname, bool through_barrier=true) const;
     60void* getTarget(const char* classname, bool through_barrier=true, bool warn=true) const;
    6161void setEmpty() {decref();subtype=0;param=NULL;object=NULL;}
    6262int isEmpty() const {return !param;}
     
    142142bool makeUnique() {return (type==TObj) && odata().makeUnique();} //< @return false if nothing has changed
    143143ExtPType getType() {return type;}
    144 void *getObjectTarget(const char* classname) {return (type==TObj)?getObject().getTarget(classname):0;}
     144void *getObjectTarget(const char* classname,bool warn=true) const;
    145145void setInt(long v) {if (type!=TInt) setri(v); else idata()=v;}
    146146void setDouble(double v) {if (type!=TDouble) setrd(v); else ddata()=v;}
  • cpp/frams/vm/classes/3dobject.cpp

    r156 r171  
    193193Pt3D_Ext* Pt3D_Ext::fromObject(const ExtValue& v)
    194194{
    195 if (v.type!=TObj) return 0;
    196 const ExtObject& o=v.getObject();
    197 return (Pt3D_Ext*)o.getTarget(getStaticParam().getName());
     195return (Pt3D_Ext*)v.getObjectTarget(getStaticParam().getName());
    198196}
    199197
     
    444442Orient_Ext* Orient_Ext::fromObject(const ExtValue& v)
    445443{
    446 if (v.type!=TObj) return 0;
    447 const ExtObject& o=v.getObject();
    448 return (Orient_Ext*)o.getTarget(getStaticParam().getName());
     444return (Orient_Ext*)v.getObjectTarget(getStaticParam().getName());
    449445}
    450446
     
    573569ReferenceObj* ReferenceObj::fromObject(const ExtValue& v)
    574570{
    575 if (v.type!=TObj) return 0;
    576 const ExtObject& o=v.getObject();
    577 return (ReferenceObj*)o.getTarget(getStaticParam().getName());
    578 }
     571return (ReferenceObj*)v.getObjectTarget(getStaticParam().getName());
     572}
  • cpp/frams/vm/classes/collectionobj.cpp

    r164 r171  
    266266}
    267267
    268 VectorObject* VectorObject::fromObject(const ExtObject& o)
    269 {
    270 return (VectorObject*)o.getTarget(par.getName());
     268VectorObject* VectorObject::fromObject(const ExtObject& o, bool warn)
     269{
     270return (VectorObject*)o.getTarget(par.getName(),true,warn);
    271271}
    272272
     
    424424}
    425425
    426 DictionaryObject* DictionaryObject::fromObject(const ExtObject& o)
    427 {
    428 return (DictionaryObject*)o.getTarget(par.getName());
     426DictionaryObject* DictionaryObject::fromObject(const ExtObject& o, bool warn)
     427{
     428return (DictionaryObject*)o.getTarget(par.getName(), true, warn);
    429429}
    430430
  • cpp/frams/vm/classes/collectionobj.h

    r121 r171  
    4444ExtObject makeObject() {return ExtObject(&par,this);}
    4545
    46 static VectorObject* fromObject(const ExtObject& o);
     46static VectorObject* fromObject(const ExtObject& o, bool warn=true);
    4747};
    4848
     
    7474static void p_new(void*,ExtValue*args,ExtValue*ret)
    7575        {ret->setObject(ExtObject(&par,new DictionaryObject));}
    76 static DictionaryObject* fromObject(const ExtObject& v);
     76static DictionaryObject* fromObject(const ExtObject& v, bool warn=true);
    7777ExtObject makeObject() {return ExtObject(&par,this);}
    7878};
  • cpp/frams/vm/classes/genoobj.cpp

    r138 r171  
    107107}
    108108
    109 Geno* GenoObj::fromObject(const ExtValue& v)
     109Geno* GenoObj::fromObject(const ExtValue& v, bool warn)
    110110{
    111 if (v.type!=TObj) return 0;
    112 const ExtObject& o=v.getObject();
    113 //if ((o.param!=&getStaticParam())&&(o.param!=&getDynamicParam())) return 0;
    114 return (Geno*)o.getTarget(getStaticParam().getName());
     111return (Geno*)v.getObjectTarget(getStaticParam().getName(), warn);
    115112}
  • cpp/frams/vm/classes/genoobj.h

    r138 r171  
    3333static ExtObject makeDynamicObject(Geno* g);
    3434static ExtObject makeDynamicObjectAndDecRef(Geno* g);
    35 static Geno* fromObject(const ExtValue& v);
     35static Geno* fromObject(const ExtValue& v, bool warn=true);
    3636static ParamInterface* getInterface();
    3737
Note: See TracChangeset for help on using the changeset viewer.