/** Prototypes for lists functions. */ #ifndef LIST_H #define LIST_H #include #include "pred.h" #ifdef __cplusplus extern "C" { #endif #ifndef NULL #define NULL ((void *)(0)) #endif /* NULL */ /* This is the LIST structure. - data - pointer to data element of list, - next - pointer to next element, - prev - pointer to previous element. You should only access elements marked as public, as implemenatation may change in the future. */ struct yetanotherclib_list { /* @@public */ void *data; /* pointer to data */ struct yetanotherclib_list *next; /* pointer to next element */ struct yetanotherclib_list *prev; /* pointer to previous element */ }; typedef struct yetanotherclib_list yacl_list; /* These are the inline initializers. which initialize the list structure. */ #define L_INIT(l) \ { \ (l).data = NULL; \ (l).next = NULL; \ (l).prev = NULL; \ } /* Initializes pointer to list struct. */ #define L_INIT_PTR(l) \ { \ (l)->data = NULL; \ (l)->next = NULL; \ (l)->prev = NULL; \ } /** Moves to the beginning of the list */ #define L_SEEK_BEGIN(l) \ { \ while( (l)->prev ) (l) = (l)->prev; \ } \ /** Moves to the end of the list */ #define L_SEEK_END(l) \ { \ while( (l)->next ) (l) = (l)->next; \ } \ /** Add to l new node and copies dane to data element. Element is inserted at the end of the list. Parameters: - l - pointer to list which we want to insert element, - dane - pointer to data which we want to be added, - r - size of data. Return values: - SUCCESS - ok, - ENOMEM - not enough memory. */ int l_insertEnd(yacl_list *l, const void *dane, size_t r); /** Add to l new element and copies data to it. Element is inserted at l->next. Parameters: - l - pointer to list, - data - data we want to add to list, - r - size of data. Return values: - SUCCESS - ok, - ENOMEM - not enough memory. */ int l_insertBegin(yacl_list *l, const void *data, size_t r); /** Searches list for element which cmp(l->data, data)==0 Parameters: - l - pointer to list which we want to search, - data - element to compare, - comp - pointer to comparison function. Return values: - NULL - element not found, - pointer to found element. */ yacl_list *l_findElem(yacl_list *l, const void *data, int (*yacl_binary_pred)(const void *, const void *)); /** Deletes from l element which cmp(l->data,data)==0. Parameters: - l - pointer to list, - data - data to compare, - comp, the comparison function. The comparison function compares each of the pointed-to items (*elem1 and *elem2), and returns an integer based on the result of the comparison. *elem1 < *elem2 comp returns an integer < 0 *elem1 == *elem2 comp returns 0 *elem1 > *elem2 comp returns an integer > 0 Return values: - YACL_SUCCESS- element was deleted, - YACL_FAILED - element was not found. */ int l_deleteElem(yacl_list *l, void *data, int (*comp)(const void *, const void *)); /** Frees all allocated memeory with l an assigns NULL value to (*l) parameter. Parameters: - l - pointer to pointer to list. */ void l_free(yacl_list **l); /* This function counts the number of items in a list. */ unsigned int l_items(yacl_list *l); int yacl_list_push(yacl_list *l,const void *data, size_t r); void * yacl_list_pop(yacl_list *l); /** true if the list is empty */ #define yacl_list_empty(ths) ((ths)->next!=NULL) yacl_list * yacl_list_clear(yacl_list *ths); void yacl_list_assign(yacl_list *ths, size_t num, const void *val, size_t val_size); yacl_list *yacl_list_back(yacl_list *ths); yacl_list *yacl_list_front(yacl_list *ths); void yacl_list_pop_back(yacl_list *ths); yacl_list * yacl_list_pop_front(yacl_list *ths); int yacl_list_push_back(yacl_list *ths, const void *val, size_t val_size); int yacl_list_push_front(yacl_list *ths, const void *val, size_t val_size); yacl_list * yacl_list_remove(yacl_list *ths, const void *val, size_t val_size); yacl_list * yacl_list_remove_if(yacl_list *ths, yacl_binary_pred cmp, const void *cmp_param); size_t yacl_list_size(yacl_list *ths); /* this functions below are not implemented yet void yacl_list_resize(yacl_list *ths, const void *val, size_t val_size); void yacl_list_reverse(yacl_list *ths); void yacl_list_sort(yacl_list *ths, yacl_binary_pred cmp); void yacl_list_swap(yacl_list *ths, yacl_list *lst); void yacl_list_unique(yacl_list *ths, yacl_binary_pred cmp); */ #ifdef __cplusplus } #endif #endif /* LIST_H */