add bitmap interface and fix toString()
This commit is contained in:
parent
00080a95f3
commit
ecb1162069
4 changed files with 94 additions and 2 deletions
77
src/bitmap.c
Normal file
77
src/bitmap.c
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rtti.h"
|
||||
|
||||
int bit_test(var v, unsigned long idx)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
bit_test_fn_t method = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, bitmap, test);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, idx);
|
||||
}
|
||||
|
||||
int bit_set(var v, unsigned long idx)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
bit_test_fn_t method = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, bitmap, set);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, idx);
|
||||
}
|
||||
|
||||
int bit_clr(var v, unsigned long idx)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
bit_test_fn_t method = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, bitmap, clr);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj, idx);
|
||||
}
|
||||
|
||||
int bit_clrall(var v)
|
||||
{
|
||||
meta_obj_t* obj = NULL;
|
||||
bit_test_fn_t method = NULL;
|
||||
|
||||
obj = RTTI_DATA_TO_OBJ(v);
|
||||
if (RTTI_OBJ_INVALID(obj)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
RTTI_GET_METHOD(method, obj, bitmap, clrall);
|
||||
if (method == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return method(obj);
|
||||
}
|
||||
|
|
@ -8,6 +8,7 @@ librtti_c_srcs=[
|
|||
'str.c',
|
||||
'hash.c',
|
||||
'length.c',
|
||||
'bitmap.c',
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ char* toString(var v, ...)
|
|||
}
|
||||
|
||||
va_start(ap, v);
|
||||
s = method(v, ap);
|
||||
s = method(obj, ap);
|
||||
va_end(ap);
|
||||
|
||||
return s;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue