add varray api
This commit is contained in:
parent
c1e4069706
commit
30f7f4475f
3 changed files with 85 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ librtti_c_srcs=[
|
|||
'length.c',
|
||||
'bitmap.c',
|
||||
'kv.c',
|
||||
'varray.c',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
66
src/varray.c
Normal file
66
src/varray.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "rtti.h"
|
||||
|
||||
int vstore(var v, void* data)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
vstore_fn_t method = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, varray, vstore);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, data);
|
||||
}
|
||||
|
||||
int vget(var v, int idx, void** data)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
vget_fn_t method = NULL;
|
||||
|
||||
if ((idx < 0) || (data == NULL)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, varray, vget);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, idx, data);
|
||||
}
|
||||
|
||||
int vput(var v, int idx, void* data)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
vput_fn_t method = NULL;
|
||||
|
||||
if (idx < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, varray, vput);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, idx, data);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue