Skip to content

Commit

Permalink
export type functions
Browse files Browse the repository at this point in the history
  • Loading branch information
recp committed Jul 14, 2020
1 parent b50823a commit 3ccafcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions include/ak/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,33 @@ typedef struct AkTypeDesc {
int userData;
} AkTypeDesc;

AK_EXPORT
AkTypeId
ak_typeid(void * __restrict mem);

AK_EXPORT
AkTypeId
ak_typeidh(AkHeapNode * __restrict hnode);

AK_EXPORT
void
ak_setypeid(void * __restrict mem,
AkTypeId tid);

AK_EXPORT
bool
ak_isKindOf(void * __restrict mem,
void * __restrict other);

AK_EXPORT
AkTypeDesc*
ak_typeDesc(AkTypeId typeId);

AK_EXPORT
AkTypeDesc*
ak_typeDescByName(const char * __restrict name);

AK_EXPORT
void
ak_registerType(AkTypeId typeId, AkTypeDesc *desc);

Expand Down
22 changes: 20 additions & 2 deletions src/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

#include <ds/rb.h>

RBTree *ak__typetree = NULL;
RBTree *ak__typetree = NULL;
RBTree *ak__typetree_byname = NULL;

AK_EXPORT
AkTypeId
ak_typeidh(AkHeapNode * __restrict hnode) {
return hnode->typeid;
}

AK_EXPORT
AkTypeId
ak_typeid(void * __restrict mem) {
AkHeapNode *hnode;
Expand All @@ -36,6 +39,7 @@ ak_typeid(void * __restrict mem) {
return hnode->typeid;
}

AK_EXPORT
void
ak_setypeid(void * __restrict mem,
AkTypeId tid) {
Expand All @@ -45,6 +49,7 @@ ak_setypeid(void * __restrict mem,
hnode->typeid = tid;
}

AK_EXPORT
bool
ak_isKindOf(void * __restrict mem,
void * __restrict other) {
Expand All @@ -59,21 +64,33 @@ ak_isKindOf(void * __restrict mem,
return hnode1->typeid == hnode2->typeid;
}

AK_EXPORT
AkTypeDesc*
ak_typeDesc(AkTypeId typeId) {
return rb_find(ak__typetree, (void *)typeId);
}

AK_EXPORT
AkTypeDesc*
ak_typeDescByName(const char * __restrict name) {
return rb_find(ak__typetree_byname, (void *)name);
}

AK_EXPORT
void
ak_registerType(AkTypeId typeId, AkTypeDesc *desc) {
rb_insert(ak__typetree, (void *)typeId, desc);

if (desc->typeName)
rb_insert(ak__typetree_byname, (void *)desc->typeName, desc);
}

void _assetkit_hide
ak_type_init() {
AkTypeDesc *it;

ak__typetree = rb_newtree(NULL, ds_cmp_i32p, NULL);
ak__typetree = rb_newtree(NULL, ds_cmp_i32p, NULL);
ak__typetree_byname = rb_newtree(NULL, ds_cmp_str, NULL);

/* register predefined type descs */
it = (AkTypeDesc *)ak_def_typedesc();
Expand All @@ -88,4 +105,5 @@ ak_type_init() {
void _assetkit_hide
ak_type_deinit() {
rb_destroy(ak__typetree);
rb_destroy(ak__typetree_byname);
}

0 comments on commit 3ccafcd

Please sign in to comment.