diff options
Diffstat (limited to 'libraries/eina/src/examples/eina_inlist_03.c')
-rw-r--r-- | libraries/eina/src/examples/eina_inlist_03.c | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/libraries/eina/src/examples/eina_inlist_03.c b/libraries/eina/src/examples/eina_inlist_03.c deleted file mode 100644 index 28706d5..0000000 --- a/libraries/eina/src/examples/eina_inlist_03.c +++ /dev/null | |||
@@ -1,74 +0,0 @@ | |||
1 | // Compile with: | ||
2 | // gcc -g eina_inlist_03.c -o eina_inlist_03 `pkg-config --cflags --libs eina` | ||
3 | |||
4 | #include <Eina.h> | ||
5 | #include <stdio.h> | ||
6 | |||
7 | struct my_struct { | ||
8 | EINA_INLIST; | ||
9 | Eina_Inlist even; | ||
10 | int a, b; | ||
11 | }; | ||
12 | |||
13 | #define EVEN_INLIST_GET(Inlist) (& ((Inlist)->even)) | ||
14 | |||
15 | #define EVEN_INLIST_CONTAINER_GET(ptr, type) \ | ||
16 | ((type *)((char *)ptr - offsetof(type, even))) | ||
17 | |||
18 | int | ||
19 | main(void) | ||
20 | { | ||
21 | struct my_struct *d, *cur; | ||
22 | int i; | ||
23 | |||
24 | Eina_Inlist *list = NULL, *list_even = NULL, *itr; | ||
25 | |||
26 | eina_init(); | ||
27 | |||
28 | for (i = 0; i < 100; i++) | ||
29 | { | ||
30 | d = malloc(sizeof(*d)); | ||
31 | d->a = i; | ||
32 | d->b = i * 10; | ||
33 | list = eina_inlist_append(list, EINA_INLIST_GET(d)); | ||
34 | if ((i % 2) == 0) | ||
35 | list_even = eina_inlist_prepend(list_even, EVEN_INLIST_GET(d)); | ||
36 | } | ||
37 | |||
38 | printf("list=%p\n", list); | ||
39 | EINA_INLIST_FOREACH(list, cur) | ||
40 | printf("\ta=%d, b=%d\n", cur->a, cur->b); | ||
41 | |||
42 | printf("list_even=%p\n", list_even); | ||
43 | for (itr = list_even; itr != NULL; itr = itr->next) | ||
44 | { | ||
45 | cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct); | ||
46 | printf("\ta=%d, b=%d\n", cur->a, cur->b); | ||
47 | } | ||
48 | |||
49 | printf("list count=%d\n", eina_inlist_count(list)); | ||
50 | printf("list_even count=%d\n\n", eina_inlist_count(list_even)); | ||
51 | |||
52 | itr = list_even; | ||
53 | while (itr) | ||
54 | { | ||
55 | Eina_Inlist *next = itr->next; | ||
56 | cur = EVEN_INLIST_CONTAINER_GET(itr, struct my_struct); | ||
57 | if ((cur->a % 3) == 0) | ||
58 | list_even = eina_inlist_remove(list_even, itr); | ||
59 | itr = next; | ||
60 | } | ||
61 | printf("list count=%d\n", eina_inlist_count(list)); | ||
62 | printf("list_even count=%d\n\n", eina_inlist_count(list_even)); | ||
63 | |||
64 | while (list) | ||
65 | { | ||
66 | Eina_Inlist *aux = list; | ||
67 | list = eina_inlist_remove(list, list); | ||
68 | free(aux); | ||
69 | } | ||
70 | |||
71 | eina_shutdown(); | ||
72 | |||
73 | return 0; | ||
74 | } | ||