forked from enlightenment/efl
* more doc in the tutorial of the array data type
* minor formatting SVN revision: 38853
This commit is contained in:
parent
2025e3db2b
commit
cda565a38e
|
@ -111,10 +111,10 @@ EAPI Eina_Accessor *eina_array_accessor_new (const Eina_Array *array) EINA_MALLO
|
||||||
* the following example:
|
* the following example:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* Eina_Array *array;
|
* Eina_Array *array;
|
||||||
* char *item;
|
* char *item;
|
||||||
* Eina_Array_Iterator iterator;
|
* Eina_Array_Iterator iterator;
|
||||||
* unsigned int i;
|
* unsigned int i;
|
||||||
*
|
*
|
||||||
* // array is already filled,
|
* // array is already filled,
|
||||||
* // its elements are just duplicated strings,
|
* // its elements are just duplicated strings,
|
||||||
|
|
|
@ -52,9 +52,10 @@ EAPI Eina_Bool eina_array_grow(Eina_Array *array);
|
||||||
*
|
*
|
||||||
* This function appends @p data to @p array. For performance
|
* This function appends @p data to @p array. For performance
|
||||||
* reasons, there is no check of @p array. If it is @c NULL or
|
* reasons, there is no check of @p array. If it is @c NULL or
|
||||||
* invalid, the program may crash. if an allocation is necessary and
|
* invalid, the program may crash. If @p data is @c NULL, or if an
|
||||||
* fails, #EINA_FALSE is returned and #EINA_ERROR_OUT_OF_MEMORY is
|
* allocation is necessary and fails, #EINA_FALSE is returned and
|
||||||
* set. Otherwise, #EINA_TRUE is returned.
|
* #EINA_ERROR_OUT_OF_MEMORY is set. Otherwise, #EINA_TRUE is
|
||||||
|
* returned.
|
||||||
*/
|
*/
|
||||||
static inline Eina_Bool
|
static inline Eina_Bool
|
||||||
eina_array_push(Eina_Array *array, const void *data)
|
eina_array_push(Eina_Array *array, const void *data)
|
||||||
|
@ -74,10 +75,11 @@ eina_array_push(Eina_Array *array, const void *data)
|
||||||
* @param array The array.
|
* @param array The array.
|
||||||
* @return The retrieved data.
|
* @return The retrieved data.
|
||||||
*
|
*
|
||||||
* This function removes the last data of @p array and returns it. For
|
* This function removes the last data of @p array, decreases the count
|
||||||
* performance reasons, there is no check of @p array. If it is
|
* of @p array and returns the data. For performance reasons, there
|
||||||
* @c NULL or invalid, the program may crash. If the count member is
|
* is no check of @p array. If it is @c NULL or invalid, the program
|
||||||
* less or equal than 0, @c NULL is returned.
|
* may crash. If the count member is less or equal than 0, @c NULL is
|
||||||
|
* returned.
|
||||||
*/
|
*/
|
||||||
static inline void *
|
static inline void *
|
||||||
eina_array_pop(Eina_Array *array)
|
eina_array_pop(Eina_Array *array)
|
||||||
|
|
|
@ -60,10 +60,83 @@
|
||||||
* following command:
|
* following command:
|
||||||
*
|
*
|
||||||
* @code
|
* @code
|
||||||
* gcc -Wall -o my_exe my_source.c `pkg-config --cflags --libs eina`
|
* gcc -o my_bin my_source.c `pkg-config --cflags --libs eina-0`
|
||||||
* @endcode
|
* @endcode
|
||||||
*
|
*
|
||||||
* Then, an array must created with eina_array_new().
|
* Then, an array must created with eina_array_new(). That function
|
||||||
|
* takes an integer as parameter, which is the count of pointers to
|
||||||
|
* add when increasing the array size. Once the array is not used
|
||||||
|
* anymore, it must be destroyed with eina_array_free().
|
||||||
|
*
|
||||||
|
* To append data at the end of the array, the function
|
||||||
|
* eina_array_push() must be used. To remove the data at the end of
|
||||||
|
* the array, eina_array_pop() must be used. Once the array is filled,
|
||||||
|
* one can check its elements by iterating over it. A while loop and
|
||||||
|
* eina_array_data_get() can be used, or else one can use the
|
||||||
|
* predefined macro EINA_ARRAY_ITER_NEXT(). To free all the elements,
|
||||||
|
* a while loop can be used with eina_array_count_get(). Here is an
|
||||||
|
* example of use:
|
||||||
|
*
|
||||||
|
* @code
|
||||||
|
* #include <stdlib.h>
|
||||||
|
* #include <stdio.h>
|
||||||
|
* #include <string.h>
|
||||||
|
*
|
||||||
|
* #include <eina_array.h>
|
||||||
|
*
|
||||||
|
* int main(void)
|
||||||
|
* {
|
||||||
|
* const char *strings[] = {
|
||||||
|
* "first string",
|
||||||
|
* "second string",
|
||||||
|
* "third string",
|
||||||
|
* "fourth string"
|
||||||
|
* };
|
||||||
|
* Eina_Array *array;
|
||||||
|
* char *item;
|
||||||
|
* Eina_Array_Iterator iterator;
|
||||||
|
* unsigned int i;
|
||||||
|
*
|
||||||
|
* if (!eina_array_init())
|
||||||
|
* {
|
||||||
|
* printf ("Error during the initialization of eina_error module\n");
|
||||||
|
* return EXIT_FAILURE;
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* array = eina_array_new(16);
|
||||||
|
* if (!array)
|
||||||
|
* goto shutdown_array;
|
||||||
|
*
|
||||||
|
* for (i = 0; i < 4; i++)
|
||||||
|
* {
|
||||||
|
* eina_array_push(array, strdup(strings[i]));
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* printf("array count: %d\n", eina_array_count_get(array));
|
||||||
|
* EINA_ARRAY_ITER_NEXT(array, i, item, iterator)
|
||||||
|
* {
|
||||||
|
* printf("item #%d: %s\n", i, item);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* while (eina_array_count_get(array))
|
||||||
|
* {
|
||||||
|
* void *data;
|
||||||
|
*
|
||||||
|
* data = eina_array_pop(array);
|
||||||
|
* free(data);
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* eina_array_free(array);
|
||||||
|
* eina_array_shutdown();
|
||||||
|
*
|
||||||
|
* return EXIT_SUCCESS;
|
||||||
|
*
|
||||||
|
* shutdown_array:
|
||||||
|
* eina_array_shutdown();
|
||||||
|
*
|
||||||
|
* return EXIT_FAILURE;
|
||||||
|
* }
|
||||||
|
* @endcode
|
||||||
*
|
*
|
||||||
* To be continued
|
* To be continued
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue