Changeset 642
- Timestamp:
- 12/31/16 20:32:03 (8 years ago)
- Location:
- cpp/frams/vm/classes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/vm/classes/collectionobj.cpp
r545 r642 15 15 ParamEntry vector_paramtab[]= 16 16 { 17 {"Vector",1,1 4,"Vector","Vector is a 1-dimensional array indexed by an integer value (starting from 0). "17 {"Vector",1,15,"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" … … 33 33 {"get",0,PARAM_NOSTATIC,"Get value at position","p x(d position)",PROCEDURE(p_get),"object[position] can be always used instead of object.get(position)"}, 34 34 {"set",0,PARAM_NOSTATIC,"Set value at position","p(d position,x value)",PROCEDURE(p_set),"object[position]=value can be always used instead of object.set(position,value)"}, 35 {"insert",0,PARAM_NOSTATIC,"Insert value at position","p(d position,x value)",PROCEDURE(p_insert),}, 35 36 {"add",0,PARAM_NOSTATIC,"Append at the end","p(x value)",PROCEDURE(p_add),}, 36 37 {"find",0,PARAM_NOSTATIC,"Find","p d(x value)",PROCEDURE(p_find),"returns the element index or -1 if not found"}, … … 95 96 :readonly(0),owndata(1) 96 97 { 97 set (0,ExtValue(pt.x));98 set (1,ExtValue(pt.y));99 set (2,ExtValue(pt.z));98 set_or_insert(0,ExtValue(pt.x),false); 99 set_or_insert(1,ExtValue(pt.y),false); 100 set_or_insert(2,ExtValue(pt.z),false); 100 101 } 101 102 … … 121 122 } 122 123 123 void VectorObject::set(int i,const ExtValue& val) 124 { 124 void VectorObject::set_or_insert(int i,const ExtValue& val,bool insert) 125 { 126 if (i<0) return; 125 127 int oldsize=data.size(); 126 if (i<0) return; 127 ExtValue *v=(ExtValue*)data.get(i); 128 if (v) delete v; 129 data.set(i,new ExtValue(val)); 130 i--; 131 while(i>=oldsize) 132 { 133 data.set(i,0); 134 i--; 128 if (i>oldsize) 129 { 130 data.setSize(i); 131 while(i>oldsize) 132 data.set(oldsize++,0); 133 } 134 if (insert) 135 data.insert(i,new ExtValue(val)); 136 else 137 { 138 ExtValue *v=(ExtValue*)data.get(i); 139 if (v) delete v; 140 data.set(i,new ExtValue(val)); 135 141 } 136 142 } -
cpp/frams/vm/classes/collectionobj.h
r490 r642 19 19 void clear(); 20 20 ExtValue *get(int i) {return (ExtValue*)data.get(i);} 21 void set (int i,const ExtValue& val);21 void set_or_insert(int i,const ExtValue& val,bool insert); 22 22 23 23 static Param par; … … 35 35 PARAMPROCDEF(p_get); 36 36 PARAMPROCDEF(p_find); 37 PARAMPROCDEF(p_set) {if (!readonly) set (arg1[1].getInt(),arg1[0]);}37 PARAMPROCDEF(p_set) {if (!readonly) set_or_insert(arg1[1].getInt(),arg1[0],false);} 38 38 PARAMPROCDEF(p_add) {if (readonly) return; /*ExtValue tmp; get_toString(&tmp); printf("%s += %s",(const char*)tmp.getString(),(const char*)arg1[0].getString());*/ data+=new ExtValue(arg1[0]); /*get_toString(&tmp); printf(" -> %s\n",(const char*)tmp.getString());*/ arg2->setInt(data.size()-1);} 39 PARAMPROCDEF(p_insert) {if (!readonly) set_or_insert(arg1[1].getInt(),arg1[0],true);} 39 40 PARAMGETDEF(toString); 40 41 PARAMPROCDEF(p_sort);
Note: See TracChangeset
for help on using the changeset viewer.