Changeset 490
- Timestamp:
- 03/30/16 17:08:08 (9 years ago)
- Location:
- cpp/frams
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/param/paramobj.cpp
r478 r490 23 23 24 24 ParamEntry* ParamObject::makeParamTab(ParamInterface *pi, bool stripgroups, bool stripproc, 25 int firstprop, int maxprops, bool dupentries, int flagsexclude, bool addnew, const char* rename, bool readonly_into_userreadonly) 26 { 25 int firstprop, int maxprops, bool dupentries, int flagsexclude_data, int flagsexclude_tab, bool addnew, const char* rename, bool readonly_into_userreadonly) 26 { 27 // flagsexclude_data - skip while calculating data offsets 28 // flagsexclude_tab - skip while creating paramtab 29 // usually _data==_tab, but vmneuron public properties need _data=0 and _tab=PARAM_USERHIDDEN (data object has all fields, paramtab skips private fields) 27 30 ParamEntry *tab, *t; 28 31 int i, n, offset; … … 30 33 int count = 0, gcount = 1; 31 34 if (!stripgroups) gcount = pi->getGroupCount(); 32 if (stripproc || flagsexclude )35 if (stripproc || flagsexclude_tab) 33 36 for (int i = firstprop; i < pi->getPropCount(); i++) 34 37 { 35 38 const char*t = pi->type(i); 36 39 if ((!stripproc) || (strchr("dfsox", *t))) 37 if ((!flagsexclude ) || (!(pi->flags(i)&flagsexclude)))40 if ((!flagsexclude_tab) || (!(pi->flags(i)&flagsexclude_tab))) 38 41 if (++count >= maxprops) break; 39 42 } … … 72 75 if ((!stripproc) || (strchr("dfsox", type[0]))) 73 76 { 74 if ((!flagsexclude) || (!(pi->flags(i)&flagsexclude))) 77 paInt flag=pi->flags(i); 78 int tmp_offset; 79 if ((!flagsexclude_data) || (!(flag&flagsexclude_data))) 75 80 { 76 81 if (type[0]=='p') 77 t ->offset=0;82 tmp_offset=0; 78 83 else 79 84 { 80 t ->offset = offset;81 if (type[0] != 'x') t ->offset += (((char*)&ex.data[0]) - ((char*)&ex));85 tmp_offset = offset; 86 if (type[0] != 'x') tmp_offset += (((char*)&ex.data[0]) - ((char*)&ex)); 82 87 offset += sizeof(ExtValue); 83 88 } 89 } 90 91 if ((!flagsexclude_tab) || (!(flag&flagsexclude_tab))) 92 { 93 t->offset=tmp_offset; 84 94 t->group = (paInt)(stripgroups ? 0 : pi->group(i)); 85 t->flags = (paInt) pi->flags(i);95 t->flags = (paInt)flag; 86 96 if (readonly_into_userreadonly && (t->flags & PARAM_READONLY)) 87 97 t->flags=(t->flags & ~PARAM_READONLY) | PARAM_USERREADONLY; … … 190 200 case 'f': v->setDouble(0); v++; break; 191 201 case 's': v->setString(SString::empty()); v++; break; 192 case 'o': v->setObject(ExtObject()); v++; break; 202 case 'o': 203 { 204 ExtObject new_obj; 205 if (t->flags & PARAM_OBJECTSET) 206 { 207 ParamInterface *cls=ExtValue::findDeserializableClass(t->type+1); 208 if (cls) 209 { 210 int new_fun = cls->findId("new"); 211 if (new_fun>=0) 212 { 213 ExtValue dummy,new_value; 214 cls->call(new_fun, &dummy, &new_value); 215 new_obj=new_value.getObject(); 216 } 217 } 218 } 219 v->setObject(new_obj); 220 v++; 221 } 222 break; 193 223 case 'x': v++; break; 194 224 } -
cpp/frams/param/paramobj.h
r396 r490 53 53 ParamObject::freeObject(obj2); 54 54 */ 55 static ParamEntry* makeParamTab(ParamInterface *pi, bool stripgroups = 0, bool stripproc = 0, int firstprop = 0, int maxprops = 9999, bool dupentries = false, int flagsexclude = 0, bool addnew = false, const char* rename = NULL,bool readonly_into_userreadonly=false);55 static ParamEntry* makeParamTab(ParamInterface *pi, bool stripgroups = 0, bool stripproc = 0, int firstprop = 0, int maxprops = 9999, bool dupentries = false, int flagsexclude_data = 0, int flagsexclude_tab = 0, bool addnew = false, const char* rename = NULL,bool readonly_into_userreadonly=false); 56 56 57 57 /** deallocate paramtab obtained from makeParamTab() */ -
cpp/frams/util/extvalue.cpp
r478 r490 357 357 } 358 358 359 void ExtValue::setError(const SString& msg) 360 { 361 ErrorObject *err=new ErrorObject; 362 err->message=msg; 363 setObject(ErrorObject::makeDynamicObject(err)); 364 } 365 359 366 static ExtValue::CompareResult longsign(paInt x) 360 367 { … … 369 376 if ((v.getType() == TInt) && (v.getInt() == 0)) return ExtValue::ResultUnequal_RelaxedEqual; 370 377 return ExtValue::ResultUnequal_RelaxedUnequal; //comparing anything else with null is valid but null is neither higher nor lower than numbers or strings 378 } 379 380 static ExtValue::CompareResult compareInvalid(const ExtValue& v) 381 { 382 if (v.getType()==TInvalid) return ExtValue::ResultEqualUnordered; 383 if ((v.getType() == TInt) && (v.getInt() == 0)) return ExtValue::ResultUnequal_RelaxedEqual; 384 return ExtValue::ResultMismatch; //comparing anything else with invalid is invalid 371 385 } 372 386 … … 392 406 else if (src.isNull()) 393 407 return compareNull(*this); 408 if (getType()==TInvalid) 409 return compareInvalid(src); 410 else if (src.getType()==TInvalid) 411 return compareInvalid(*this); 394 412 switch (type) 395 413 { … … 1121 1139 return in + 5; 1122 1140 } 1123 else if (!strncmp(in, "invalid", 9))1141 else if (!strncmp(in, "invalid", 7)) 1124 1142 { 1125 1143 setInvalid(); 1126 return in + 9;1144 return in + 7; 1127 1145 } 1128 1146 else if (*in == '<') 1129 1147 { //unserializable object 1130 setInvalid(); 1131 while (*in) 1132 if (*in == '>') 1133 return in + 1; 1134 else in++; 1135 return in; 1148 const char* end=in+1; 1149 while (*end) 1150 if (*end == '>') 1151 { 1152 setError(SString("Unserializable class: ")+SString(in+1,end-in-1)); 1153 return end+1; 1154 } 1155 else 1156 end++; 1157 logPrintf("ExtValue", "deserialize", LOG_ERROR, "Missing '>'"); 1158 return NULL; 1136 1159 } 1137 1160 else if (*in == '^') … … 1236 1259 return v.toString(); 1237 1260 } 1261 1262 #define FIELDSTRUCT ErrorObject 1263 static ParamEntry errorobject_paramtab[]= 1264 { 1265 {"Error",1,3,"Error",}, 1266 {"message",0,0,"Message","s",FIELD(message),}, 1267 {"newFromString",0,0,"create new object","p oError(s message)",PROCEDURE(p_newfromstring),}, 1268 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"Textual form","s",GETONLY(toString),}, 1269 {0,0,0,}, 1270 }; 1271 #undef FIELDSTRUCT 1272 1273 Param& ErrorObject::getParam() 1274 { 1275 static Param param(errorobject_paramtab); 1276 return param; 1277 } 1278 1279 ExtObject ErrorObject::makeDynamicObject(ErrorObject* e) 1280 { 1281 return ExtObject(&getParam(), (DestrBase*)e); 1282 } 1283 1284 const SString ErrorObject::TO_STRING_PREFIX="Error: "; 1285 1286 void ErrorObject::get_toString(ExtValue* ret) 1287 { 1288 ret->setString(TO_STRING_PREFIX+message); 1289 } 1290 1291 void ErrorObject::p_newfromstring(ExtValue *args, ExtValue *ret) 1292 { 1293 ErrorObject *err=new ErrorObject(); 1294 err->message=args[0].getString(); 1295 if (err->message.startsWith(TO_STRING_PREFIX.c_str())) 1296 err->message=err->message.substr(TO_STRING_PREFIX.len()); 1297 *ret = makeDynamicObject(err); 1298 } 1299 1300 REGISTER_DESERIALIZABLE(ErrorObject) -
cpp/frams/util/extvalue.h
r482 r490 185 185 void setEmpty(); 186 186 void setInvalid() { setEmpty(); type = TInvalid; } 187 void setError(const SString& msg); 187 188 bool makeUnique() { return (type == TObj) && odata().makeUnique(); } //< @return false if nothing has changed 188 189 ExtPType getType() const { return type; } … … 243 244 #define REGISTER_DESERIALIZABLE(name) ExtValue::AddDeserializable<name> deserializable_autoinit_ ## name; 244 245 245 #endif 246 class ErrorObject: public DestrBase 247 { 248 public: 249 SString message; 250 static Param& getParam(); 251 static Param& getStaticParam() {return getParam();} 252 static ExtObject makeDynamicObject(ErrorObject* e); 253 static const SString TO_STRING_PREFIX; 254 #define STATRICKCLASS ErrorObject 255 PARAMGETDEF(toString); 256 PARAMPROCDEF(p_newfromstring); 257 #undef STATRICKCLASS 258 }; 259 260 #endif -
cpp/frams/vm/classes/collectionobj.cpp
r478 r490 545 545 ret->setEmpty(); 546 546 } 547 548 // not actually needed for deserialization (vector and dict are special cases) but findDeserializableClass can be also used in other contexts 549 REGISTER_DESERIALIZABLE(VectorObject) 550 REGISTER_DESERIALIZABLE(DictionaryObject) -
cpp/frams/vm/classes/collectionobj.h
r478 r490 25 25 VectorObject():readonly(0),owndata(1) {} 26 26 ~VectorObject() {clear();} 27 static Param& getStaticParam() {return par;} 27 28 #define STATRICKCLASS VectorObject 28 29 PARAMPROCDEF(p_clear) {if (readonly) return; clear();} … … 62 63 DictionaryObject():it(hash),it_index(-1) {} 63 64 ~DictionaryObject() {clear();} 65 static Param& getStaticParam() {return par;} 64 66 #define STATRICKCLASS DictionaryObject 65 67 PARAMPROCDEF(p_clear) {clear();}
Note: See TracChangeset
for help on using the changeset viewer.