eina: add eina_list_data_idx().

Summary:
Now the developer has to iterate the whole list to find the
index of the first occurence of the data.
I see that it is possible to get the index of the item for
the genlist widget, but for the eina_list not.

With these APIs it will be easier to implement *index_get
functions for the rest of widgets which contain items (Elm_List,
Elm_Ctxpopup etc.).

These functions returns the index of the given data or node in the eina_list.

Reviewers: Hermet, cedric

Subscribers: raster, cedric

Differential Revision: https://phab.enlightenment.org/D2189

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
Michal Jagiello 2015-03-25 19:29:49 +01:00 committed by Cedric BAIL
parent cf27288b50
commit 6b88246808
2 changed files with 36 additions and 0 deletions

View File

@ -1569,3 +1569,23 @@ eina_list_accessor_new(const Eina_List *list)
return &ac->accessor;
}
EAPI int
eina_list_data_idx(const Eina_List *list, void *data)
{
const Eina_List *l;
void *list_data;
int ret = 0;
if (!list) return -1;
EINA_MAGIC_CHECK_LIST(list, -1);
EINA_LIST_FOREACH(list, l, list_data)
{
if (list_data == data)
return ret;
ret++;
}
return -1;
}

View File

@ -1344,6 +1344,22 @@ EAPI Eina_Iterator *eina_list_iterator_reversed_new(const Eina_List *list
*/
EAPI Eina_Accessor *eina_list_accessor_new(const Eina_List *list) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
/**
* @brief Find the member of the list and return the index.
*
* @param list The list.
* @param data The data member.
* @return The index of data member if found, @c -1 otherwise.
*
* This function searches in @p list from beginning to end for the
* first member whose data pointer is @p data. If it is found, the
* index of the data will be returned, otherwise @c -1 will be returned.
*
* @warning @p list must be a pointer to the first element of the list.
*
*/
EAPI int eina_list_data_idx(const Eina_List *list, void *data);
/**
* @def EINA_LIST_FOREACH
* @brief Macro to iterate over a list.