This file provides a simple (non-type safe) array for elements with (optional) in-place construction support. More...
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
Go to the source code of this file.
Data Structures | |
struct | SimpleArrayConfig |
Simple Array configuration structure. More... | |
Functions | |
SimpleArray * | simple_array_alloc (const SimpleArrayConfig *config) |
Allocate a SimpleArray instance with the given configuration. | |
void | simple_array_free (SimpleArray *instance) |
Free a SimpleArray instance and release its contents. | |
void | simple_array_init (SimpleArray *instance, uint32_t count) |
Initialise a SimpleArray instance by allocating additional space to contain the requested number of elements. | |
void | simple_array_reset (SimpleArray *instance) |
Reset a SimpleArray instance and delete all of its elements. | |
void | simple_array_copy (SimpleArray *instance, const SimpleArray *other) |
Copy (duplicate) another SimpleArray instance to this one. | |
bool | simple_array_is_equal (const SimpleArray *instance, const SimpleArray *other) |
Check if another SimpleArray instance is equal (the same object or holds the same data) to this one. | |
uint32_t | simple_array_get_count (const SimpleArray *instance) |
Get the count of elements currently contained in a SimpleArray instance. | |
SimpleArrayElement * | simple_array_get (SimpleArray *instance, uint32_t index) |
Get a pointer to an element contained in a SimpleArray instance. | |
const SimpleArrayElement * | simple_array_cget (const SimpleArray *instance, uint32_t index) |
Get a const pointer to an element contained in a SimpleArray instance. | |
SimpleArrayData * | simple_array_get_data (SimpleArray *instance) |
Get a pointer to the internal data of a SimpleArray instance. | |
const SimpleArrayData * | simple_array_cget_data (const SimpleArray *instance) |
Get a constant pointer to the internal data of a SimpleArray instance. | |
Variables | |
const SimpleArrayConfig | simple_array_config_uint8_t |
This file provides a simple (non-type safe) array for elements with (optional) in-place construction support.
No append, remove or take operations are supported. Instead, the user must call simple_array_init() in order to reserve the memory for n elements. In case if init() is specified in the configuration, then the elements are constructed in-place.
To clear all elements from the array, call simple_array_reset(), which will also call reset() for each element in case if it was specified in the configuration. This is useful if a custom destructor is required for a particular type. Calling simple_array_free() will also result in a simple_array_reset() call automatically.
SimpleArray * simple_array_alloc | ( | const SimpleArrayConfig * | config | ) |
Allocate a SimpleArray instance with the given configuration.
[in] | config | Pointer to the type-specific configuration |
const SimpleArrayElement * simple_array_cget | ( | const SimpleArray * | instance, |
uint32_t | index ) |
Get a const pointer to an element contained in a SimpleArray instance.
[in] | instance | Pointer to the SimpleArray instance to get an element from |
[in] | index | Index of the element in question. MUST be less than total element count |
const SimpleArrayData * simple_array_cget_data | ( | const SimpleArray * | instance | ) |
Get a constant pointer to the internal data of a SimpleArray instance.
[in] | instance | Pointer to the SimpleArray instance to get the data of |
void simple_array_copy | ( | SimpleArray * | instance, |
const SimpleArray * | other ) |
Copy (duplicate) another SimpleArray instance to this one.
If copy() is specified in the config, then it is called for each element, otherwise the data is simply memcpy()'d.
[in] | instance | Pointer to the SimpleArray instance to copy to |
[in] | other | Pointer to the SimpleArray instance to copy from |
void simple_array_free | ( | SimpleArray * | instance | ) |
Free a SimpleArray instance and release its contents.
[in] | instance | Pointer to the SimpleArray instance to be freed |
SimpleArrayElement * simple_array_get | ( | SimpleArray * | instance, |
uint32_t | index ) |
Get a pointer to an element contained in a SimpleArray instance.
[in] | instance | Pointer to the SimpleArray instance to get an element from |
[in] | index | Index of the element in question. MUST be less than total element count |
uint32_t simple_array_get_count | ( | const SimpleArray * | instance | ) |
Get the count of elements currently contained in a SimpleArray instance.
[in] | instance | Pointer to the SimpleArray instance to query the count from |
SimpleArrayData * simple_array_get_data | ( | SimpleArray * | instance | ) |
Get a pointer to the internal data of a SimpleArray instance.
[in] | instance | Pointer to the SimpleArray instance to get the data of |
void simple_array_init | ( | SimpleArray * | instance, |
uint32_t | count ) |
Initialise a SimpleArray instance by allocating additional space to contain the requested number of elements.
If init() is specified in the config, then it is called for each element, otherwise the data is filled with zeroes.
[in] | instance | Pointer to the SimpleArray instance to be init'd |
[in] | count | Number of elements to be allocated and init'd |
bool simple_array_is_equal | ( | const SimpleArray * | instance, |
const SimpleArray * | other ) |
Check if another SimpleArray instance is equal (the same object or holds the same data) to this one.
[in] | instance | Pointer to the SimpleArray instance to be compared |
[in] | other | Pointer to the SimpleArray instance to be compared |
void simple_array_reset | ( | SimpleArray * | instance | ) |
Reset a SimpleArray instance and delete all of its elements.
If reset() is specified in the config, then it is called for each element, otherwise the data is simply free()'d.
[in] | instance | Pointer to the SimpleArray instance to be reset |