Changeset 453
- Timestamp:
- 11/29/15 22:20:55 (9 years ago)
- Location:
- cpp/frams/vm/classes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/collectionobj.cpp
r409 r453 15 15 ParamEntry vector_paramtab[]= 16 16 { 17 {"Vector",1,1 3,"Vector","Vector is a 1-dimensional array indexed by an integer value (starting from 0). "17 {"Vector",1,14,"Vector","Vector is a 1-dimensional array indexed by an integer value (starting from 0). " 18 18 "Multidimensional arrays can be simulated by putting other Vector objects into a Vector.\n" 19 19 "Examples:\n" … … 39 39 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"Textual form","s",GETONLY(toString),}, 40 40 {"new",0,0,"Create new Vector","p oVector()",STATICPROCEDURE(p_new),}, 41 {"sort",0,PARAM_NOSTATIC,"Sort elements (in place)","p(o comparator)",PROCEDURE(p_sort),"comparator can be null, giving the \"natural\" sorting order (depending on element type), otherwise it must be a function reference obtained by the \"function FUNCTIONNAME\"operator.\n\nExample:\nfunction compareLastDigit(a,b) {return (a%10)<(b%10);}\nvar v=[16,23,35,42,54,61];\nv.sort(function compareLastDigit);"},41 {"sort",0,PARAM_NOSTATIC,"Sort elements (in place)","p(oFunctionReference comparator)",PROCEDURE(p_sort),"comparator can be null, giving the \"natural\" sorting order (depending on element type), otherwise it must be a function reference obtained from the 'function' operator.\n\nExample:\nfunction compareLastDigit(a,b) {return (a%10)<(b%10);}\nvar v=[16,23,35,42,54,61];\nv.sort(function compareLastDigit);"}, 42 42 {"iterator",0,PARAM_NOSTATIC | PARAM_READONLY,"Iterator","o",GETONLY(iterator),}, 43 {"clone",0,PARAM_NOSTATIC,"Create a clone","p oVector()",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));"}, 43 44 {0,0,0,}, 44 45 }; … … 48 49 ParamEntry dictionary_paramtab[]= 49 50 { 50 {"Dictionary",1, 9,"Dictionary","Dictionary associates stored values with string keys "51 {"Dictionary",1,10,"Dictionary","Dictionary associates stored values with string keys " 51 52 "(\"key\" is the first argument in get/set/remove functions). Integer key can be " 52 53 "used to enumerate all elements (note that while iterating, the elements are returned in no particular order).\n" … … 74 75 {"new",0,0,"Create a Dictionary","p oDictionary()",STATICPROCEDURE(p_new),"Empty directory can be also created using the {} expression."}, 75 76 {"toString",0,PARAM_READONLY | PARAM_NOSTATIC,"Textual form","s",GETONLY(toString),}, 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));"}, 76 78 {0,0,0,}, 77 79 }; … … 220 222 } 221 223 ret->setInt(-1); 224 } 225 226 void VectorObject::p_clone(PARAMPROCARGS) 227 { 228 VectorObject *c=new VectorObject; 229 c->data.setSize(data.size()); 230 for(int i=0;i<data.size();i++) 231 { 232 ExtValue *v=(ExtValue*)get(i); 233 if (v) 234 c->data.set(i,new ExtValue(*v)); 235 } 236 ret->setObject(ExtObject(&par,c)); 222 237 } 223 238 … … 446 461 } 447 462 463 void DictionaryObject::p_clone(PARAMPROCARGS) 464 { 465 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 } 471 ret->setObject(ExtObject(&par,c)); 472 } 473 448 474 DictionaryObject* DictionaryObject::fromObject(const ExtObject& o, bool warn) 449 475 { -
cpp/frams/vm/classes/collectionobj.h
r286 r453 38 38 PARAMGETDEF(toString); 39 39 PARAMPROCDEF(p_sort); 40 PARAMPROCDEF(p_clone); 40 41 #undef STATRICKCLASS 41 42 static void p_new(void*,ExtValue*args,ExtValue*ret) … … 70 71 PARAMPROCDEF(p_find); 71 72 PARAMGETDEF(toString); 73 PARAMPROCDEF(p_clone); 72 74 #undef STATRICKCLASS 73 75 SString serialize() const;
Note: See TracChangeset
for help on using the changeset viewer.