eina_inlist_02.c Eina_Inlist advanced usage - lists and inlists source
// Compile with:
// gcc -g eina_inlist_02.c -o eina_inlist_02 `pkg-config --cflags --libs eina`
#include <Eina.h>
#include <stdio.h>
struct my_struct {
int a, b;
};
int
main(void)
{
struct my_struct *d, *cur;
int i;
Eina_Inlist *inlist = NULL;
Eina_List *list = NULL, *l_itr, *l_next;
eina_init();
for (i = 0; i < 100; i++)
{
d = malloc(sizeof(*d));
d->a = i;
d->b = i * 10;
inlist = eina_inlist_append(inlist, EINA_INLIST_GET(d));
if ((i % 2) == 0)
list = eina_list_prepend(list, d);
}
printf("inlist=%p\n", inlist);
EINA_INLIST_FOREACH(inlist, cur)
printf("\ta=%d, b=%d\n", cur->a, cur->b);
printf("list=%p\n", list);
EINA_LIST_FOREACH(list, l_itr, cur)
printf("\ta=%d, b=%d\n", cur->a, cur->b);
printf("inlist count=%d\n", eina_inlist_count(inlist));
printf("list count=%d\n\n", eina_list_count(list));
EINA_LIST_FOREACH_SAFE(list, l_itr, l_next, cur)
{
if ((cur->a % 3) == 0)
list = eina_list_remove_list(list, l_itr);
}
printf("inlist count=%d\n", eina_inlist_count(inlist));
printf("list count=%d\n\n", eina_list_count(list));
eina_list_free(list);
while (inlist)
{
struct my_struct *aux = EINA_INLIST_CONTAINER_GET(inlist,
struct my_struct);
inlist = eina_inlist_remove(inlist, inlist);
free(aux);
}
return 0;
}
Eina Utility library.
Eina_Inlist * eina_inlist_append(Eina_Inlist *in_list, Eina_Inlist *in_item)
Add a new node to end of a list.
Definition eina_inlist.c:222
unsigned int eina_inlist_count(const Eina_Inlist *list)
Get the count of the number of items in a list.
Definition eina_inlist.c:443
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition eina_inlist.h:415
#define EINA_INLIST_CONTAINER_GET(ptr, type)
Utility macro to get the container object of an inlist.
Definition eina_inlist.h:417
#define EINA_INLIST
Used for declaring an inlist member in a struct.
Definition eina_inlist.h:413
Eina_Inlist * eina_inlist_remove(Eina_Inlist *in_list, Eina_Inlist *in_item)
Remove node from list.
Definition eina_inlist.c:330
#define EINA_INLIST_FOREACH(list, l)
Macro to iterate over an inlist.
Definition eina_inlist.h:794
static unsigned int eina_list_count(const Eina_List *list)
Get the count of the number of items in a list.
Eina_List * eina_list_free(Eina_List *list)
Free an entire list and all the nodes, ignoring the data contained.
Definition eina_list.c:754
#define EINA_LIST_FOREACH_SAFE(list, l, l_next, data)
Macro to iterate over a list with support for node deletion.
Definition eina_list.h:1509
struct _Eina_List Eina_List
Type for a generic double linked list.
Definition eina_list.h:307
Eina_List * eina_list_remove_list(Eina_List *list, Eina_List *remove_list)
Remove the specified list node.
Definition eina_list.c:720
#define EINA_LIST_FOREACH(list, l, data)
Macro to iterate over a list.
Definition eina_list.h:1399
Eina_List * eina_list_prepend(Eina_List *list, const void *data)
Prepends the given data to the given linked list.
Definition eina_list.c:560