ocssw
V2022
|
#include <stdlib.h>
Go to the source code of this file.
Classes | |
struct | EPR_SPtrArray |
Functions | |
EPR_SPtrArray * | epr_create_ptr_array (unsigned int capacity) |
void | epr_free_ptr_array (EPR_SPtrArray *ptr_array) |
void | epr_free_char_ptr_array (EPR_SPtrArray *char_ptr_array) |
int | epr_add_ptr_array_elem (EPR_SPtrArray *ptr_array, void *elem) |
int | epr_grow_ptr_array (EPR_SPtrArray *ptr_array, unsigned int capacity) |
unsigned int | epr_get_ptr_array_length (const EPR_SPtrArray *ptr_array) |
unsigned int | epr_get_ptr_array_capacity (const EPR_SPtrArray *ptr_array) |
void * | epr_get_ptr_array_elem_at (const EPR_SPtrArray *ptr_array, unsigned int index) |
Function Documentation
◆ epr_add_ptr_array_elem()
int epr_add_ptr_array_elem | ( | EPR_SPtrArray * | ptr_array, |
void * | elem | ||
) |
Adds a new pointer to the given pointer array. The function automatically grows the array if necessary.
- Parameters
-
ptr_array the pointer array to which to add the new element, must not be NULL. elem the element to be added
- Returns
- zero for success, an error code otherwise
Definition at line 75 of file epr_ptrarray.c.
◆ epr_create_ptr_array()
EPR_SPtrArray* epr_create_ptr_array | ( | unsigned int | capacity | ) |
Creates a new dynamic pointer array instance.
- Parameters
-
capacity the initial capacity
- Returns
- a new dynamic pointer array instance with the given capacity or
NULL
if memory could not be allocated
Definition at line 29 of file epr_ptrarray.c.
◆ epr_free_char_ptr_array()
void epr_free_char_ptr_array | ( | EPR_SPtrArray * | char_ptr_array | ) |
Special application of the epr_free_ptr_array
for arrays that contain dynamically allocated strings (type char*
).
For each element in the given array the epr_free_string
function is called.
- Parameters
-
char_ptr_array an array containing strings
Definition at line 65 of file epr_ptrarray.c.
◆ epr_free_ptr_array()
void epr_free_ptr_array | ( | EPR_SPtrArray * | ptr_array | ) |
Frees the memory allocated through the given dynamic pointer array.
After calling this function the give record pointer array gets invalid and should not be used anymore.
- Parameters
-
ptr_array the pointer array to be released, if NULL
the function immediately returns
Definition at line 51 of file epr_ptrarray.c.
◆ epr_get_ptr_array_capacity()
unsigned int epr_get_ptr_array_capacity | ( | const EPR_SPtrArray * | ptr_array | ) |
Returns the capacity of the given pointer array.
- Parameters
-
ptr_array the pointer array, must not be NULL.
- Returns
- the capacity of the given pointer array
◆ epr_get_ptr_array_elem_at()
void* epr_get_ptr_array_elem_at | ( | const EPR_SPtrArray * | ptr_array, |
unsigned int | index | ||
) |
Gets the element with the specified index of the given pointer array.
- Parameters
-
ptr_array the pointer array, must not be NULL. index the zero-based index, must be less than the array's length
- Returns
- the element at the given index
Definition at line 122 of file epr_ptrarray.c.
◆ epr_get_ptr_array_length()
unsigned int epr_get_ptr_array_length | ( | const EPR_SPtrArray * | ptr_array | ) |
Returns the length of the given pointer array.
- Parameters
-
ptr_array the pointer array, must not be NULL.
- Returns
- the length of the given pointer array
Definition at line 115 of file epr_ptrarray.c.
◆ epr_grow_ptr_array()
int epr_grow_ptr_array | ( | EPR_SPtrArray * | ptr_array, |
unsigned int | capacity | ||
) |
Grows the given pointer array so that is has the given capacity. The length of the array is not touched by this function.
- Parameters
-
ptr_array the pointer array to which to add the new element, must not be NULL. capacity the new capacity
- Returns
- zero for success, an error code otherwise
Definition at line 91 of file epr_ptrarray.c.