|
|
| version 1.1, 2024/09/10 19:15:48 | version 1.4, 2024/09/16 23:22:52 |
|---|---|
| Line 41 static void _create_or_add(Request& r, M | Line 41 static void _create_or_add(Request& r, M |
| VArray& self=GET_SELF(r, VArray); | VArray& self=GET_SELF(r, VArray); |
| ArrayValue& self_array=self.array(); | ArrayValue& self_array=self.array(); |
| if(VArray* src=static_cast<VArray*>(vsrc.as(VARRAY_TYPE))) { | if(VArray* src=dynamic_cast<VArray*>(&vsrc)) { |
| ArrayValue& src_array =src->array(); | ArrayValue& src_array =src->array(); |
| if(&src_array==&self_array) // same: doing nothing | if(&src_array==&self_array) // same: doing nothing |
| return; | return; |
| Line 51 static void _create_or_add(Request& r, M | Line 51 static void _create_or_add(Request& r, M |
| for(HashStringValue::Iterator i(*src_hash); i; i.next()) | for(HashStringValue::Iterator i(*src_hash); i; i.next()) |
| self_array+=i.value(); | self_array+=i.value(); |
| } | } |
| self.clear_hash(); | self.invalidate(); |
| } | } |
| } | } |
| Line 89 static void _keys(Request& r, MethodPara | Line 89 static void _keys(Request& r, MethodPara |
| } | } |
| static void _count(Request& r, MethodParams&) { | static void _count(Request& r, MethodParams&) { |
| r.write(*new VInt(GET_SELF(r, VArray).count())); | r.write(*new VInt(GET_SELF(r, VArray).array().used())); |
| } | |
| static void _append(Request& r, MethodParams& params) { | |
| VArray& self=GET_SELF(r, VArray); | |
| ArrayValue& array=self.array(); | |
| int count=params.count(); | |
| for(int i=0; i<count; i++){ | |
| array+=&r.process(params[i]); | |
| } | |
| self.invalidate(); | |
| } | |
| static void _insert(Request& r, MethodParams& params) { | |
| VArray& self=GET_SELF(r, VArray); | |
| ArrayValue& array=self.array(); | |
| int count=params.count(); | |
| size_t index=VArray::index(params.as_int(0, "index must be integer", r)); | |
| for(int i=1; i<count; i++){ | |
| array.insert(index+i-1, &r.process(params[i])); | |
| } | |
| self.invalidate(); | |
| } | } |
| static void _delete(Request& r, MethodParams& params) { | static void _delete(Request& r, MethodParams& params) { |
| Line 220 static void _sort(Request& r, MethodPara | Line 245 static void _sort(Request& r, MethodPara |
| VArray& self=GET_SELF(r, VArray); | VArray& self=GET_SELF(r, VArray); |
| ArrayValue& array=self.array(); | ArrayValue& array=self.array(); |
| int count=self.count(); // not array.count() | int count=array.used(); // not array.count() |
| Array_seq_item* seq=new Array_seq_item[count]; | Array_seq_item* seq=new Array_seq_item[count]; |
| int pos=0; | int pos=0; |
| Line 269 static void _sort(Request& r, MethodPara | Line 294 static void _sort(Request& r, MethodPara |
| static void _at(Request& r, MethodParams& params) { | static void _at(Request& r, MethodParams& params) { |
| VArray& self=GET_SELF(r, VArray); | VArray& self=GET_SELF(r, VArray); |
| ArrayValue& array=self.array(); | ArrayValue& array=self.array(); |
| size_t count=self.count(); | size_t count=array.count(); |
| int pos=0; | int pos=0; |
| Line 423 static void _reverse(Request& r, MethodP | Line 448 static void _reverse(Request& r, MethodP |
| VArray& result=*new VArray(count); | VArray& result=*new VArray(count); |
| ArrayValue& result_array=result.array(); | ArrayValue& result_array=result.array(); |
| for(ArrayValue::Iterator i(source_array); i; ){ | for(ArrayValue::ReverseIterator i(source_array); i; ){ |
| Value *v=i.next(); | result_array+=i.prev(); |
| if(v){ | |
| result_array.fit(count-i.index() /* no -1 as .next() is called */, v); | |
| } | |
| } | } |
| r.write(result); | r.write(result); |
| Line 448 MArray::MArray(): Methoded(VARRAY_TYPE) | Line 470 MArray::MArray(): Methoded(VARRAY_TYPE) |
| // ^array.sub[sub_from] | // ^array.sub[sub_from] |
| add_native_method("sub", Method::CT_DYNAMIC, _sub, 1, 1); | add_native_method("sub", Method::CT_DYNAMIC, _sub, 1, 1); |
| // ^a.union[b] = array | // ^array.union[b] = array |
| add_native_method("union", Method::CT_DYNAMIC, _union, 1, 1); | add_native_method("union", Method::CT_DYNAMIC, _union, 1, 1); |
| // ^a.intersection[b][options array] = array | // ^array.intersection[b][options array] = array |
| add_native_method("intersection", Method::CT_DYNAMIC, _intersection, 1, 2); | add_native_method("intersection", Method::CT_DYNAMIC, _intersection, 1, 2); |
| // ^a.intersects[b] = bool | // ^array.intersects[b] = bool |
| add_native_method("intersects", Method::CT_DYNAMIC, _intersects, 1, 1); | add_native_method("intersects", Method::CT_DYNAMIC, _intersects, 1, 1); |
| // ^a.delete[key] | // ^array.append[value;value] |
| add_native_method("append", Method::CT_DYNAMIC, _append, 1, 10000); | |
| // ^array.insert[index;value...] | |
| add_native_method("insert", Method::CT_DYNAMIC, _insert, 2, 10000); | |
| // ^array.delete[index] | |
| add_native_method("delete", Method::CT_DYNAMIC, _delete, 0, 1); | add_native_method("delete", Method::CT_DYNAMIC, _delete, 0, 1); |
| // ^a.contains[key] | // ^array.contains[index] |
| add_native_method("contains", Method::CT_DYNAMIC, _contains, 1, 1); | add_native_method("contains", Method::CT_DYNAMIC, _contains, 1, 1); |
| // backward | |
| add_native_method("contain", Method::CT_DYNAMIC, _contains, 1, 1); | |
| // ^array::sql[query][options array] | // ^array::sql[query][options array] |
| add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); | add_native_method("sql", Method::CT_DYNAMIC, _sql, 1, 2); |
| Line 472 MArray::MArray(): Methoded(VARRAY_TYPE) | Line 498 MArray::MArray(): Methoded(VARRAY_TYPE) |
| // ^array._count[] | // ^array._count[] |
| add_native_method("_count", Method::CT_DYNAMIC, _count, 0, 0); | add_native_method("_count", Method::CT_DYNAMIC, _count, 0, 0); |
| // ^array.foreach[key;value]{code}[delim] | // ^array.foreach[index;value]{code}[delim] |
| add_native_method("foreach", Method::CT_DYNAMIC, _foreach, 2+1, 2+1+1); | add_native_method("foreach", Method::CT_DYNAMIC, _foreach, 2+1, 2+1+1); |
| // ^array.sort[key;value]{string-key-maker}[[asc|desc]] | // ^array.sort[index;value]{string-key-maker}[[asc|desc]] |
| // ^array.sort[key;value](numeric-key-maker)[[asc|desc]] | // ^array.sort[index;value](numeric-key-maker)[[asc|desc]] |
| add_native_method("sort", Method::CT_DYNAMIC, _sort, 3, 4); | add_native_method("sort", Method::CT_DYNAMIC, _sort, 3, 4); |
| // ^array.select[key;value](bool-condition)[options array] | // ^array.select[index;value](bool-condition)[options hash] |
| add_native_method("select", Method::CT_DYNAMIC, _select, 3, 4); | add_native_method("select", Method::CT_DYNAMIC, _select, 3, 4); |
| // ^array.reverse[] | // ^array.reverse[] |
| add_native_method("reverse", Method::CT_DYNAMIC, _reverse, 0, 0); | add_native_method("reverse", Method::CT_DYNAMIC, _reverse, 0, 0); |
| // ^array._at[first|last[;'key'|'value'|'array']] | // ^array._at[first|last[;'key'|'value'|'hash']] |
| // ^array._at([-+]offset)[['key'|'value'|'array']] | // ^array._at([-+]offset)[['key'|'value'|'hash']] |
| add_native_method("_at", Method::CT_DYNAMIC, _at, 1, 2); | add_native_method("_at", Method::CT_DYNAMIC, _at, 1, 2); |
| // ^array.rename[from;to] | // ^array.rename[from;to] |