44 #define KSI_LIST(type) type##List
51 #define KSI_NEW_LIST(type, list) KSI_List_new(type##_free, (list))
58 #define KSI_NEW_REFLIST(type, list) KSI_RefList_new(type##_free, type##_ref, (list))
65 #define KSI_LIST_FN_NAME(type, name) type##List_##name
67 #define KSI_DEFINE_LIST_STRUCT(ltype, rtype) \
75 int (*append)(ltype *, rtype *); \
85 int (*removeElement)(ltype *, size_t, rtype **); \
93 int (*indexOf)(ltype *, rtype *, size_t **); \
103 int (*insertAt)(ltype *, size_t, rtype *); \
113 int (*replaceAt)(ltype *, size_t, rtype *); \
122 int (*elementAt)(ltype *, size_t pos, rtype **); \
127 size_t (*length)(ltype *list); \
128 void (*obj_free)(rtype *); \
133 int (*sort)(ltype *list, int (*cmp)(const rtype **, const rtype **)); \
140 int (*foldl)(ltype *list, void *foldCtx, int (*fn)(rtype *el, void *foldCtx)); \
153 int (*find)(ltype *list, rtype *el, int *found, size_t *pos); \
159 #define KSI_DEFINE_LIST(type) \
160 typedef struct type##_list_st KSI_LIST(type); \
161 struct type##_list_st { \
162 KSI_DEFINE_LIST_STRUCT(KSI_LIST(type), type) \
164 int KSI_LIST_FN_NAME(type, new)(KSI_LIST(type) **list); \
165 void KSI_LIST_FN_NAME(type, free)(KSI_LIST(type) *list); \
186 #define KSI_IMPLEMENT_LIST(type, free_fn) \
187 int KSI_LIST_FN_NAME(type, new)(KSI_LIST(type) **list) { \
188 return KSI_List_new((void (*)(void *))free_fn, (KSI_List **)list); \
190 void KSI_LIST_FN_NAME(type, free)(KSI_LIST(type) *list) { \
191 KSI_List_free((KSI_List *)list); \
void KSI_List_free(KSI_List *list)
int KSI_List_indexOf(KSI_List *list, void *o, size_t **i)
int KSI_List_foldl(KSI_List *list, void *foldCtx, int(*fn)(void *el, void *foldCtx))
int KSI_List_remove(KSI_List *list, size_t pos, void **o)
int KSI_List_elementAt(KSI_List *list, size_t pos, void **o)
int KSI_List_find(KSI_List *list, void *el, int *found, size_t *pos)
size_t KSI_List_length(KSI_List *list)
int KSI_List_new(void(*obj_free)(void *), KSI_List **list)
int KSI_List_insertAt(KSI_List *list, size_t pos, void *o)
int KSI_List_sort(KSI_List *list, int(*)(const void **, const void **))
int KSI_List_append(KSI_List *list, void *o)
int KSI_List_replaceAt(KSI_List *list, size_t pos, void *o)
struct KSI_List_st KSI_List
Definition: list.h:38