From 9816cfd26348eb32cd41f811a55543842868c2d6 Mon Sep 17 00:00:00 2001 From: Daniel Vieira Franzolin Date: Tue, 6 Mar 2012 14:27:03 +0000 Subject: [PATCH] Another eina_inarray example. Patch by: "Daniel Vieira Franzolin" SVN revision: 68835 --- legacy/eina/src/examples/eina_inarray_02.c | 33 ++++++++++++++++++++ legacy/eina/src/include/eina_inarray.h | 35 ++++++++++++++++++++-- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 legacy/eina/src/examples/eina_inarray_02.c diff --git a/legacy/eina/src/examples/eina_inarray_02.c b/legacy/eina/src/examples/eina_inarray_02.c new file mode 100644 index 0000000000..3653b36f9a --- /dev/null +++ b/legacy/eina/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/legacy/eina/src/include/eina_inarray.h b/legacy/eina/src/include/eina_inarray.h index c9114b7ecc..079f1e3744 100644 --- a/legacy/eina/src/include/eina_inarray.h +++ b/legacy/eina/src/include/eina_inarray.h @@ -118,6 +118,36 @@ * @example eina_inarray_01.c */ +/** + * @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 * @@ -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 * * @{ */