ajwillia-ms pushed a commit to branch master. http://git.enlightenment.org/tools/examples.git/commit/?id=d89bd6fb617560aeecab8c59eecd66dee0b03d67
commit d89bd6fb617560aeecab8c59eecd66dee0b03d67 Author: Andy Williams <[email protected]> Date: Tue Nov 14 13:31:39 2017 +0000 eina: Add an array reference example --- reference/c/eina/src/eina_array_main.c | 91 ++++++++++++++++++++++++++++++++++ reference/c/eina/src/meson.build | 7 +++ 2 files changed, 98 insertions(+) diff --git a/reference/c/eina/src/eina_array_main.c b/reference/c/eina/src/eina_array_main.c new file mode 100644 index 0000000..51eb4b1 --- /dev/null +++ b/reference/c/eina/src/eina_array_main.c @@ -0,0 +1,91 @@ +#define EFL_EO_API_SUPPORT 1 +#define EFL_BETA_API_SUPPORT 1 + +#include <stdio.h> +#include <Eina.h> + +#include <Efl.h> +#include <Elementary.h> + +static Eina_Array * +_array_create() +{ + const char *names[] = + { + "helo", "hera", "starbuck", "kat", "boomer", + "hotdog", "longshot", "jammer", "crashdown", "hardball", + "duck", "racetrack", "apolo", "husker", "freaker", + "skulls", "bulldog", "flat top", "hammerhead", "gonzo" + }; + + Eina_Array *array; + unsigned int i; + + array = eina_array_new(20); + for (i = 0; i < 20; i++) + eina_array_push(array, strdup(names[i])); + + return array; +} + +static void _array_free(Eina_Array *array) +{ + Eina_Array_Iterator iterator; + char *item; + unsigned int i; + + EINA_ARRAY_ITER_NEXT(array, i, item, iterator) + free(item); + eina_array_free(array); +} + +static Eina_Bool +_item_print(const void *container EINA_UNUSED, void *data, void *fdata EINA_UNUSED) +{ + printf(" %s\n", (char *)data); + return EINA_TRUE; +} + +static Eina_Bool +_item_keep(void *data, void *gdata EINA_UNUSED) +{ + const char *name; + name = (const char *)data; + + if (strlen(name) <= 7) + return EINA_TRUE; + + return EINA_FALSE; +} + +EAPI_MAIN void +efl_main(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED) +{ + Eina_Array *array; + + array = _array_create(); + + // show the contents of our array + printf("Array count: %d\n", eina_array_count(array)); + printf("Array contents:\n"); + eina_array_foreach(array, _item_print, NULL); + + // access a specific item in the array + printf("Top gun: %s\n", (char*)eina_array_data_get(array, 2)); + + // update a single item in the array + eina_array_data_set(array, 17, strdup("flattop")); + // update the array removing items that do not match the _item_keep criteria + eina_array_remove(array, _item_keep, NULL); + + // print the new contents of our array + printf("New array count: %d\n", eina_array_count(array)); + printf("New array contents:\n"); + eina_array_foreach(array, _item_print, NULL); + + _array_free(array); + + efl_exit(0); +} +EFL_MAIN() + diff --git a/reference/c/eina/src/meson.build b/reference/c/eina/src/meson.build index 490e6a8..0e132d4 100644 --- a/reference/c/eina/src/meson.build +++ b/reference/c/eina/src/meson.build @@ -1,5 +1,12 @@ deps = [eina, efl, elm] +executable('efl_reference_eina_array', + files(['eina_array_main.c']), + dependencies : deps, + include_directories : inc, + install : true +) + executable('efl_reference_eina_iterator', files(['eina_iterator_main.c']), dependencies : deps, --
