lv_array.h
Array. The elements are dynamically allocated by the 'lv_mem' module.
Defines
-
LV_ARRAY_DEFAULT_CAPACITY
Functions
-
void lv_array_init(lv_array_t *array, uint32_t capacity, uint32_t element_size)
Init an array.
- Parameters:
array -- pointer to an
lv_array_t
variable to initializecapacity -- the initial capacity of the array
element_size -- the size of an element in bytes
-
void lv_array_resize(lv_array_t *array, uint32_t new_capacity)
Resize the array to the given capacity.
Note
if the new capacity is smaller than the current size, the array will be truncated.
- Parameters:
array -- pointer to an
lv_array_t
variablenew_capacity -- the new capacity of the array
-
void lv_array_deinit(lv_array_t *array)
Deinit the array, and free the allocated memory
- Parameters:
array -- pointer to an
lv_array_t
variable to deinitialize
-
static inline uint32_t lv_array_size(const lv_array_t *array)
Return how many elements are stored in the array.
- Parameters:
array -- pointer to an
lv_array_t
variable- Returns:
the number of elements stored in the array
-
static inline uint32_t lv_array_capacity(const lv_array_t *array)
Return the capacity of the array, i.e. how many elements can be stored.
- Parameters:
array -- pointer to an
lv_array_t
variable- Returns:
the capacity of the array
-
static inline bool lv_array_is_empty(const lv_array_t *array)
Return if the array is empty
- Parameters:
array -- pointer to an
lv_array_t
variable- Returns:
true: array is empty; false: array is not empty
-
static inline bool lv_array_is_full(const lv_array_t *array)
Return if the array is full
- Parameters:
array -- pointer to an
lv_array_t
variable- Returns:
true: array is full; false: array is not full
-
void lv_array_copy(lv_array_t *target, const lv_array_t *source)
Copy an array to another.
Note
this will create a new array with the same capacity and size as the source array.
- Parameters:
target -- pointer to an
lv_array_t
variable to copy tosource -- pointer to an
lv_array_t
variable to copy from
-
static inline void lv_array_clear(lv_array_t *array)
Remove all elements in array.
- Parameters:
array -- pointer to an
lv_array_t
variable
-
lv_result_t lv_array_remove(lv_array_t *array, uint32_t index)
Remove the element at the specified position in the array.
- Parameters:
array -- pointer to an
lv_array_t
variableindex -- the index of the element to remove
- Returns:
LV_RESULT_OK: success, otherwise: error
-
lv_result_t lv_array_erase(lv_array_t *array, uint32_t start, uint32_t end)
Remove from the array either a single element or a range of elements ([start, end)).
Note
This effectively reduces the container size by the number of elements removed.
Note
When start equals to end, the function has no effect.
- Parameters:
array -- pointer to an
lv_array_t
variablestart -- the index of the first element to be removed
end -- the index of the first element that is not to be removed
- Returns:
LV_RESULT_OK: success, otherwise: error
-
lv_result_t lv_array_concat(lv_array_t *array, const lv_array_t *other)
Concatenate two arrays. Adds new elements to the end of the array.
Note
The destination array is automatically expanded as necessary.
- Parameters:
array -- pointer to an
lv_array_t
variableother -- pointer to the array to concatenate
- Returns:
LV_RESULT_OK: success, otherwise: error
-
lv_result_t lv_array_push_back(lv_array_t *array, const void *element)
Push back element. Adds a new element to the end of the array. If the array capacity is not enough for the new element, the array will be resized automatically.
- Parameters:
array -- pointer to an
lv_array_t
variableelement -- pointer to the element to add
- Returns:
LV_RESULT_OK: success, otherwise: error
-
lv_result_t lv_array_assign(lv_array_t *array, uint32_t index, const void *value)
Assigns one content to the array, replacing its current content.
- Parameters:
array -- pointer to an
lv_array_t
variableindex -- the index of the element to replace
value -- pointer to the elements to add
- Returns:
true: success; false: error
-
void *lv_array_at(const lv_array_t *array, uint32_t index)
Returns a pointer to the element at position n in the array.
- Parameters:
array -- pointer to an
lv_array_t
variableindex -- the index of the element to return
- Returns:
a pointer to the requested element, NULL if
index
is out of range
-
static inline void *lv_array_front(const lv_array_t *array)
Returns a pointer to the first element in the array.
- Parameters:
array -- pointer to an
lv_array_t
variable- Returns:
a pointer to the first element in the array
-
static inline void *lv_array_back(const lv_array_t *array)
Returns a pointer to the last element in the array.
- Parameters:
array -- pointer to an
lv_array_t
variable
-
struct lv_array_t
- #include <lv_array.h>
Description of a array