eina_array_01.c
//Compile with:
//gcc -g eina_array_01.c -o eina_array_01 `pkg-config --cflags --libs eina`
#include <stdio.h>
#include <string.h>
#include <Eina.h>
static Eina_Bool
_print(const void *container EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
{
printf("%s\n", (char *)data);
return EINA_TRUE;
}
int
main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
const char* strings[] = {
"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;
eina_init();
array = eina_array_new(10);
eina_array_step_set(array, sizeof(*array), 20);
for (i = 0; i < 20; i++)
eina_array_push(array, strdup(strings[i]));
printf("array count: %d\n", eina_array_count(array));
eina_array_foreach(array, _print, NULL);
printf("Top gun: %s\n", (char*)eina_array_data_get(array, 2));
while (eina_array_count(array))
free(eina_array_pop(array));
eina_array_free(array);
eina_shutdown();
return 0;
}
Eina.h
Eina Utility library.
eina_array_pop
static void * eina_array_pop(Eina_Array *array)
Removes the last data item in an array.
Eina_Array
struct _Eina_Array Eina_Array
Type for a generic one-dimensional linear data structure.
Definition eina_array.h:216
eina_array_free
EINA_API void eina_array_free(Eina_Array *array)
Frees an array.
Definition eina_array.c:295
eina_array_foreach
static Eina_Bool eina_array_foreach(Eina_Array *array, Eina_Each_Cb cb, void *fdata)
Iterates over an array using a callback function.
eina_array_push
static Eina_Bool eina_array_push(Eina_Array *array, const void *data)
Appends a data item to an array.
eina_array_step_set
EINA_API void eina_array_step_set(Eina_Array *array, unsigned int sizeof_eina_array, unsigned int step)
Sets the step of an array.
Definition eina_array.c:305
eina_array_data_get
static void * eina_array_data_get(const Eina_Array *array, unsigned int idx)
Returns the data at a given position in an array.
eina_array_new
EINA_API Eina_Array * eina_array_new(unsigned int step)
Creates a new array.
Definition eina_array.c:276
eina_array_count
static unsigned int eina_array_count(const Eina_Array *array)
Returns the number of elements in an array.
eina_shutdown
EINA_API int eina_shutdown(void)
Shuts down the Eina library.
Definition eina_main.c:379
eina_init
EINA_API int eina_init(void)
Initializes the Eina library.
Definition eina_main.c:291
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:527
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339