#ifndef LISTH #define LISTH #include #include #include /* une fonction d erreur -> EXIT */ #define ErrExit(mesg) {fprintf(stderr, "Fatal: %s\n", (char *)(mesg)); exit(1);} typedef void * NODE; typedef int (*PFI)(); /* pointeur vers fonction retournant int */ /** * gestion de listes chainées génériques simplifiees * definition de la structure d'un élément d'une liste chainée */ typedef struct _Elt { NODE value; /**< le pointeur a stoquer */ struct _Elt * next; /**< l'élément suivant */ struct _Elt * previous; /**< l'élément précedent */ }Elt, *ptrElt; /** * définition de da structure de liste générique */ typedef struct { int count; /**< le nombre d'elements de la liste */ ptrElt first; /**< premier élément de la liste */ ptrElt last; /**< dernier élément de la liste */ ptrElt current; /**< courant élément (interne pour tri) */ } _List, *LIST; /** Constructor, creates an empty list * @return a new LIST */ LIST make_list(); /** Destroyer, free the list * @param list the list to free */ void free_list(LIST list); /** Sorts the list with a given function * @param list the list to sort * @param func a PFI function * @return the list sorted */ LIST sort_list_func(LIST list, PFI func); NODE search_list(LIST list, NODE node, PFI func); NODE search_list_ptr(LIST list, NODE ident, NODE var, NODE code, PFI func); /** Adds an element at the end of the list * @param list the list to add an element to * @param value the element to include * @return NODE the included element */ NODE add_to_tail(LIST list, NODE value); /** Deletes a node from th elist * @param list the list to delete an element from * @param node the node to destroy * @return NODE the destroyed node */ NODE delete_list_node(LIST list, NODE node); /** Use this to iterate in a list. * You have to use it like a "for" * i.e. : loop_through_list(list, ptr , type){...} * * @param list the LIST to iterate * @param ptr the pointer that will contain the extracted elements * @param type The type of the elements to extract */ #define loop_through_list( list, ptr , type) \ for ( (list)->current = (list)->first ,\ ptr = ((list)->current? (type)(list)->current->value: (type)NULL); \ (list)->current != NULL ; \ (list)->current= (list)->current->next, \ ptr = ((list)->current? (type)(list)->current->value: (type)NULL)) /** Retreive the last element from a list * @param list the LIST * @return NODE the last element */ #define get_list_tail( list ) \ ( (list) ? ((list)->last ? (list)->last->value: NULL) : NULL ) /** Retreive the first element from a list * @param list the LIST * @return NODE the first element */ #define get_list_head( list ) \ ( list ? (list->first ? list->first->value: NULL) : NULL ) /** Reurns the length of the list (the number of elements) * @param list the LIST * @return int the size of the list */ #define list_length( list ) (list)->count \ #endif