diff options
| author | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-27 20:50:39 +0100 |
|---|---|---|
| committer | Jonas Kümmerlin <jonas@kuemmerlin.eu> | 2018-12-27 20:50:39 +0100 |
| commit | b0b0e97aa5a06b22768bb9c9ea5e8caf383d78a4 (patch) | |
| tree | 8432ca1d8bf811bc7de6240e5988fb84e35b1f40 /alf/alflist.h | |
| parent | 64b6b40ace30693f0e12d56799abc40c997df07c (diff) | |
split into multiple files
Diffstat (limited to 'alf/alflist.h')
| -rw-r--r-- | alf/alflist.h | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/alf/alflist.h b/alf/alflist.h new file mode 100644 index 0000000..e0de033 --- /dev/null +++ b/alf/alflist.h @@ -0,0 +1,50 @@ + +typedef struct ALFListHeader { + struct ALFListHeader *prev; + struct ALFListHeader *next; +} ALFListHeader; + +#define ALF_LIST_CONTAINER(ContainerType, containermember, listp) \ + ((ContainerType *)((char *)(listp) - offsetof(ContainerType, containermember))) + +#define ALF_FOR_LIST(ContainerType, containermember, listp, iteratorvar) \ + for (ALFListHeader *alf_list_##iteratorvar##_curr = (listp)->next, \ + *alf_list_##iteratorvar##_next = alf_list_##iteratorvar##_curr->next; \ + alf_list_##iteratorvar##_curr != (listp); \ + alf_list_##iteratorvar##_curr = alf_list_##iteratorvar##_next, \ + alf_list_##iteratorvar##_next = alf_list_##iteratorvar##_next->next) \ + for (ContainerType *iteratorvar = (ContainerType *)((char *)alf_list_##iteratorvar##_curr - offsetof(ContainerType, containermember)); \ + iteratorvar; iteratorvar = NULL) \ + + +static inline BOOL +ALF_ListIsEmpty(ALFListHeader *list) +{ + return list->next == list; +} + +static inline void +ALF_ListInsert(ALFListHeader *list, ALFListHeader *newel) +{ + newel->prev = list; + newel->next = list->next; + newel->next->prev = newel; + list->next = newel; +} + +static inline void +ALF_ListRemove(ALFListHeader *member) +{ + member->prev->next = member->next; + member->next->prev = member->prev; + member->next = NULL; + member->prev = NULL; +} + +static inline void +ALF_ListInit(ALFListHeader *list) +{ + list->next = list->prev = list; +} + + |
