89 lines
1.5 KiB
C
89 lines
1.5 KiB
C
#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);
|
|
}
|
|
|
|
void vclear(var v)
|
|
{
|
|
meta_obj_t* obj = NULL;
|
|
vclear_fn_t method = NULL;
|
|
|
|
obj = RTTI_DATA_TO_OBJ(v);
|
|
if (RTTI_OBJ_INVALID(obj)) {
|
|
errno = EINVAL;
|
|
return;
|
|
}
|
|
|
|
RTTI_GET_METHOD(method, obj, varray, vclear);
|
|
if (method == NULL) {
|
|
errno = EINVAL;
|
|
|
|
return;
|
|
}
|
|
|
|
method(obj);
|
|
|
|
return;
|
|
}
|