From a1d1f8d9db1454314488f23c50f94c0b169a65e9 Mon Sep 17 00:00:00 2001 From: gastal Date: Tue, 6 Mar 2012 14:27:03 +0000 Subject: [PATCH] Another eina_inarray example. Patch by: "Daniel Vieira Franzolin" git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@68835 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/examples/eina_inarray_02.c | 33 +++++++++++++++++++++++++++++++++ src/include/eina_inarray.h | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 src/examples/eina_inarray_02.c diff --git a/src/examples/eina_inarray_02.c b/src/examples/eina_inarray_02.c new file mode 100644 index 0000000..3653b36 --- /dev/null +++ b/src/examples/eina_inarray_02.c @@ -0,0 +1,33 @@ +//Compile with: +//gcc -g eina_inarray_02.c -o eina_inarray_02 `pkg-config --cflags --libs eina` + +#include + +int +main(int argc, char **argv) +{ + const char* strings[] = { + "helo", "hera", "starbuck", "kat", "boomer", + "hotdog", "longshot", "jammer", "crashdown", "hardball", + "duck", "racetrack", "apolo", "husker", "freaker", + "skulls", "bulldog", "flat top", "hammerhead", "gonzo" + }; + char **str, **str2; + Eina_Inarray *iarr; + int i; + + eina_init(); + iarr = eina_inarray_new(sizeof(char *), 0); + + for (i = 0; i < 20; i++){ + str = &strings[i]; + eina_inarray_append(iarr, str); + } + + printf("Inline array of strings:\n"); + EINA_INARRAY_FOREACH(iarr, str2) + printf("string: %s(pointer: %p)\n", *str2, str2); + + eina_inarray_free(iarr); + eina_shutdown(); +} diff --git a/src/include/eina_inarray.h b/src/include/eina_inarray.h index c9114b7..079f1e3 100644 --- a/src/include/eina_inarray.h +++ b/src/include/eina_inarray.h @@ -119,6 +119,36 @@ */ /** + * @page eina_inarray_example_02 Eina inline array of strings + * @dontinclude eina_inarray_02.c + * + * This example will create an inline array of strings, add some elements and + * then print them. This example is based on @ref eina_array_01_example_page and + * @ref eina_inarray_example_01. + * + * We start with some variable declarations and eina initialization: + * @skip int + * @until eina_init + * + * We then create the array much like we did on @ref eina_inarray_example_01: + * @until inarray_new + * + * The point were this example significantly differs from the first eina inline + * array example. We'll not be adding the strings themselves to the array since + * their size varies, we'll store pointer to the strings instead. We therefore + * use @c char** to populate our inline array: + * @until } + * + * The source for this example: @ref eina_inarray_02_c + */ + +/** + * @page eina_inarray_02_c eina_inarray_02.c + * @include eina_inarray_02.c + * @example eina_inarray_02.c + */ + +/** * @addtogroup Eina_Data_Types_Group Data Types * * @since 1.2 @@ -144,8 +174,9 @@ * of the array is a lot more costly than appending, so those operations should * be minimized. * - * Example: - * @ref eina_inarray_example_01 + * Examples: + * @li @ref eina_inarray_example_01 + * @li @ref eina_inarray_example_02 * * @{ */ -- 2.7.4