Asterisk - The Open Source Telephony Project GIT-master-3dae2cf
|
Vector container support. More...
#include "asterisk/lock.h"
Go to the source code of this file.
Data Structures | |
struct | ast_vector_const_string |
struct | ast_vector_int |
Integer vector definition. More... | |
struct | ast_vector_string |
String vector definitions. More... | |
Macros | |
#define | __make_room(idx, vec) |
#define | AST_VECTOR(name, type) |
Define a vector structure. More... | |
#define | AST_VECTOR_ADD_SORTED(vec, elem, cmp) |
Add an element into a sorted vector. More... | |
#define | AST_VECTOR_APPEND(vec, elem) |
Append an element to a vector, growing the vector if needed. More... | |
#define | AST_VECTOR_CALLBACK(vec, callback, default_value, ...) |
Execute a callback on every element in a vector returning the first matched. More... | |
#define | AST_VECTOR_CALLBACK_MULTIPLE(vec, callback, ...) |
Execute a callback on every element in a vector returning the matching elements in a new vector. More... | |
#define | AST_VECTOR_CALLBACK_VOID(vec, callback, ...) |
Execute a callback on every element in a vector disregarding callback return. More... | |
#define | AST_VECTOR_COMPACT(vec) |
Resize a vector so that its capacity is the same as its size. More... | |
#define | AST_VECTOR_DEFAULT(vec, size, value) |
Default a vector up to size with the given value. More... | |
#define | AST_VECTOR_ELEM_CLEANUP_NOOP(elem) |
Vector element cleanup that does nothing. More... | |
#define | AST_VECTOR_ELEM_DEFAULT_CMP(elem, value) ((elem) == (value)) |
Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED() More... | |
#define | AST_VECTOR_FREE(vec) |
Deallocates this vector. More... | |
#define | AST_VECTOR_GET(vec, idx) |
Get an element from a vector. More... | |
#define | AST_VECTOR_GET_ADDR(vec, idx) |
Get an address of element in a vector. More... | |
#define | AST_VECTOR_GET_CMP(vec, value, cmp) |
Get an element from a vector that matches the given comparison. More... | |
#define | AST_VECTOR_GET_INDEX(vec, value, cmp) AST_VECTOR_GET_INDEX_NTH(vec, 1, value, cmp) |
Get the 1st index from a vector that matches the given comparison. More... | |
#define | AST_VECTOR_GET_INDEX_NTH(vec, nth, value, cmp) |
Get the nth index from a vector that matches the given comparison. More... | |
#define | AST_VECTOR_INIT(vec, size) |
Initialize a vector. More... | |
#define | AST_VECTOR_INSERT_AT(vec, idx, elem) |
Insert an element at a specific position in a vector, growing the vector if needed. More... | |
#define | AST_VECTOR_MATCH_ALL(element) (CMP_MATCH) |
Default callback for AST_VECTOR_CALLBACK() More... | |
#define | AST_VECTOR_MAX_SIZE(vec) (vec)->max |
Get the maximum number of elements the vector can currently hold. More... | |
#define | AST_VECTOR_PTR_FREE(vec) |
Deallocates this vector pointer. More... | |
#define | AST_VECTOR_REMOVE(vec, idx, preserve_ordered) |
Remove an element from a vector by index. More... | |
#define | AST_VECTOR_REMOVE_ALL_CMP_ORDERED(vec, value, cmp, cleanup) |
Remove all elements from a vector that matches the given comparison while maintaining order. More... | |
#define | AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(vec, value, cmp, cleanup) |
Remove all elements from a vector that matches the given comparison. More... | |
#define | AST_VECTOR_REMOVE_CMP_ORDERED(vec, value, cmp, cleanup) |
Remove an element from a vector that matches the given comparison while maintaining order. More... | |
#define | AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup) |
Remove an element from a vector that matches the given comparison. More... | |
#define | AST_VECTOR_REMOVE_ELEM_ORDERED(vec, elem, cleanup) |
Remove an element from a vector while maintaining order. More... | |
#define | AST_VECTOR_REMOVE_ELEM_UNORDERED(vec, elem, cleanup) |
Remove an element from a vector. More... | |
#define | AST_VECTOR_REMOVE_ORDERED(vec, idx) AST_VECTOR_REMOVE(vec, idx, 1) |
Remove an element from a vector by index while maintaining order. More... | |
#define | AST_VECTOR_REMOVE_UNORDERED(vec, idx) AST_VECTOR_REMOVE(vec, idx, 0) |
Remove an element from an unordered vector by index. More... | |
#define | AST_VECTOR_REPLACE(vec, idx, elem) |
Replace an element at a specific position in a vector, growing the vector if needed. More... | |
#define | AST_VECTOR_RESET(vec, cleanup) |
Reset vector. More... | |
#define | AST_VECTOR_RW(name, type) |
Define a vector structure with a read/write lock. More... | |
#define | AST_VECTOR_RW_FREE(vec) |
Deallocates this locked vector. More... | |
#define | AST_VECTOR_RW_INIT(vec, size) |
Initialize a vector with a read/write lock. More... | |
#define | AST_VECTOR_RW_PTR_FREE(vec) |
Deallocates this locked vector pointer. More... | |
#define | AST_VECTOR_RW_RDLOCK(vec) ast_rwlock_rdlock(&(vec)->lock) |
Obtain read lock on vector. More... | |
#define | AST_VECTOR_RW_RDLOCK_TIMED(vec, timespec) ast_rwlock_timedrdlock(&(vec)->lock, timespec) |
Try to obtain read lock on vector failing after timeout if unable. More... | |
#define | AST_VECTOR_RW_RDLOCK_TRY(vec) ast_rwlock_tryrdlock(&(vec)->lock) |
Try to obtain read lock on vector failing immediately if unable. More... | |
#define | AST_VECTOR_RW_UNLOCK(vec) ast_rwlock_unlock(&(vec)->lock) |
Unlock vector. More... | |
#define | AST_VECTOR_RW_WRLOCK(vec) ast_rwlock_wrlock(&(vec)->lock) |
Obtain write lock on vector. More... | |
#define | AST_VECTOR_RW_WRLOCK_TIMED(vec, timespec) ast_rwlock_timedwrlock(&(vec)->lock, timespec) |
Try to obtain write lock on vector failing after timeout if unable. More... | |
#define | AST_VECTOR_RW_WRLOCK_TRY(vec) ast_rwlock_trywrlock(&(vec)->lock) |
Try to obtain write lock on vector failing immediately if unable. More... | |
#define | AST_VECTOR_SIZE(vec) (vec)->current |
Get the number of elements in a vector. More... | |
#define | AST_VECTOR_SORT(vec, cmp) |
Sort a vector in-place. More... | |
#define | AST_VECTOR_STEAL_ELEMENTS(vec) |
Steal the elements from a vector and reinitialize. More... | |
Enumerations | |
enum | ast_vector_string_split_flags { AST_VECTOR_STRING_SPLIT_NO_TRIM = 0x01 , AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY = 0x02 } |
Functions | |
int | ast_vector_string_split (struct ast_vector_string *dest, const char *input, const char *delim, int flags, int(*excludes_cmp)(const char *s1, const char *s2)) |
Append a string vector by splitting a string. More... | |
Vector container support.
A vector is a variable length array, with properties that can be useful when order doesn't matter.
Definition in file vector.h.
#define AST_VECTOR_ADD_SORTED | ( | vec, | |
elem, | |||
cmp | |||
) |
Add an element into a sorted vector.
vec | Sorted vector to add to. |
elem | Element to insert. Must not be an array type. |
cmp | A strcmp compatible compare function. |
0 | on success. |
Non-zero | on failure. |
#define AST_VECTOR_APPEND | ( | vec, | |
elem | |||
) |
#define AST_VECTOR_CALLBACK | ( | vec, | |
callback, | |||
default_value, | |||
... | |||
) |
Execute a callback on every element in a vector returning the first matched.
vec | Vector to operate on. |
callback | A callback that takes at least 1 argument (the element) plus number of optional arguments |
default_value | A default value to return if no elements matched |
#define AST_VECTOR_CALLBACK_MULTIPLE | ( | vec, | |
callback, | |||
... | |||
) |
Execute a callback on every element in a vector returning the matching elements in a new vector.
This macro basically provides a filtered clone.
vec | Vector to operate on. |
callback | A callback that takes at least 1 argument (the element) plus number of optional arguments |
The following will result in "error: assignment from incompatible pointer type" because these declare 2 different structures.
This will work because you're using the type of the first to declare the second:
This will also work because you're declaring both vector_1 and vector_2 from the same definition.
#define AST_VECTOR_CALLBACK_VOID | ( | vec, | |
callback, | |||
... | |||
) |
#define AST_VECTOR_COMPACT | ( | vec | ) |
#define AST_VECTOR_DEFAULT | ( | vec, | |
size, | |||
value | |||
) |
Default a vector up to size with the given value.
vec | Vector to default. |
size | The number of elements to default |
value | The default value to set each element to |
#define AST_VECTOR_ELEM_CLEANUP_NOOP | ( | elem | ) |
Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
elem | Element to compare against |
value | Value to compare with the vector element. |
0 | if element does not match. |
Non-zero | if element matches. |
#define AST_VECTOR_FREE | ( | vec | ) |
#define AST_VECTOR_GET | ( | vec, | |
idx | |||
) |
#define AST_VECTOR_GET_ADDR | ( | vec, | |
idx | |||
) |
#define AST_VECTOR_GET_CMP | ( | vec, | |
value, | |||
cmp | |||
) |
#define AST_VECTOR_GET_INDEX | ( | vec, | |
value, | |||
cmp | |||
) | AST_VECTOR_GET_INDEX_NTH(vec, 1, value, cmp) |
#define AST_VECTOR_GET_INDEX_NTH | ( | vec, | |
nth, | |||
value, | |||
cmp | |||
) |
Get the nth index from a vector that matches the given comparison.
vec | Vector to get from. |
nth | The nth index to find |
value | Value to pass into comparator. |
cmp | Comparator function/macros (called as cmp(elem, value) ) |
#define AST_VECTOR_INIT | ( | vec, | |
size | |||
) |
#define AST_VECTOR_INSERT_AT | ( | vec, | |
idx, | |||
elem | |||
) |
Insert an element at a specific position in a vector, growing the vector if needed.
vec | Vector to insert into. |
idx | Position to insert at. |
elem | Element to insert. |
0 | on success. |
Non-zero | on failure. |
#define AST_VECTOR_MATCH_ALL | ( | element | ) | (CMP_MATCH) |
Default callback for AST_VECTOR_CALLBACK()
element | Element to compare against |
CMP_MATCH | always. |
#define AST_VECTOR_MAX_SIZE | ( | vec | ) | (vec)->max |
#define AST_VECTOR_PTR_FREE | ( | vec | ) |
#define AST_VECTOR_REMOVE | ( | vec, | |
idx, | |||
preserve_ordered | |||
) |
Remove an element from a vector by index.
Note that elements in the vector may be reordered, so that the remove can happen in constant time.
vec | Vector to remove from. |
idx | Index of the element to remove. |
preserve_ordered | Preserve the vector order. |
Remove all elements from a vector that matches the given comparison while maintaining order.
vec | Vector to remove from. |
value | Value to pass into comparator. |
cmp | Comparator function/macros (called as cmp(elem, value) ) |
cleanup | How to cleanup a removed element macro/function. |
Remove all elements from a vector that matches the given comparison.
vec | Vector to remove from. |
value | Value to pass into comparator. |
cmp | Comparator function/macros (called as cmp(elem, value) ) |
cleanup | How to cleanup a removed element macro/function. |
Remove an element from a vector that matches the given comparison while maintaining order.
vec | Vector to remove from. |
value | Value to pass into comparator. |
cmp | Comparator function/macros (called as cmp(elem, value) ) |
cleanup | How to cleanup a removed element macro/function. |
0 | if element was removed. |
Non-zero | if element was not in the vector. |
Remove an element from a vector that matches the given comparison.
vec | Vector to remove from. |
value | Value to pass into comparator. |
cmp | Comparator function/macros (called as cmp(elem, value) ) |
cleanup | How to cleanup a removed element macro/function. |
0 | if element was removed. |
Non-zero | if element was not in the vector. |
#define AST_VECTOR_REMOVE_ELEM_ORDERED | ( | vec, | |
elem, | |||
cleanup | |||
) |
Remove an element from a vector while maintaining order.
vec | Vector to remove from. |
elem | Element to remove |
cleanup | How to cleanup a removed element macro/function. |
0 | if element was removed. |
Non-zero | if element was not in the vector. |
#define AST_VECTOR_REMOVE_ELEM_UNORDERED | ( | vec, | |
elem, | |||
cleanup | |||
) |
Remove an element from a vector.
vec | Vector to remove from. |
elem | Element to remove |
cleanup | How to cleanup a removed element macro/function. |
0 | if element was removed. |
Non-zero | if element was not in the vector. |
#define AST_VECTOR_REMOVE_ORDERED | ( | vec, | |
idx | |||
) | AST_VECTOR_REMOVE(vec, idx, 1) |
#define AST_VECTOR_REMOVE_UNORDERED | ( | vec, | |
idx | |||
) | AST_VECTOR_REMOVE(vec, idx, 0) |
Remove an element from an unordered vector by index.
Note that elements in the vector may be reordered, so that the remove can happen in constant time.
vec | Vector to remove from. |
idx | Index of the element to remove. |
#define AST_VECTOR_REPLACE | ( | vec, | |
idx, | |||
elem | |||
) |
Replace an element at a specific position in a vector, growing the vector if needed.
vec | Vector to replace into. |
idx | Position to replace. |
elem | Element to replace. |
0 | on success. |
Non-zero | on failure. |
#define AST_VECTOR_RESET | ( | vec, | |
cleanup | |||
) |
#define AST_VECTOR_RW_FREE | ( | vec | ) |
Deallocates this locked vector.
If any code to free the elements of this vector need to be run, that should be done prior to this call.
vec | Vector to deallocate. |
#define AST_VECTOR_RW_INIT | ( | vec, | |
size | |||
) |
#define AST_VECTOR_RW_PTR_FREE | ( | vec | ) |
Deallocates this locked vector pointer.
If any code to free the elements of this vector need to be run, that should be done prior to this call.
vec | Pointer to a malloc'd vector structure. |
#define AST_VECTOR_RW_RDLOCK | ( | vec | ) | ast_rwlock_rdlock(&(vec)->lock) |
#define AST_VECTOR_RW_RDLOCK_TIMED | ( | vec, | |
timespec | |||
) | ast_rwlock_timedrdlock(&(vec)->lock, timespec) |
#define AST_VECTOR_RW_RDLOCK_TRY | ( | vec | ) | ast_rwlock_tryrdlock(&(vec)->lock) |
#define AST_VECTOR_RW_UNLOCK | ( | vec | ) | ast_rwlock_unlock(&(vec)->lock) |
#define AST_VECTOR_RW_WRLOCK | ( | vec | ) | ast_rwlock_wrlock(&(vec)->lock) |
#define AST_VECTOR_RW_WRLOCK_TIMED | ( | vec, | |
timespec | |||
) | ast_rwlock_timedwrlock(&(vec)->lock, timespec) |
#define AST_VECTOR_RW_WRLOCK_TRY | ( | vec | ) | ast_rwlock_trywrlock(&(vec)->lock) |
#define AST_VECTOR_SIZE | ( | vec | ) | (vec)->current |
#define AST_VECTOR_SORT | ( | vec, | |
cmp | |||
) |
#define AST_VECTOR_STEAL_ELEMENTS | ( | vec | ) |
Steal the elements from a vector and reinitialize.
vec | Vector to operate on. |
This allows you to use vector.h to construct a list and use the data as a bare array.
Options to override default processing of ast_vector_string_split.
Enumerator | |
---|---|
AST_VECTOR_STRING_SPLIT_NO_TRIM | Do not trim whitespace from values. |
AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY | Append empty strings to the vector. |
Definition at line 59 of file vector.h.
int ast_vector_string_split | ( | struct ast_vector_string * | dest, |
const char * | input, | ||
const char * | delim, | ||
int | flags, | ||
int(*)(const char *s1, const char *s2) | excludes_cmp | ||
) |
Append a string vector by splitting a string.
dest | Pointer to an initialized vector. |
input | String buffer to split. |
delim | String delimeter passed to strsep. |
flags | Processing options defined by ast_vector_string_split_flags. |
excludes_cmp | NULL or a function like strcmp to exclude duplicate strings. |
0 | Success |
-1 | Failure |
Definition at line 392 of file strings.c.
References ast_assert, ast_free, ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero(), AST_VECTOR_APPEND, AST_VECTOR_GET_CMP, AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY, AST_VECTOR_STRING_SPLIT_NO_TRIM, buf, input(), NULL, and strsep().
Referenced by module_post_register().