eina_inarray_01.c
//Compile with:
//gcc -g eina_inarray_01.c -o eina_inarray_01 `pkg-config --cflags --libs eina`
#include <Eina.h>
int
cmp(const void *a, const void *b)
{
return *(int*)a > *(int*)b;
}
int main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Eina_Inarray *iarr;
char ch, *ch2;
int a, *b;
eina_init();
iarr = eina_inarray_new(sizeof(char), 0);
ch = 'a';
eina_inarray_push(iarr, &ch);
ch = 'b';
eina_inarray_push(iarr, &ch);
ch = 'c';
eina_inarray_push(iarr, &ch);
ch = 'd';
eina_inarray_push(iarr, &ch);
printf("Inline array of chars:\n");
EINA_INARRAY_FOREACH(iarr, ch2)
printf("char: %c(pointer: %p)\n", *ch2, ch2);
eina_inarray_flush(iarr);
eina_inarray_step_set(iarr, sizeof(Eina_Inarray), sizeof(int), 4);
a = 97;
eina_inarray_push(iarr, &a);
a = 98;
eina_inarray_push(iarr, &a);
a = 100;
eina_inarray_push(iarr, &a);
a = 99;
eina_inarray_insert_sorted(iarr, &a, cmp);
printf("Inline array of integers with %d elements:\n", eina_inarray_count(iarr));
EINA_INARRAY_FOREACH(iarr, b)
printf("int: %d(pointer: %p)\n", *b, b);
eina_inarray_free(iarr);
eina_shutdown();
}
Eina.h
Eina Utility library.
eina_inarray_free
EINA_API void eina_inarray_free(Eina_Inarray *array)
Frees an array and its members.
Definition eina_inarray.c:355
eina_inarray_push
EINA_API int eina_inarray_push(Eina_Inarray *array, const void *data)
Copies the data as the last member of the array.
Definition eina_inarray.c:411
eina_inarray_flush
EINA_API void eina_inarray_flush(Eina_Inarray *array)
Removes every member from the array.
Definition eina_inarray.c:388
eina_inarray_count
EINA_API unsigned int eina_inarray_count(const Eina_Inarray *array)
Counts the number of members in an array.
Definition eina_inarray.c:732
eina_inarray_insert_sorted
EINA_API int eina_inarray_insert_sorted(Eina_Inarray *array, const void *data, Eina_Compare_Cb compare)
Copies the data to the array at a position found by the comparison function.
Definition eina_inarray.c:475
EINA_INARRAY_FOREACH
#define EINA_INARRAY_FOREACH(array, itr)
Walks through an array linearly from head to tail.
Definition eina_inarray.h:724
eina_inarray_new
EINA_API Eina_Inarray * eina_inarray_new(unsigned int member_size, unsigned int step)
Creates a new inline array.
Definition eina_inarray.c:342
Eina_Inarray
struct _Eina_Inarray Eina_Inarray
Type for the inlined array.
Definition eina_inarray.h:212
eina_inarray_step_set
EINA_API void eina_inarray_step_set(Eina_Inarray *array, unsigned int sizeof_eina_inarray, unsigned int member_size, unsigned int step)
Initializes an inline array.
Definition eina_inarray.c:366
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_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339