summaryrefslogtreecommitdiff
path: root/legacy/eina
diff options
context:
space:
mode:
authorJonas M. Gastal <jgastal@profusion.mobi>2011-06-10 13:42:19 +0000
committerJonas M. Gastal <jgastal@profusion.mobi>2011-06-10 13:42:19 +0000
commit160fdb558fc215ce611fadeed04aa3eb30cb154d (patch)
treed8a394288aa5a0fd65c76548039a145cbd92cb27 /legacy/eina
parent11458e8e08da49592dadcc8ff721ac375dfb8ab7 (diff)
eina: Eina_Iterator documentation.
SVN revision: 60193
Diffstat (limited to 'legacy/eina')
-rw-r--r--legacy/eina/src/examples/Makefile.am2
-rw-r--r--legacy/eina/src/examples/eina_iterator_01.c66
-rw-r--r--legacy/eina/src/include/Eina.h1
-rw-r--r--legacy/eina/src/include/eina_iterator.h59
4 files changed, 128 insertions, 0 deletions
diff --git a/legacy/eina/src/examples/Makefile.am b/legacy/eina/src/examples/Makefile.am
index 3805eab41f..756dcffb27 100644
--- a/legacy/eina/src/examples/Makefile.am
+++ b/legacy/eina/src/examples/Makefile.am
@@ -15,6 +15,7 @@ SRCS = \
15 eina_array_02.c \ 15 eina_array_02.c \
16 eina_hash_01.c \ 16 eina_hash_01.c \
17 eina_hash_02.c \ 17 eina_hash_02.c \
18 eina_iterator_01.c \
18 eina_list_01.c \ 19 eina_list_01.c \
19 eina_list_02.c \ 20 eina_list_02.c \
20 eina_list_03.c \ 21 eina_list_03.c \
@@ -33,6 +34,7 @@ pkglib_PROGRAMS += \
33 eina_array_02 \ 34 eina_array_02 \
34 eina_hash_01 \ 35 eina_hash_01 \
35 eina_hash_02 \ 36 eina_hash_02 \
37 eina_iterator_01 \
36 eina_list_01 \ 38 eina_list_01 \
37 eina_list_02 \ 39 eina_list_02 \
38 eina_list_03 \ 40 eina_list_03 \
diff --git a/legacy/eina/src/examples/eina_iterator_01.c b/legacy/eina/src/examples/eina_iterator_01.c
new file mode 100644
index 0000000000..f467f9042d
--- /dev/null
+++ b/legacy/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
8static Eina_Bool
9print_one(const void *container, void *data, void *fdata)
10{
11 printf("%s\n", (char*)data);
12 return EINA_TRUE;
13}
14
15static void
16print_eina_container(Eina_Iterator *it)
17{
18 eina_iterator_foreach(it, print_one, NULL);
19 printf("\n");
20}
21
22int
23main(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}
diff --git a/legacy/eina/src/include/Eina.h b/legacy/eina/src/include/Eina.h
index 4fcba126ad..67ebea4601 100644
--- a/legacy/eina/src/include/Eina.h
+++ b/legacy/eina/src/include/Eina.h
@@ -71,6 +71,7 @@
71 * @li @ref Eina_Hash_Group standard hash of @c void* data. 71 * @li @ref Eina_Hash_Group standard hash of @c void* data.
72 * @li @ref Eina_Inline_List_Group list with nodes inlined into user type. 72 * @li @ref Eina_Inline_List_Group list with nodes inlined into user type.
73 * @li @ref Eina_List_Group standard list of @c void* data. 73 * @li @ref Eina_List_Group standard list of @c void* data.
74 * @li @ref Eina_Iterator_Group Iterator functions.
74 * @li @ref Eina_Matrixsparse_Group sparse matrix of @c void* data. 75 * @li @ref Eina_Matrixsparse_Group sparse matrix of @c void* data.
75 * @li @ref Eina_Rbtree_Group red-black tree with nodes inlined into user type. 76 * @li @ref Eina_Rbtree_Group red-black tree with nodes inlined into user type.
76 * @li @ref Eina_String_Buffer_Group mutable string to prepend, insert or append strings to a buffer. 77 * @li @ref Eina_String_Buffer_Group mutable string to prepend, insert or append strings to a buffer.
diff --git a/legacy/eina/src/include/eina_iterator.h b/legacy/eina/src/include/eina_iterator.h
index 6358d5b1e4..3eba53ba23 100644
--- a/legacy/eina/src/include/eina_iterator.h
+++ b/legacy/eina/src/include/eina_iterator.h
@@ -24,6 +24,63 @@
24#include "eina_types.h" 24#include "eina_types.h"
25#include "eina_magic.h" 25#include "eina_magic.h"
26 26
27/**
28 * @page eina_iterator_example Eina_Iterator usage
29 * @dontinclude eina_iterator_01.c
30 *
31 * As always when using eina we need to include it:
32 * @skip #include
33 * @until Eina.h
34 *
35 * Here we a declare an unimpressive @ref Eina_Each_Cb "function" that prints
36 * some data:
37 * @until }
38 * @note Returning EINA_TRUE is important so we don't stop iterating over the
39 * container.
40 *
41 * And here a more interesting function, it uses an iterator to print the
42 * contents of a container. What's interesting about it is that it doesn't care
43 * the type of container, it works for anything that can provide an iterator:
44 * @until }
45 *
46 * And on to our main function were we declare some variables and initialize
47 * eina, nothing too special:
48 * @until eina_init
49 *
50 * Next we populate both an array and a list with our strings, for more details
51 * see @ref eina_list_01_example and @ref eina_array_01_example:
52 * @until }
53 *
54 * And now we create an array and because the first element of the container
55 * doesn't interest us we skip it:
56 * @until iterator_next
57 *
58 * Having our iterator now pointing to interesting data we go ahead and print:
59 * @until print_eina_container
60 *
61 * As always once data with a structure we free it, but just because we can we
62 * do it by asking the iterator for it's container, and then of course free the
63 * iterator itself:
64 * @until eina_iterator_free
65 *
66 * But so far you're not impressed in @ref eina_array_01_example an array is
67 * also printed, so now we go to the cool stuff and use an iterator to do same
68 * stuff to a list:
69 * @until eina_iterator_free
70 * @note The only significant diference to the block above is in the
71 * function used to create the iterator.
72 *
73 * And now we free the list and shut eina down:
74 * @until }
75 */
76
77/**
78 * @page eina_iterator_01_c Eina_Iterator usage
79 * @page eina_iterator_01_c Eina_Iterator usage
80 *
81 * @include eina_iterator_01.c
82 * @example eina_iterator_01.c
83 */
27 84
28/** 85/**
29 * @addtogroup Eina_Iterator_Group Iterator Functions 86 * @addtogroup Eina_Iterator_Group Iterator Functions
@@ -41,6 +98,8 @@
41 * eina_iterator_free(). To get the data and iterate, use 98 * eina_iterator_free(). To get the data and iterate, use
42 * eina_iterator_next(). To call a function on all the elements of a 99 * eina_iterator_next(). To call a function on all the elements of a
43 * container, use eina_iterator_foreach(). 100 * container, use eina_iterator_foreach().
101 *
102 * Here an @ref eina_iterator_example "example"
44 * 103 *
45 * @{ 104 * @{
46 */ 105 */