eina_inlist_03.c

- Main Page
- Related Pages
- Modules
- Data Structures
- Files
- Examples

eina_inlist_03.c
// Compile with:
// gcc -g eina_inlist_03.c -o eina_inlist_03 `pkg-config --cflags --libs eina`
#include <Eina.h>
#include <stdio.h>
struct my_struct {
EINA_INLIST;
Eina_Inlist even;
int a, b;
};
#define EVEN_INLIST_GET(Inlist) (& ((Inlist)->even))
#define EVEN_INLIST_CONTAINER_GET(ptr, type) \
((type *)((char *)ptr - offsetof(type, even)))
int
main(void)
{
struct my_struct *d, *cur;
int i;
Eina_Inlist *list = NULL, *list_even = NULL, *itr;
eina_init();
for (i = 0; i < 100; i++)
{
d = malloc(sizeof(*d));
d->a = i;
d->b = i * 10;
list = eina_inlist_append(list, EINA_INLIST_GET(d));
if ((i % 2) == 0)
list_even = eina_inlist_prepend(list_even, EVEN_INLIST_GET(d));
}
printf("list=%p\n", list);
EINA_INLIST_FOREACH(list, cur)
printf("\ta=%d, b=%d\n", cur->a, cur->b);
printf("list_even=%p\n", list_even);
for (itr = list_even; itr != NULL; itr = itr->next)
{
cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct);
printf("\ta=%d, b=%d\n", cur->a, cur->b);
}
printf("list count=%d\n", eina_inlist_count(list));
printf("list_even count=%d\n\n", eina_inlist_count(list_even));
itr = list_even;
while (itr)
{
Eina_Inlist *next = itr->next;
cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct);
if ((cur->a % 3) == 0)
list_even = eina_inlist_remove(list_even, itr);
itr = next;
}
printf("list count=%d\n", eina_inlist_count(list));
printf("list_even count=%d\n\n", eina_inlist_count(list_even));
while (list)
{
struct my_struct *aux = EINA_INLIST_CONTAINER_GET(list,
struct my_struct);
list = eina_inlist_remove(list, list);
free(aux);
}
eina_shutdown();
return 0;
}
Eina.h
Eina Utility library.
eina_inlist_prepend
EINA_API Eina_Inlist * eina_inlist_prepend(Eina_Inlist *list, Eina_Inlist *new_l)
Adds a new node to beginning of list.
Definition: eina_inlist.c:254
eina_inlist_count
EINA_API unsigned int eina_inlist_count(const Eina_Inlist *list)
Gets the count of the number of items in a list.
Definition: eina_inlist.c:448
EINA_INLIST_GET
#define EINA_INLIST_GET(Inlist)
Utility macro to get the inlist object of a struct.
Definition: eina_inlist.h:413
EINA_INLIST_FOREACH
#define EINA_INLIST_FOREACH(list, it)
Definition: eina_inlist.h:832
EINA_INLIST_CONTAINER_GET
#define EINA_INLIST_CONTAINER_GET(ptr, type)
Utility macro to get the container object of an inlist.
Definition: eina_inlist.h:415
EINA_INLIST
#define EINA_INLIST
Used for declaring an inlist member in a struct.
Definition: eina_inlist.h:411
eina_inlist_append
EINA_API Eina_Inlist * eina_inlist_append(Eina_Inlist *list, Eina_Inlist *new_l)
Adds a new node to end of a list.
Definition: eina_inlist.c:227
eina_inlist_remove
EINA_API Eina_Inlist * eina_inlist_remove(Eina_Inlist *list, Eina_Inlist *item)
Removes node from list.
Definition: eina_inlist.c:335
eina_shutdown
EINA_API int eina_shutdown(void)
Shuts down the Eina library.
Definition: eina_main.c:379
eina_init
EINA_API int eina_init(void)
Initializes the Eina library.
Definition: eina_main.c:291
_Eina_Inlist
Inlined list type.
Definition: eina_inlist.h:405
_Eina_Inlist::next
Eina_Inlist * next
next node
Definition: eina_inlist.h:406