use class Arg instead of __arg

This commit is contained in:
lyon 2022-05-22 20:50:28 +08:00
parent 64730bca8f
commit 77267cff07
3 changed files with 41 additions and 39 deletions

View File

@ -11,7 +11,7 @@ TEST(content, init) {
contentIn[1] = 2;
contentIn[2] = 3;
contentIn[3] = 4;
uint8_t* self = content_init("name", ARG_TYPE_NONE, contentIn, 4, NULL);
Arg* self = content_init("name", ARG_TYPE_NONE, contentIn, 4, NULL);
uint16_t typeOffset = content_typeOffset(self);
uint16_t sizeOffset = content_sizeOffset(self);
@ -46,7 +46,7 @@ TEST(content, set) {
contentIn[1] = 2;
contentIn[2] = 3;
contentIn[3] = 4;
uint8_t* self = content_init("", ARG_TYPE_NONE, NULL, 0, NULL);
Arg* self = content_init("", ARG_TYPE_NONE, NULL, 0, NULL);
self = content_setName(self, "name");
self = content_setType(self, ARG_TYPE_NONE);
self = content_setContent(self, contentIn, 4);

View File

@ -53,9 +53,9 @@ static uint8_t* content_init_hash(Hash nameHash,
uint8_t* content,
uint32_t size,
uint8_t* next) {
__arg* self = (__arg*)pikaMalloc(sizeof(__arg) + size);
Arg* self = (Arg*)pikaMalloc(sizeof(Arg) + size);
self->next = (__arg*)next;
self->next = (Arg*)next;
self->size = size;
self->name_hash = nameHash;
self->type = type;
@ -77,8 +77,8 @@ static uint8_t* content_init(char* name,
return content_init_hash(nameHash, type, content, size, next);
}
uint16_t content_totleSize(uint8_t* self) {
return ((__arg*)self)->size + sizeof(__arg);
uint16_t content_totleSize(Arg* self) {
return ((Arg*)self)->size + sizeof(Arg);
}
void arg_freeContent(Arg* self) {
@ -87,13 +87,13 @@ void arg_freeContent(Arg* self) {
}
}
uint8_t* content_deinit(uint8_t* self) {
uint8_t* content_deinit(Arg* self) {
uint16_t totleSize = content_totleSize(self);
pikaFree(self, totleSize);
return 0;
}
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
uint8_t* content_setContent(Arg* self, uint8_t* content, uint16_t size) {
if (NULL == self) {
/* malloc */
return content_init("", ARG_TYPE_VOID, content, size, NULL);
@ -101,7 +101,7 @@ uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
/* only copy */
if (content_getSize(self) == size) {
__platform_memcpy(((__arg*)self)->content, content, size);
__platform_memcpy(((Arg*)self)->content, content, size);
return self;
}
@ -115,32 +115,32 @@ uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size) {
return newContent;
}
uint8_t* content_setNameHash(uint8_t* self, Hash nameHash) {
uint8_t* content_setNameHash(Arg* self, Hash nameHash) {
if (NULL == self) {
return content_init_hash(nameHash, ARG_TYPE_VOID, NULL, 0, NULL);
}
__arg* arg = (__arg*)self;
Arg* arg = (Arg*)self;
arg->name_hash = nameHash;
return self;
}
uint8_t* content_setName(uint8_t* self, char* name) {
uint8_t* content_setName(Arg* self, char* name) {
return content_setNameHash(self, hash_time33(name));
}
uint8_t* content_setType(uint8_t* self, ArgType type) {
uint8_t* content_setType(Arg* self, ArgType type) {
if (NULL == self) {
return content_init("", type, NULL, 0, NULL);
}
__arg* arg = (__arg*)self;
Arg* arg = (Arg*)self;
arg->type = type;
return self;
}
ArgType content_getType(uint8_t* self) {
__arg* arg = (__arg*)self;
ArgType content_getType(Arg* self) {
Arg* arg = (Arg*)self;
return (ArgType)arg->type;
}
@ -254,7 +254,7 @@ float arg_getFloat(Arg* self) {
return -999.999;
}
return *(float*)(((__arg*)self)->content);
return *(float*)(((Arg*)self)->content);
}
Arg* arg_setPtr(Arg* self, char* name, ArgType type, void* pointer) {
@ -271,14 +271,14 @@ int64_t arg_getInt(Arg* self) {
if (NULL == arg_getContent(self)) {
return -999999;
}
return *(int64_t*)(((__arg*)self)->content);
return *(int64_t*)(((Arg*)self)->content);
}
void* arg_getPtr(Arg* self) {
if (NULL == arg_getContent(self)) {
return NULL;
}
return *(void**)(((__arg*)self)->content);
return *(void**)(((Arg*)self)->content);
}
char* arg_getStr(Arg* self) {
return (char*)arg_getContent(self);
@ -400,23 +400,23 @@ void arg_deinit(Arg* self) {
}
Hash content_getNameHash(Arg* self) {
return ((__arg*)self)->name_hash;
return ((Arg*)self)->name_hash;
}
Arg* content_getNext(Arg* self) {
return (Arg*)(((__arg*)self)->next);
return (Arg*)(((Arg*)self)->next);
}
uint16_t content_getSize(Arg* self) {
return ((__arg*)self)->size;
return ((Arg*)self)->size;
}
uint8_t* content_getContent(Arg* self) {
return ((__arg*)self)->content;
return ((Arg*)self)->content;
}
void content_setNext(Arg* self, uint8_t* next) {
((__arg*)self)->next = (__arg*)(next);
((Arg*)self)->next = (Arg*)(next);
}
uint8_t* arg_getContent(Arg* self) {

View File

@ -68,26 +68,28 @@ typedef enum {
typedef void (*StructDeinitFun)(void* struct_);
typedef struct __arg __arg;
def_class(__arg,
private_member(__arg* next; uint16_t size; uint8_t type;
dcl_class(Arg)
def_class(Arg,
private_member(
Arg* next;
uint16_t size; uint8_t type;
uint8_t ref_cnt;
Hash name_hash;
uint8_t content[];));
typedef uint8_t Arg;
uint8_t content[];
)
);
Hash content_getNameHash(Arg* self);
ArgType content_getType(uint8_t* self);
ArgType content_getType(Arg* self);
Arg* content_getNext(Arg* self);
uint16_t content_getSize(Arg* self);
uint8_t* content_getContent(Arg* self);
uint16_t content_totleSize(uint8_t* self);
uint8_t* content_deinit(uint8_t* self);
uint8_t* content_setName(uint8_t* self, char* name);
uint8_t* content_setType(uint8_t* self, ArgType type);
uint8_t* content_setContent(uint8_t* self, uint8_t* content, uint16_t size);
void content_setNext(uint8_t* self, uint8_t* next);
uint16_t content_totleSize(Arg* self);
uint8_t* content_deinit(Arg* self);
uint8_t* content_setName(Arg* self, char* name);
uint8_t* content_setType(Arg* self, ArgType type);
uint8_t* content_setContent(Arg* self, uint8_t* content, uint16_t size);
void content_setNext(Arg* self, uint8_t* next);
uint16_t arg_getTotleSize(Arg* self);
void arg_freeContent(Arg* self);