diff options
Diffstat (limited to 'libraries/eina/src/examples/eina_iterator_01.c')
-rw-r--r-- | libraries/eina/src/examples/eina_iterator_01.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/libraries/eina/src/examples/eina_iterator_01.c b/libraries/eina/src/examples/eina_iterator_01.c new file mode 100644 index 0000000..f467f90 --- /dev/null +++ b/libraries/eina/src/examples/eina_iterator_01.c | |||
@@ -0,0 +1,66 @@ | |||
1 | //Compile with: | ||
2 | //gcc -g `pkg-config --cflags --libs eina` eina_iterator_01.c -o eina_iterator_01 | ||
3 | |||
4 | #include <stdio.h> | ||
5 | |||
6 | #include <Eina.h> | ||
7 | |||
8 | static Eina_Bool | ||
9 | print_one(const void *container, void *data, void *fdata) | ||
10 | { | ||
11 | printf("%s\n", (char*)data); | ||
12 | return EINA_TRUE; | ||
13 | } | ||
14 | |||
15 | static void | ||
16 | print_eina_container(Eina_Iterator *it) | ||
17 | { | ||
18 | eina_iterator_foreach(it, print_one, NULL); | ||
19 | printf("\n"); | ||
20 | } | ||
21 | |||
22 | int | ||
23 | main(int argc, char **argv) | ||
24 | { | ||
25 | const char *strings[] = { | ||
26 | "unintersting string", "husker", "starbuck", "husker" | ||
27 | }; | ||
28 | const char *more_strings[] = { | ||
29 | "very unintersting string", | ||
30 | "what do your hear?", | ||
31 | "nothing but the rain", | ||
32 | "then grab your gun and bring the cat in" | ||
33 | }; | ||
34 | Eina_Array *array; | ||
35 | Eina_List *list = NULL; | ||
36 | Eina_Iterator *it; | ||
37 | unsigned short int i; | ||
38 | char *uninteresting; | ||
39 | |||
40 | eina_init(); | ||
41 | |||
42 | array = eina_array_new(4); | ||
43 | |||
44 | for (i = 0; i < 4; i++) | ||
45 | { | ||
46 | eina_array_push(array, strings[i]); | ||
47 | list = eina_list_append(list, more_strings[i]); | ||
48 | } | ||
49 | |||
50 | it = eina_array_iterator_new(array); | ||
51 | eina_iterator_next(it, &uninteresting); | ||
52 | print_eina_container(it); | ||
53 | eina_array_free(eina_iterator_container_get(it)); | ||
54 | eina_iterator_free(it); | ||
55 | |||
56 | it = eina_list_iterator_new(list); | ||
57 | eina_iterator_next(it, &uninteresting); | ||
58 | print_eina_container(it); | ||
59 | eina_iterator_free(it); | ||
60 | |||
61 | eina_list_free(list); | ||
62 | |||
63 | eina_shutdown(); | ||
64 | |||
65 | return 0; | ||
66 | } | ||