Soletta™ Framework
|
Soletta pointer vector is a convenience API to manipulate vectors storing pointers that is based on Soletta Vector. More...
Data Structures | |
struct | sol_ptr_vector |
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers. More... | |
Macros | |
#define | SOL_PTR_VECTOR_FOREACH_IDX(vector, itrvar, idx) |
Macro to iterate over the pointer vector easily. More... | |
#define | SOL_PTR_VECTOR_FOREACH_IDX_UNTIL(vector, itrvar, idx, until) |
Macro to iterate over the pointer vector until a index. More... | |
#define | SOL_PTR_VECTOR_FOREACH_REVERSE_IDX(vector, itrvar, idx) |
Macro to iterate over the pointer vector easily in the reverse order. More... | |
#define | SOL_PTR_VECTOR_INIT { { NULL, 0, sizeof(void *) } } |
Helper macro to initialize a struct sol_ptr_vector . More... | |
Typedefs | |
typedef struct sol_ptr_vector | sol_ptr_vector |
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers. More... | |
Functions | |
int | sol_ptr_vector_append (struct sol_ptr_vector *pv, const void *ptr) |
Append a pointer to the end of the vector. More... | |
static void | sol_ptr_vector_clear (struct sol_ptr_vector *pv) |
Delete all elements from the vector. More... | |
static int | sol_ptr_vector_del (struct sol_ptr_vector *pv, uint16_t i) |
Remove the pointer of index i from the vector. More... | |
int | sol_ptr_vector_del_element (struct sol_ptr_vector *pv, const void *elem) |
Remove all occurrences of elem from the vector pv . More... | |
static int | sol_ptr_vector_del_last (struct sol_ptr_vector *pv) |
Remove the last element from the vector. More... | |
static int | sol_ptr_vector_del_range (struct sol_ptr_vector *pv, uint16_t start, uint16_t len) |
Remove an range of pointers from the vector. More... | |
static int32_t | sol_ptr_vector_find_first (const struct sol_ptr_vector *pv, const void *elem) |
Find the first occurrence of elem from the vector pv . More... | |
static int32_t | sol_ptr_vector_find_first_sorted (const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2)) |
Find the first occurrence of elem in the sorted vector pv . More... | |
static int32_t | sol_ptr_vector_find_last (const struct sol_ptr_vector *pv, const void *elem) |
Find the last occurrence of elem from the vector pv . More... | |
static int32_t | sol_ptr_vector_find_last_sorted (const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2)) |
Find the last occurrence of elem in the sorted vector pv . More... | |
static int32_t | sol_ptr_vector_find_sorted (const struct sol_ptr_vector *pv, const void *elem, int(*compare_cb)(const void *data1, const void *data2)) |
Find the exact occurrence of elem in the sorted vector pv . More... | |
static void * | sol_ptr_vector_get (const struct sol_ptr_vector *pv, uint16_t i) |
Return the element of the vector at the given index. More... | |
static uint16_t | sol_ptr_vector_get_len (const struct sol_ptr_vector *pv) |
Returns the number of pointers stored in the vector. More... | |
static void * | sol_ptr_vector_get_no_check (const struct sol_ptr_vector *pv, uint16_t i) |
Return the element of the vector at the given index (no safety checks). More... | |
static void | sol_ptr_vector_init (struct sol_ptr_vector *pv) |
Initializes a sol_ptr_vector structure. More... | |
int | sol_ptr_vector_init_n (struct sol_ptr_vector *pv, uint16_t n) |
Initializes a sol_ptr_vector structure and preallocates n elements. More... | |
int | sol_ptr_vector_insert_at (struct sol_ptr_vector *pv, uint16_t i, const void *ptr) |
Insert a pointer in the pointer vector at a given position. More... | |
int32_t | sol_ptr_vector_insert_sorted (struct sol_ptr_vector *pv, const void *ptr, int(*compare_cb)(const void *data1, const void *data2)) |
Insert a pointer in the pointer vector, using the given comparison function to determine its position. More... | |
static int32_t | sol_ptr_vector_match_first (const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2)) |
Match for the first occurrence matching template tempt . More... | |
static int32_t | sol_ptr_vector_match_last (const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2)) |
Match for the last occurrence matching template tempt . More... | |
int32_t | sol_ptr_vector_match_sorted (const struct sol_ptr_vector *pv, const void *tempt, int(*compare_cb)(const void *data1, const void *data2)) |
Match for occurrence matching template tempt in the sorted vector pv . More... | |
int | sol_ptr_vector_remove (struct sol_ptr_vector *pv, const void *ptr) |
Remove an pointer from the vector. More... | |
int | sol_ptr_vector_set (struct sol_ptr_vector *pv, uint16_t i, const void *ptr) |
Set the element at index i to be ptr . More... | |
static void * | sol_ptr_vector_steal (struct sol_ptr_vector *pv, uint16_t i) |
Remove and return the element at index i from the vector. More... | |
static void * | sol_ptr_vector_steal_data (struct sol_ptr_vector *pv) |
Steal the memory holding the elements of the vector. More... | |
static void * | sol_ptr_vector_steal_last (struct sol_ptr_vector *pv) |
Remove and return the last element from the vector. More... | |
int32_t | sol_ptr_vector_update_sorted (struct sol_ptr_vector *pv, uint16_t i, int(*compare_cb)(const void *data1, const void *data2)) |
Update sorted pointer vector so the element is still in order. More... | |
Soletta pointer vector is a convenience API to manipulate vectors storing pointers that is based on Soletta Vector.
#define SOL_PTR_VECTOR_FOREACH_IDX | ( | vector, | |
itrvar, | |||
idx | |||
) |
Macro to iterate over the pointer vector easily.
vector | The pointer vector to iterate over |
itrvar | Variable pointing to the data on each iteration |
idx | Index integer variable that is increased while iterating |
Referenced by _sol_glib_integration_source_fd_handler_data_find(), api_close(), get_location_object_status(), on_stdin(), request_input(), shutdown(), shutdown_server(), sol_netctl_find_service_by_name(), sol_ptr_vector_find_first(), and sol_ptr_vector_match_first().
#define SOL_PTR_VECTOR_FOREACH_IDX_UNTIL | ( | vector, | |
itrvar, | |||
idx, | |||
until | |||
) |
Macro to iterate over the pointer vector until a index.
vector | The pointer vector to iterate over |
itrvar | Variable pointing to the current element's data on each iteration |
idx | Index integer variable that is increased while iterating |
until | The index that the iteration should stop |
#define SOL_PTR_VECTOR_FOREACH_REVERSE_IDX | ( | vector, | |
itrvar, | |||
idx | |||
) |
Macro to iterate over the pointer vector easily in the reverse order.
vector | The pointer vector to iterate over |
itrvar | Variable pointing to the data on each iteration |
idx | Index integer variable that is decreased while iterating |
Referenced by _sol_glib_integration_source_dispose(), _sol_glib_integration_source_fd_handlers_adjust(), sol_ptr_vector_find_last(), and sol_ptr_vector_match_last().
#define SOL_PTR_VECTOR_INIT { { NULL, 0, sizeof(void *) } } |
Helper macro to initialize a struct
sol_ptr_vector
.
typedef struct sol_ptr_vector sol_ptr_vector |
Soletta pointer vector is a wrapper around vector with an API more convenient to handle pointers.
NULL
pointers in the vector since some functions will return NULL
as an error when failing to retrieve the data from vector elements.int sol_ptr_vector_append | ( | struct sol_ptr_vector * | pv, |
const void * | ptr | ||
) |
Append a pointer to the end of the vector.
Creates a new element in end of the vector and stores ptr
on it.
pv | Pointer Vector pointer |
ptr | Pointer to be stored |
0
on success, error code (always negative) otherwiseReferenced by _sol_glib_integration_source_fd_handlers_adjust(), hash_file(), hash_stdin(), my_stream_api_feed(), request_events_cb(), and request_input().
|
inlinestatic |
Delete all elements from the vector.
And frees the memory allocated for them. The vector returns to the initial state (empty).
pv | Pointer Vector pointer |
References sol_ptr_vector::base, and sol_vector_clear().
Referenced by _sol_glib_integration_source_dispose(), api_close(), request_input(), shutdown(), and shutdown_server().
|
inlinestatic |
Remove the pointer of index i
from the vector.
pv | Pointer Vector pointer |
i | Index of the element to remove |
0
on success, error code (always negative) otherwiseReferences sol_ptr_vector::base, and sol_vector_del().
Referenced by _can_write(), _sol_glib_integration_source_fd_handlers_adjust(), sol_ptr_vector_del_last(), and sol_ptr_vector_steal().
int sol_ptr_vector_del_element | ( | struct sol_ptr_vector * | pv, |
const void * | elem | ||
) |
Remove all occurrences of elem
from the vector pv
.
pv | Pointer Vector pointer |
elem | Element to remove |
0
on success, error code (always negative) otherwiseReferenced by my_stream_api_feed().
|
inlinestatic |
Remove the last element from the vector.
pv | Pointer Vector pointer |
0
on success, error code (always negative) otherwiseReferences sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_del().
|
inlinestatic |
Remove an range of pointers from the vector.
Removes the range starting at index start from the vector and goes until start + len.
pv | Pointer Vector pointer |
start | Index of the first element to remove |
len | the number of elements to remover |
0
on success, error code (always negative) otherwise References sol_ptr_vector::base, and sol_vector_del_range().
|
inlinestatic |
Find the first occurrence of elem
from the vector pv
.
pv | Pointer Vector pointer |
elem | Element to find |
References SOL_PTR_VECTOR_FOREACH_IDX.
|
inlinestatic |
Find the first occurrence of elem
in the sorted vector pv
.
pv | Pointer Vector pointer (already sorted) |
elem | Element to find |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().
|
inlinestatic |
Find the last occurrence of elem
from the vector pv
.
pv | Pointer Vector pointer |
elem | Element to find |
References SOL_PTR_VECTOR_FOREACH_REVERSE_IDX.
|
inlinestatic |
Find the last occurrence of elem
in the sorted vector pv
.
pv | Pointer Vector pointer (already sorted) |
elem | Element to find |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().
|
inlinestatic |
Find the exact occurrence of elem
in the sorted vector pv
.
This function will find the exact pointer to elem, so an existing element must be used. For a query-element (only used for reference in the compare_cb), use sol_ptr_vector_match_sorted().
Unlike sol_ptr_vector_find_first_sorted() and sol_ptr_vector_find_last_sorted(), it will do a binary search and return the first occurrence of the pointer elem. In the case of multiple occurrences, it may be an element in the middle of those that would match (compare_cb returns 0).
pv | Pointer Vector pointer (already sorted) |
elem | Element to find |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
References sol_ptr_vector::base, sol_vector::len, sol_ptr_vector_get_no_check(), and sol_ptr_vector_match_sorted().
|
inlinestatic |
Return the element of the vector at the given index.
pv | Pointer Vector pointer |
i | Index of the element to return |
i
and NULL
on errors.References sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_get_no_check().
Referenced by _can_write(), and sol_ptr_vector_steal().
|
inlinestatic |
Returns the number of pointers stored in the vector.
pv | Pointer to the struct sol_ptr_vector to be initialized |
References sol_ptr_vector::base, and sol_vector::len.
Referenced by _can_write(), delete_cb(), and get_location_object_status().
|
inlinestatic |
Return the element of the vector at the given index (no safety checks).
This is similar to sol_ptr_vector_get(), but does no safety checks such as array boundaries. Only use this whenever you're sure the index i exists.
pv | Pointer Vector pointer |
i | Index of the element to return |
i
.References sol_ptr_vector::base, sol_vector::data, and sol_vector_get_no_check().
Referenced by sol_ptr_vector_find_first_sorted(), sol_ptr_vector_find_last_sorted(), sol_ptr_vector_find_sorted(), and sol_ptr_vector_get().
|
inlinestatic |
Initializes a sol_ptr_vector
structure.
pv | Pointer to the struct sol_ptr_vector to be initialized |
References sol_ptr_vector::base, and sol_vector_init().
Referenced by my_stream_api_new(), request_input(), and sol_glib_integration().
int sol_ptr_vector_init_n | ( | struct sol_ptr_vector * | pv, |
uint16_t | n | ||
) |
Initializes a sol_ptr_vector
structure and preallocates n
elements.
pv | Pointer to the struct sol_ptr_vector to be initialized |
n | Number of elements that should be preallocated |
n
int sol_ptr_vector_insert_at | ( | struct sol_ptr_vector * | pv, |
uint16_t | i, | ||
const void * | ptr | ||
) |
Insert a pointer in the pointer vector at a given position.
This function inserts a new element ptr at index i. All existing elements with index greater than i will be moved, thus their index will increase by one. If the index is the last position (sol_ptr_vector_get_len()), then it will have the same effect as sol_ptr_vector_append().
pv | Pointer Vector pointer |
i | Index to insert element at. |
ptr | The pointer |
int32_t sol_ptr_vector_insert_sorted | ( | struct sol_ptr_vector * | pv, |
const void * | ptr, | ||
int(*)(const void *data1, const void *data2) | compare_cb | ||
) |
Insert a pointer in the pointer vector, using the given comparison function to determine its position.
This function should be stable, if the new element ptr matches an existing in the vector (ie: compare_cb returns 0), then it will insert the new element after the last matching, keeping instances in a stable order.
pv | Pointer Vector pointer |
ptr | The pointer |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
|
inlinestatic |
Match for the first occurrence matching template tempt
.
pv | Pointer Vector pointer |
tempt | The template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0. |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
References SOL_PTR_VECTOR_FOREACH_IDX.
|
inlinestatic |
Match for the last occurrence matching template tempt
.
pv | Pointer Vector pointer |
tempt | The template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0. |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
References SOL_PTR_VECTOR_FOREACH_REVERSE_IDX.
int32_t sol_ptr_vector_match_sorted | ( | const struct sol_ptr_vector * | pv, |
const void * | tempt, | ||
int(*)(const void *data1, const void *data2) | compare_cb | ||
) |
Match for occurrence matching template tempt
in the sorted vector pv
.
pv | Pointer Vector pointer (already sorted) |
tempt | The template used to find, the returned index may not be of tempt pointer, but to another element which makes compare_cb return 0. |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |
Referenced by sol_ptr_vector_find_first_sorted(), sol_ptr_vector_find_last_sorted(), and sol_ptr_vector_find_sorted().
int sol_ptr_vector_remove | ( | struct sol_ptr_vector * | pv, |
const void * | ptr | ||
) |
Remove an pointer from the vector.
Removes the last occurrence of the pointer ptr
from the vector. To delete all use sol_ptr_vector_del_element()
pv | Pointer Vector pointer |
ptr | Pointer to remove |
0
on success, error code (always negative) otherwiseptr
position and the end of the vectorReferenced by delete_cb().
int sol_ptr_vector_set | ( | struct sol_ptr_vector * | pv, |
uint16_t | i, | ||
const void * | ptr | ||
) |
Set the element at index i
to be ptr
.
pv | Pointer Vector pointer |
i | Index of the element to set |
ptr | The pointer |
0
on success, error code (always negative) otherwise
|
inlinestatic |
Remove and return the element at index i
from the vector.
pv | Pointer Vector pointer |
i | Index of the element to retrieved |
i
, NULL
otherwiseReferences sol_ptr_vector_del(), and sol_ptr_vector_get().
Referenced by sol_ptr_vector_steal_last().
|
inlinestatic |
Steal the memory holding the elements of the vector.
And returns the vector to the initial state.
pv | Pointer Vector pointer |
References sol_ptr_vector::base, and sol_vector_steal_data().
|
inlinestatic |
Remove and return the last element from the vector.
pv | Pointer Vector pointer |
NULL
otherwiseReferences sol_ptr_vector::base, sol_vector::len, and sol_ptr_vector_steal().
int32_t sol_ptr_vector_update_sorted | ( | struct sol_ptr_vector * | pv, |
uint16_t | i, | ||
int(*)(const void *data1, const void *data2) | compare_cb | ||
) |
Update sorted pointer vector so the element is still in order.
This function takes an index i
and checks it is in correct order in the previously sorted array. It is an optimized version to be used instead of deleting and inserting it again, so array size is untouched.
pv | Pointer Vector pointer |
i | The index that was updated and may be repositioned |
compare_cb | Function to compare elements in the list. It should return an integer less than, equal to, or greater than zero if data1 is found, respectively, to be less than, to match, or be greater than data2 in the sort order |