2012-01-09 15:24:18 -08:00
|
|
|
/* EINA - EFL data type library
|
|
|
|
* Copyright (C) 2012 ProFUSION embedded systems
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library;
|
|
|
|
* if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef EINA_INARRAY_H_
|
|
|
|
#define EINA_INARRAY_H_
|
|
|
|
|
|
|
|
#include "eina_types.h"
|
|
|
|
#include "eina_iterator.h"
|
|
|
|
#include "eina_accessor.h"
|
|
|
|
|
2012-02-22 05:15:38 -08:00
|
|
|
/**
|
|
|
|
* @page eina_inarray_example_01 Eina inline array usage
|
|
|
|
* @dontinclude eina_inarray_01.c
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* This example creates an inline array of chars, adds some elements, prints
|
|
|
|
* them, re-purposes the array to store ints, adds some elements and print that.
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* We are going to start with a function to compare ints. We need this because the '>'
|
2012-02-22 05:15:38 -08:00
|
|
|
* operator is not a function and can't be used where Eina_Compare_Cb is needed.
|
|
|
|
* @skip int
|
|
|
|
* @until }
|
|
|
|
*
|
|
|
|
* And then move on to the code we actually care about, starting with variable
|
|
|
|
* declarations and eina initialization:
|
|
|
|
* @until eina_init
|
|
|
|
*
|
|
|
|
* Creating an inline array is very simple, we just need to know what type we
|
|
|
|
* want to store:
|
|
|
|
* @until inarray_new
|
|
|
|
* @note The second parameter(the step) is left at zero which means that eina
|
2014-10-28 13:16:38 -07:00
|
|
|
* chooses an appropriate value, this should @b only be changed if it's
|
|
|
|
* known, beforehand, that how many elements the array has.
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
|
|
|
* Once we have an array we can start adding elements to it. Because the
|
2014-10-28 13:16:38 -07:00
|
|
|
* insertion function expects a memory address we have to put the value we want
|
|
|
|
* to store in a variable(this should be no problem since in the real world usage
|
|
|
|
* that's usually where the value is anyways):
|
2012-04-20 01:30:59 -07:00
|
|
|
* @until push
|
2012-02-22 05:15:38 -08:00
|
|
|
* @note Because the inline array copies the value given to it we can later
|
|
|
|
* change @c ch, which we do, without affecting the contents of the array.
|
|
|
|
*
|
|
|
|
* So let's add some more elements:
|
2012-04-20 01:30:59 -07:00
|
|
|
* @until push
|
|
|
|
* @until push
|
|
|
|
* @until push
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* We then iterate over our array and print every position of it. The thing
|
|
|
|
* to note here is not so much the values, which are the expected 'a', 'b',
|
|
|
|
* 'c', and 'd', but rather the memory address of these values, they are
|
2012-02-22 05:15:38 -08:00
|
|
|
* sequential:
|
|
|
|
* @until printf
|
|
|
|
* @until printf
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* We are now going to use our array to store ints, so we need to first erase every member
|
2012-02-22 05:15:38 -08:00
|
|
|
* currently on the array:
|
|
|
|
* @until _flush
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* And then to be able to store a different type on the same array, we use the
|
2012-04-20 01:30:59 -07:00
|
|
|
* eina_inarray_step_set() function, which is just like the eina_inarray_new()
|
2014-10-28 13:16:38 -07:00
|
|
|
* function except it receives an already allocated memory. This time we're going
|
|
|
|
* to ask eina to use a step of size 4 because that's how many elements we are going to
|
|
|
|
* put in the array:
|
2012-04-20 01:30:59 -07:00
|
|
|
* @until _step_set
|
2012-08-24 14:03:07 -07:00
|
|
|
* @note Strictly speaking the reason to call eina_inarray_step_set() is not
|
2014-10-28 13:16:38 -07:00
|
|
|
* because we're storing a different type, but because our types have
|
2012-02-22 05:15:38 -08:00
|
|
|
* different sizes. Eina inline arrays don't actually know anything about types,
|
2014-10-28 13:16:38 -07:00
|
|
|
* they only deal with blocks of memory of a given size.
|
|
|
|
* @note Since eina_inarray_step_set() receives already allocated memory, you can(and
|
|
|
|
* it is in fact a good practice) use inline arrays that are not declared as pointers:
|
2012-02-22 05:15:38 -08:00
|
|
|
* @code
|
|
|
|
* Eina_Inarray arr;
|
2012-04-20 01:30:59 -07:00
|
|
|
* eina_inarray_step_set(&arr, sizeof(arr), sizeof(int), 4);
|
2012-02-22 05:15:38 -08:00
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* And now to add our integer values to the array:
|
2012-04-20 01:30:59 -07:00
|
|
|
* @until push
|
|
|
|
* @until push
|
|
|
|
* @until push
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* Just to change things up a bit we've left out the 99 value, but we still
|
|
|
|
* add it in such a way that it keeps the array ordered. There are many ways to do
|
2012-02-22 05:15:38 -08:00
|
|
|
* this, we could use eina_inarray_insert_at(), or we could change the value
|
|
|
|
* of the last member using eina_inarray_replace_at() and then append the values
|
|
|
|
* in the right order, but for no particular reason we're going to use
|
|
|
|
* eina_inarray_insert_sorted() instead:
|
|
|
|
* @until insert_sorted
|
|
|
|
*
|
|
|
|
* We then print the size of our array, and the array itself, much like last
|
|
|
|
* time the values are not surprising, and neither should it be that the memory
|
|
|
|
* addresses are contiguous:
|
|
|
|
* @until printf
|
|
|
|
* @until printf
|
|
|
|
*
|
|
|
|
* Once done we free our array and shutdown eina:
|
|
|
|
* @until }
|
|
|
|
*
|
|
|
|
* The source for this example: @ref eina_inarray_01_c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @page eina_inarray_01_c eina_inarray_01.c
|
|
|
|
* @include eina_inarray_01.c
|
|
|
|
* @example eina_inarray_01.c
|
|
|
|
*/
|
|
|
|
|
2012-03-06 06:27:03 -08:00
|
|
|
/**
|
|
|
|
* @page eina_inarray_example_02 Eina inline array of strings
|
|
|
|
* @dontinclude eina_inarray_02.c
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* This example creates an inline array of strings, adds some elements, and
|
|
|
|
* then prints them. This example is based on @ref eina_array_01_example_page and
|
2012-03-06 06:27:03 -08:00
|
|
|
* @ref eina_inarray_example_01.
|
|
|
|
*
|
|
|
|
* We start with some variable declarations and eina initialization:
|
|
|
|
* @skip int
|
|
|
|
* @until eina_init
|
|
|
|
*
|
2012-03-29 04:35:34 -07:00
|
|
|
* We then create the array much like we did on @ref eina_inarray_example_01 :
|
2012-03-06 06:27:03 -08:00
|
|
|
* @until inarray_new
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* The point is this example significantly differs from the first eina inline
|
|
|
|
* array example. We are not going to add the strings themselves to the array since
|
|
|
|
* their size varies, we are going to store a pointer to the strings instead. We therefore
|
2012-03-06 06:27:03 -08:00
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2014-12-22 06:08:41 -08:00
|
|
|
/**
|
|
|
|
* @page eina_inarray_example_03 Eina inline array insert, sort and search
|
|
|
|
* @dontinclude eina_inarray_03.c
|
|
|
|
*
|
|
|
|
* This example creates an inline array of integers, and demonstrates the
|
|
|
|
* difference between eina_inarray_insert and eina_inarray_sort, and
|
|
|
|
* eina_inarray_search and eina_inarray_search_sort.
|
|
|
|
* @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
|
|
|
|
*
|
|
|
|
* We then add element using eina_inarray_insert and print. Then remove that
|
|
|
|
* element and add again using eina_inarray_insert_sorted and prints. This
|
2017-02-19 22:18:21 -08:00
|
|
|
* shows the 2 different positions the element gets added. Then searches an
|
2014-12-22 06:08:41 -08:00
|
|
|
* element in the unsorted array using eina_inarray_search, then sorts the
|
|
|
|
* array and then searches the same element using eina_inarray_search_sorted.
|
|
|
|
* @until }
|
|
|
|
*
|
|
|
|
* The source for this example: @ref eina_inarray_03_c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @page eina_inarray_03_c eina_inarray_03.c
|
|
|
|
* @include eina_inarray_03.c
|
|
|
|
* @example eina_inarray_03.c
|
|
|
|
*/
|
|
|
|
|
2012-01-09 15:24:18 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @defgroup Eina_Inline_Array_Group Inline Array
|
|
|
|
* @ingroup Eina_Containers_Group
|
2012-01-09 16:23:24 -08:00
|
|
|
* @since 1.2
|
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Inline array is a container that stores the data itself, not the pointers to the data.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* This means there is no memory fragmentation, also for small data types(such
|
|
|
|
* as char, short, int, and so on) it's more memory efficient.
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
|
|
|
* Usage of the inline array is very similar to that of other
|
|
|
|
* @ref Eina_Containers_Group, like all arrays adding elements to the beginning
|
|
|
|
* of the array is a lot more costly than appending, so those operations should
|
|
|
|
* be minimized.
|
|
|
|
*
|
2012-03-06 06:27:03 -08:00
|
|
|
* Examples:
|
|
|
|
* @li @ref eina_inarray_example_01
|
|
|
|
* @li @ref eina_inarray_example_02
|
2012-02-22 05:15:38 -08:00
|
|
|
*
|
2012-01-09 15:24:18 -08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef Eina_Inarray
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Type for the inlined array.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
typedef struct _Eina_Inarray Eina_Inarray;
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Inline array structure.
|
|
|
|
*
|
|
|
|
* @note Use #Eina_Inarray instead.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note Do not modify these fields directly, use eina_inarray_step_set() or
|
|
|
|
* eina_inarray_new() instead.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
struct _Eina_Inarray
|
|
|
|
{
|
2012-04-20 01:30:59 -07:00
|
|
|
#define EINA_ARRAY_VERSION 1
|
2014-10-28 13:16:38 -07:00
|
|
|
int version; /**< Should match the EINA_ARRAY_VERSION used when compiling your apps, provided for ABI compatibility */
|
2012-04-20 01:30:59 -07:00
|
|
|
|
2014-10-28 13:16:38 -07:00
|
|
|
unsigned int member_size; /**< Byte size of each entry in the members */
|
|
|
|
unsigned int len; /**< Number of elements used by the members */
|
|
|
|
unsigned int max; /**< Number of elements allocated to the members */
|
|
|
|
unsigned int step; /**< Amount to grow the number of members allocated */
|
|
|
|
void *members; /**< Actual array of elements */
|
2012-01-09 15:24:18 -08:00
|
|
|
EINA_MAGIC
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Creates a new inline array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This creates a new array where members are inlined in a sequence. Each
|
|
|
|
* member has @a member_size bytes.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] member_size The size of each member in the array
|
|
|
|
* @param[in] step The step size by which to resize the array, do this using the following
|
|
|
|
* extra amount
|
|
|
|
* @return The new inline array table, otherwise @c NULL on failure
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If the @a step is @c 0, then a safe default is chosen.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note On failure, @c NULL is returned. If @p member_size is zero, then @c NULL is returned.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_free()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Inarray *eina_inarray_new(unsigned int member_size,
|
|
|
|
unsigned int step) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Frees an array and its members.
|
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_flush()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_inarray_free(Eina_Inarray *array) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Initializes an inline array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This initializes an array. If the @p step is @c 0, then a safe default is
|
|
|
|
* chosen.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object to initialize
|
|
|
|
* @param[in] sizeof_eina_inarray The size of array object
|
|
|
|
* @param[in] member_size The size of each member in the array
|
|
|
|
* @param[in] step The step size by which to resize the array, do this using the following
|
|
|
|
* extra amount
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This is useful for arrays inlined into other structures or
|
|
|
|
* allocated to a stack.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_flush()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
2012-04-20 01:30:59 -07:00
|
|
|
EAPI void eina_inarray_step_set(Eina_Inarray *array,
|
|
|
|
unsigned int sizeof_eina_inarray,
|
|
|
|
unsigned int member_size,
|
|
|
|
unsigned int step) EINA_ARG_NONNULL(1);
|
2012-01-09 15:24:18 -08:00
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Removes every member from the array.
|
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_inarray_flush(Eina_Inarray *array) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Copies the data as the last member of the array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This copies the given pointer contents at the end of the array. The
|
|
|
|
* pointer is not referenced, instead its contents are copied to the
|
|
|
|
* members array using the previously defined @c member_size.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The data to be copied at the end
|
|
|
|
* @return The index of the new member, otherwise @c -1 on errors
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @see eina_inarray_insert_at()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
2012-04-20 01:30:59 -07:00
|
|
|
EAPI int eina_inarray_push(Eina_Inarray *array,
|
|
|
|
const void *data) EINA_ARG_NONNULL(1, 2);
|
2012-01-09 15:24:18 -08:00
|
|
|
|
2012-12-30 16:05:02 -08:00
|
|
|
/**
|
2017-02-19 22:18:21 -08:00
|
|
|
* @brief Allocates new item at the end of the array.
|
2012-12-30 16:05:02 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] size The number of new item to allocate
|
|
|
|
*
|
|
|
|
* @note The returned pointer is only valid until you use any other eina_inarray
|
|
|
|
* function.
|
2012-12-30 16:05:02 -08:00
|
|
|
*
|
|
|
|
* @since 1.8
|
|
|
|
*/
|
2012-12-30 17:27:58 -08:00
|
|
|
EAPI void *eina_inarray_grow(Eina_Inarray *array, unsigned int size);
|
2012-12-30 16:05:02 -08:00
|
|
|
|
2012-01-09 15:24:18 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Copies the data to the array at a position found by the comparison function.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This copies the given pointer contents at the array position defined by the
|
|
|
|
* given @a compare function. The pointer is not referenced, instead
|
|
|
|
* its contents are copied to the members array using the previously
|
|
|
|
* defined @c member_size.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The data to be copied
|
|
|
|
* @param[in] compare The compare function
|
|
|
|
* @return The index of the new member, otherwise @c -1 on errors
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The data given to the @p compare function is a pointer to the member
|
|
|
|
* memory itself, do no change it.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_insert_sorted()
|
|
|
|
* @see eina_inarray_insert_at()
|
2012-04-20 01:30:59 -07:00
|
|
|
* @see eina_inarray_push()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_insert(Eina_Inarray *array,
|
|
|
|
const void *data,
|
|
|
|
Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Copies the data to the array at a position found by the comparison function.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This copies the given pointer contents at the array position defined by the
|
|
|
|
* given @p compare function. The pointer is not referenced, instead
|
|
|
|
* its contents are copied to the members array using the previously
|
|
|
|
* defined @p member_size.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The data to be copied
|
|
|
|
* @param[in] compare The compare function
|
|
|
|
* @return The index of the new member, otherwise @c -1 on errors
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The data given to the @p compare function is a pointer to the member
|
|
|
|
* memory itself, do no change it.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This variation optimizes the insertion position assuming that the array
|
|
|
|
* is already sorted by doing a binary search.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_sort()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_insert_sorted(Eina_Inarray *array,
|
|
|
|
const void *data,
|
|
|
|
Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Finds data and removes the matching member.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This finds data in the array and removes it. Data may be an existing
|
|
|
|
* member of the array (then optimized) or the contents are matched
|
|
|
|
* using memcmp().
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The data to be found and removed
|
|
|
|
* @return The index of the removed member, otherwise @c -1 on errors
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_pop()
|
|
|
|
* @see eina_inarray_remove_at()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_remove(Eina_Inarray *array,
|
|
|
|
const void *data) EINA_ARG_NONNULL(1, 2);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Removes the last member of the array.
|
2012-04-20 01:30:59 -07:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @return The data poped out of the array
|
|
|
|
*
|
|
|
|
* @note The data could be considered valid only until any other operation touched the Inarray.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
2012-04-20 01:30:59 -07:00
|
|
|
EAPI void *eina_inarray_pop(Eina_Inarray *array) EINA_ARG_NONNULL(1);
|
2012-01-09 15:24:18 -08:00
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Gets the member at the given position.
|
|
|
|
* @details This gets the member given that its position in the array is provided. It is a pointer to
|
|
|
|
* its current memory, then it can be invalidated with functions that
|
|
|
|
* change the array such as eina_inarray_push(),
|
|
|
|
* eina_inarray_insert_at(), or eina_inarray_remove_at(), or variants.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2017-02-19 22:18:21 -08:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] position The member position
|
|
|
|
* @return A pointer to current the member memory
|
|
|
|
*
|
2012-01-09 16:23:24 -08:00
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI void *eina_inarray_nth(const Eina_Inarray *array,
|
|
|
|
unsigned int position) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Copies the data at the given position in the array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This copies the given pointer contents at the given @p position in the
|
|
|
|
* array. The pointer is not referenced, instead its contents are
|
|
|
|
* copied to the members array using the previously defined
|
|
|
|
* @p member_size.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] position The position to insert the member at
|
|
|
|
* @param[in] data The data to be copied at the position
|
|
|
|
* @return #EINA_TRUE on success, otherwise #EINA_FALSE on failure
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note All the members from @a position to the end of the array are
|
|
|
|
* shifted to the end.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If @a position is equal to the end of the array (equal to
|
|
|
|
* eina_inarray_count()), then the member is appended.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If @a position is bigger than the array length, it fails.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Bool eina_inarray_insert_at(Eina_Inarray *array,
|
|
|
|
unsigned int position,
|
|
|
|
const void *data) EINA_ARG_NONNULL(1, 3);
|
|
|
|
|
2012-01-12 11:08:26 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Opens a space at the given position, returning its pointer.
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] position The position to insert first member at (open/allocate space)
|
|
|
|
* @param[in] member_count The number of times @c member_size bytes are allocated
|
|
|
|
* @return A pointer to the first member memory allocated, otherwise @c NULL on errors
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This is similar to eina_inarray_insert_at(), but useful if the
|
|
|
|
* members contents are still unknown or unallocated. It makes
|
|
|
|
* room for the required number of items and returns the pointer to the
|
|
|
|
* first item, similar to malloc(member_count * member_size), with the
|
|
|
|
* guarantee that all the memory is within the members array.
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The new member memory is undefined, it's not automatically zeroed.
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note All the members from @a position to the end of the array are
|
|
|
|
* shifted to the end.
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If @a position is equal to the end of the array (equal to
|
|
|
|
* eina_inarray_count()), then the member is appended.
|
|
|
|
*
|
|
|
|
* @note If @a position is bigger than the array length, it fails.
|
2012-01-12 11:08:26 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
|
|
|
*/
|
|
|
|
EAPI void *eina_inarray_alloc_at(Eina_Inarray *array,
|
|
|
|
unsigned int position,
|
|
|
|
unsigned int member_count) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
|
|
|
|
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Copies the data to the given position.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This copies the given pointer contents at the given @p position in the
|
|
|
|
* array. The pointer is not referenced, instead its contents are
|
|
|
|
* copied to the members array using the previously defined
|
|
|
|
* @p member_size.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] position The position to copy the member at
|
|
|
|
* @param[in] data The data to be copied at the position
|
|
|
|
* @return #EINA_TRUE on success, otherwise #EINA_FALSE on failure
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If @p position does not exist, it fails.
|
add eina_value.
eina value is a generic value storage, it's quite efficient to space
(16 bytes) and speed (inlines for basic types).
It's basically a structure describing how to manage memory
(Eina_Value_Type), with default implementation for char, short, int,
long, int64_t (and unsigned variants), float, double, stringshare and
string.
If a type 'value_size' is smaller than 8 bytes, it's stored
inline. Otherwise a value is allocated and managed.
Most of the methods are inline, with special handling for char, short,
int... Then no extra calls are made, allowing the compiler to optimize
them.
For array of a single type it is recommend to use Eina_Value_Array, as
it will efficiently store and access members (just a char if subtype
is EINA_VALUE_TYPE_CHAR, etc).
It can copy itself, compare itself. Including arrays.
It would be nice to have something that converts between EET and this.
SVN revision: 67035
2012-01-10 18:20:26 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool eina_inarray_replace_at(Eina_Inarray *array,
|
|
|
|
unsigned int position,
|
|
|
|
const void *data) EINA_ARG_NONNULL(1, 3);
|
|
|
|
|
2012-01-09 15:24:18 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Removes a member from the given position.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] position The position from which to remove a member
|
|
|
|
* @return #EINA_TRUE on success, otherwise #EINA_FALSE on failure
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The member is removed from an array and members after it are moved
|
|
|
|
* towards the array head.
|
|
|
|
*
|
|
|
|
* @see eina_inarray_pop()
|
|
|
|
* @see eina_inarray_remove()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Bool eina_inarray_remove_at(Eina_Inarray *array,
|
|
|
|
unsigned int position) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Reverses members in the array.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
*
|
|
|
|
* @note If you do not want to change the array, just walk through its elements
|
|
|
|
* backwards, then use the EINA_INARRAY_REVERSE_FOREACH() macro.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see EINA_INARRAY_REVERSE_FOREACH()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_inarray_reverse(Eina_Inarray *array) EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Applies a quick sort to the array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This applies a quick sort to the @a array.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] compare The compare function
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The data given to the @a compare function is a pointer to the member
|
|
|
|
* memory itself, do no change it.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see eina_inarray_insert_sorted()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI void eina_inarray_sort(Eina_Inarray *array,
|
|
|
|
Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Searches for a member (linear walk).
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This walks through an array by linearly looking for the given data compared by
|
|
|
|
* the @p compare function.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The member to search using the @p compare function
|
|
|
|
* @param[in] compare The compare function
|
|
|
|
* @return The member index, otherwise @c -1 if not found
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The data given to the @p compare function is a pointer to the member
|
|
|
|
* memory itself, do no change it.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2012-01-09 16:23:24 -08:00
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_search(const Eina_Inarray *array,
|
|
|
|
const void *data,
|
|
|
|
Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Searches for member (binary search walk).
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] data The member to search using the @p compare function
|
|
|
|
* @param[in] compare The compare function
|
|
|
|
* @return The member index, otherwise @c -1 if not found
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note Uses a binary search for the given data as compared by the @p compare function.
|
|
|
|
*
|
|
|
|
* @note The data given to the @p compare function is a pointer to the member
|
|
|
|
* memory itself, do no change it.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_search_sorted(const Eina_Inarray *array,
|
|
|
|
const void *data,
|
|
|
|
Eina_Compare_Cb compare) EINA_ARG_NONNULL(1, 2, 3);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Calls @p function for each array member.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This calls @p function for every given data in @p array.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] function The callback function
|
|
|
|
* @param[in] user_data The user data given to a callback @a function
|
|
|
|
* @return #EINA_TRUE if it successfully iterates all the items of the array
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This is a safe way to iterate over an array. @p function should return #EINA_TRUE
|
|
|
|
* as long as you want the function to continue iterating, by
|
|
|
|
* returning #EINA_FALSE it stops and returns #EINA_FALSE as the result.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note The data given to @p function is a pointer to the member memory itself.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
|
|
|
* @see EINA_INARRAY_FOREACH()
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Bool eina_inarray_foreach(const Eina_Inarray *array,
|
|
|
|
Eina_Each_Cb function,
|
|
|
|
const void *user_data) EINA_ARG_NONNULL(1, 2);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Removes all the members that match.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This removes all the entries in @p array, where the @p match function
|
|
|
|
* returns #EINA_TRUE.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] match The match function
|
|
|
|
* @param[in] user_data The user data given to callback @p match
|
|
|
|
* @return The number of removed entries, otherwise @c -1 on error
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2012-01-09 16:23:24 -08:00
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI int eina_inarray_foreach_remove(Eina_Inarray *array,
|
|
|
|
Eina_Each_Cb match,
|
|
|
|
const void *user_data) EINA_ARG_NONNULL(1, 2);
|
|
|
|
|
2014-02-25 12:19:11 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Resizes array to new size
|
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] new_size New size for resize
|
|
|
|
* @return #EINA_TRUE if it resized the array successfully.
|
2014-02-25 12:19:11 -08:00
|
|
|
*
|
|
|
|
* @since 1.10
|
|
|
|
*/
|
|
|
|
EAPI Eina_Bool eina_inarray_resize(Eina_Inarray *array, unsigned int new_size);
|
|
|
|
|
2012-01-09 15:24:18 -08:00
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Counts the number of members in an array.
|
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @return The number of members in the array
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI unsigned int eina_inarray_count(const Eina_Inarray *array) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT;
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Returns a new iterator associated to an array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This function returns a newly allocated iterator associated to
|
|
|
|
* @p array.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @return A new iterator
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If the memory cannot be allocated, @c NULL is returned.
|
|
|
|
* Otherwise, a valid iterator is returned.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @warning If the array structure changes then the iterator becomes
|
|
|
|
* invalid. That is, if you add or remove members this
|
|
|
|
* iterator's behavior is undefined and your program may crash.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Iterator *eina_inarray_iterator_new(const Eina_Inarray *array) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Returns a new reversed iterator associated to an array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This function returns a newly allocated iterator associated to
|
|
|
|
* @p array.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @return A new iterator
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note Unlike eina_inarray_iterator_new(), this walks through the array backwards.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If the memory cannot be allocated, @c NULL is returned.
|
|
|
|
* Otherwise, a valid iterator is returned.
|
|
|
|
*
|
|
|
|
* @warning If the array structure changes then the iterator becomes
|
|
|
|
* invalid. That is, if you add or remove nodes this iterator's
|
|
|
|
* behavior is undefined and your program may crash.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Iterator *eina_inarray_iterator_reversed_new(const Eina_Inarray *array) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Returns a new accessor associated to an array.
|
2017-02-19 22:18:21 -08:00
|
|
|
* @details This function returns a newly allocated accessor associated to
|
|
|
|
* @p array.
|
2014-10-28 13:16:38 -07:00
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @return A new accessor
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note If the memory cannot be allocated, @c NULL is returned
|
|
|
|
* Otherwise, a valid accessor is returned.
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
|
|
|
EAPI Eina_Accessor *eina_inarray_accessor_new(const Eina_Inarray *array) EINA_MALLOC EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @def EINA_INARRAY_FOREACH
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Walks through an array linearly from head to tail.
|
|
|
|
*
|
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] itr An iterator pointer
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note @p itr must be a pointer with sizeof(itr*) == array->member_size.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This is fast as it does direct pointer access, but it does
|
|
|
|
* not check for @c NULL pointers or invalid array objects.
|
|
|
|
* Use eina_inarray_foreach() to do that.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note Do not modify an array as you walk through it. If that is desired,
|
|
|
|
* then use eina_inarray_foreach_remove().
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
2013-07-29 00:28:07 -07:00
|
|
|
#define EINA_INARRAY_FOREACH(array, itr) \
|
|
|
|
for ((itr) = (array)->members; \
|
|
|
|
(itr) < (((__typeof__(*itr)*)(array)->members) + (array)->len); \
|
|
|
|
(itr)++)
|
2012-01-09 15:24:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @def EINA_INARRAY_REVERSE_FOREACH
|
2014-10-28 13:16:38 -07:00
|
|
|
* @brief Walks through an array linearly from tail to head.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @param[in] array The array object
|
|
|
|
* @param[in] itr An iterator pointer
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note @p itr must be a pointer with sizeof(itr*) == array->member_size.
|
2012-01-09 15:24:18 -08:00
|
|
|
*
|
2014-10-28 13:16:38 -07:00
|
|
|
* @note This is fast as it does direct pointer access, but it does
|
|
|
|
* not check for @c NULL pointers or invalid array objects.
|
|
|
|
*
|
|
|
|
* @note Do not modify an array as you walk through it. If that is desired,
|
|
|
|
* then use eina_inarray_foreach_remove().
|
2012-01-09 16:23:24 -08:00
|
|
|
*
|
|
|
|
* @since 1.2
|
2012-01-09 15:24:18 -08:00
|
|
|
*/
|
2013-07-29 00:28:07 -07:00
|
|
|
#define EINA_INARRAY_REVERSE_FOREACH(array, itr) \
|
|
|
|
for ((itr) = ((((__typeof__(*(itr))*)(array)->members) + (array)->len) - 1); \
|
|
|
|
(((itr) >= (__typeof__(*(itr))*)(array)->members) \
|
|
|
|
&& ((array)->members != NULL)); \
|
|
|
|
(itr)--)
|
2012-01-09 15:24:18 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /*EINA_INARRAY_H_*/
|