Changeset 642 for cpp/frams/vm/classes/collectionobj.cpp
- Timestamp:
- 12/31/16 20:32:03 (8 years ago)
- File:
-
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.