diff options
author | Michal Jagiello <m.jagiello@samsung.com> | 2015-03-25 19:29:49 +0100 |
---|---|---|
committer | Cedric BAIL <cedric@osg.samsung.com> | 2015-03-25 19:40:41 +0100 |
commit | 6b8824680888abc16e5e300ab75e383550670262 (patch) | |
tree | 039d52bbd1dc2e9bd4c9d89e3e9f29a899ded8af | |
parent | cf27288b505b5745493c01caa85b0103749c96d7 (diff) | |
download | efl-6b8824680888abc16e5e300ab75e383550670262.tar.gz |
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>
-rw-r--r-- | src/lib/eina/eina_list.c | 20 | ||||
-rw-r--r-- | src/lib/eina/eina_list.h | 16 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/eina/eina_list.c b/src/lib/eina/eina_list.c index e1088b0d33..6a73243335 100644 --- a/src/lib/eina/eina_list.c +++ b/src/lib/eina/eina_list.c @@ -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; +} diff --git a/src/lib/eina/eina_list.h b/src/lib/eina/eina_list.h index 91de6ea08c..9d3bb90310 100644 --- a/src/lib/eina/eina_list.h +++ b/src/lib/eina/eina_list.h @@ -1345,6 +1345,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. * |