From fbb669f65fdaec09d12df694cf00cf2566633c58 Mon Sep 17 00:00:00 2001 From: Kim Woelders Date: Thu, 28 Dec 2006 10:24:53 +0000 Subject: [PATCH] Fix build with ecore (ecore_list_find implemented in ecore). SVN revision: 27581 --- src/e16-ecore_list.c | 61 ++++++++++++++++++++++++++++---------------- src/e16-ecore_list.h | 8 +++--- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/e16-ecore_list.c b/src/e16-ecore_list.c index 81123ba4..5f1978a5 100644 --- a/src/e16-ecore_list.c +++ b/src/e16-ecore_list.c @@ -105,6 +105,9 @@ static void *_ecore_list_goto_index(Ecore_List * list, int indx); static int _ecore_list_for_each(Ecore_List * list, Ecore_For_Each function, void *user_data); +static void *_ecore_list_find(Ecore_List * list, + Ecore_Compare_Cb function, + const void *user_data); /** * @defgroup Ecore_Data_List_Creation_Group List Creation/Destruction Functions @@ -276,9 +279,7 @@ static int _ecore_list_append_0(Ecore_List * list, Ecore_List_Node * end) { if (list->last) - { - list->last->next = end; - } + list->last->next = end; list->last = end; @@ -585,9 +586,7 @@ _ecore_list_remove_last(Ecore_List * list) { prev->next = NULL; if (list->current == old) - { - list->current = NULL; - } + list->current = NULL; } if (old) @@ -897,11 +896,44 @@ _ecore_list_for_each(Ecore_List * list, Ecore_For_Each function, return TRUE; } +/** + * Find data in @p list using the compare function @p func + * @param list The list. + * @param function The function to test each node of @p list with + * @param user_data Data to match against (used by @p function) + * @return the first matching data node, or NULL if none match + */ +EAPI void * +ecore_list_find(Ecore_List * list, Ecore_Compare_Cb function, + const void *user_data) +{ + CHECK_PARAM_POINTER_RETURN("list", list, NULL); + + return _ecore_list_find(list, function, user_data); +} + +/* The real meat of finding a node via a compare cb */ +static void * +_ecore_list_find(Ecore_List * list, Ecore_Compare_Cb function, + const void *user_data) +{ + void *value; + + if (!list || !function) + return NULL; + + _ecore_list_goto_first(list); + while ((value = _ecore_list_next(list)) != NULL) + if (!function(value, user_data)) + return value; + + return NULL; +} + /* Initialize a node to starting values */ EAPI int ecore_list_node_init(Ecore_List_Node * node) { - CHECK_PARAM_POINTER_RETURN("node", node, FALSE); node->next = NULL; @@ -964,21 +996,6 @@ ecore_list_node_destroy(Ecore_List_Node * node, Ecore_Free_Cb free_func) * E16 additions */ -EAPI void * -ecore_list_find(Ecore_List * list, Ecore_Match function, const void *match) -{ - void *data; - - if (!list || !function) - return NULL; - - for (_ecore_list_goto_first(list); (data = _ecore_list_next(list)) != NULL;) - if (!function(data, match)) - return data; - - return NULL; -} - EAPI void * ecore_list_remove_node(Ecore_List * list, void *_data) { diff --git a/src/e16-ecore_list.h b/src/e16-ecore_list.h index 6ec2ca05..581903de 100644 --- a/src/e16-ecore_list.h +++ b/src/e16-ecore_list.h @@ -45,6 +45,7 @@ typedef struct _ecore_list Ecore_List; typedef struct _ecore_list_node Ecore_List_Node; +typedef int (*Ecore_Compare_Cb) (const void *data, const void *match); typedef void (*Ecore_For_Each) (void *value, void *user_data); typedef void (*Ecore_Free_Cb) (void *data); @@ -79,6 +80,9 @@ EAPI void *ecore_list_goto(Ecore_List * list, void *_data); /* Traversing the list and returning data */ EAPI void *ecore_list_next(Ecore_List * list); +EAPI void *ecore_list_find(Ecore_List * list, + Ecore_Compare_Cb function, + const void *match); /* Check to see if there is any data in the list */ EAPI int ecore_list_is_empty(Ecore_List * list); @@ -106,11 +110,7 @@ EAPI int ecore_list_set_free_cb(Ecore_List * list, #define ECORE_LIST_FOR_EACH(list, p) \ for (ecore_list_goto_first(list); (p = ecore_list_next(list)) != NULL;) -typedef int (*Ecore_Match) (const void *data, const void *match); - EAPI void *ecore_list_remove_node(Ecore_List * list, void *_data); -EAPI void *ecore_list_find(Ecore_List * list, - Ecore_Match function, const void *match); EAPI void **ecore_list_items_get(Ecore_List * list, int *pnum); #endif /* _E16_ECORE_LIST_H_ */