lv_array.h

Array. The elements are dynamically allocated by the 'lv_mem' module.

Defines

LV_ARRAY_DEFAULT_CAPACITY
LV_ARRAY_DEFAULT_SHRINK_RATIO

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 initialize

  • capacity – the initial capacity of the array

  • element_size – the size of an element in bytes

void lv_array_init_from_buf(lv_array_t *array, void *buf, uint32_t capacity, uint32_t element_size)

Init an array from a buffer.

Note

The buffer must be large enough to store capacity elements. The array will not release the buffer and reallocate it. The user must ensure that the buffer is valid during the lifetime of the array. And release the buffer when the array is no longer needed.

Parameters:
  • array – pointer to an lv_array_t variable to initialize

  • buf – pointer to a buffer to use as the array's data

  • capacity – the initial capacity of the array

  • element_size – the size of an element in bytes

bool 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 variable

  • new_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

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

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

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

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 to

  • source – pointer to an lv_array_t variable to copy from

void lv_array_clear(lv_array_t *array)

Remove all elements in array.

Parameters:

array – pointer to an lv_array_t variable

void lv_array_shrink(lv_array_t *array)

Shrink the memory capacity of array if necessary.

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 variable

  • index – 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 variable

  • start – 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 variable

  • other – 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.

Note

If the element is NULL, it will be added as an empty element.

Parameters:
  • array – pointer to an lv_array_t variable

  • element – pointer to the element to add. NULL to push an empty element.

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 variable

  • index – 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 variable

  • index – the index of the element to return

Returns:

a pointer to the requested element, NULL if index is out of range

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

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

Public Members

uint8_t *data
uint32_t size
uint32_t capacity
uint32_t element_size
bool inner_alloc