| Asterisk - The Open Source Telephony Project GIT-master-27fb039
    | 
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. | |
| #define | AST_VECTOR_ADD_SORTED(vec, elem, cmp) | 
| Add an element into a sorted vector. | |
| #define | AST_VECTOR_APPEND(vec, elem) | 
| Append an element to a vector, growing the vector if needed. | |
| #define | AST_VECTOR_CALLBACK(vec, callback, default_value, ...) | 
| Execute a callback on every element in a vector returning the first 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. | |
| #define | AST_VECTOR_CALLBACK_VOID(vec, callback, ...) | 
| Execute a callback on every element in a vector disregarding callback return. | |
| #define | AST_VECTOR_COMPACT(vec) | 
| Resize a vector so that its capacity is the same as its size. | |
| #define | AST_VECTOR_DEFAULT(vec, size, value) | 
| Default a vector up to size with the given value. | |
| #define | AST_VECTOR_ELEM_CLEANUP_NOOP(elem) | 
| Vector element cleanup that does nothing. | |
| #define | AST_VECTOR_ELEM_DEFAULT_CMP(elem, value) ((elem) == (value)) | 
| Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED() | |
| #define | AST_VECTOR_FREE(vec) | 
| Deallocates this vector. | |
| #define | AST_VECTOR_GET(vec, idx) | 
| Get an element from a vector. | |
| #define | AST_VECTOR_GET_ADDR(vec, idx) | 
| Get an address of element in a vector. | |
| #define | AST_VECTOR_GET_CMP(vec, value, cmp) | 
| Get an element from a vector that matches the given comparison. | |
| #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. | |
| #define | AST_VECTOR_GET_INDEX_NTH(vec, nth, value, cmp) | 
| Get the nth index from a vector that matches the given comparison. | |
| #define | AST_VECTOR_INIT(vec, size) | 
| Initialize a vector. | |
| #define | AST_VECTOR_INSERT_AT(vec, idx, elem) | 
| Insert an element at a specific position in a vector, growing the vector if needed. | |
| #define | AST_VECTOR_MATCH_ALL(element) (CMP_MATCH) | 
| Default callback for AST_VECTOR_CALLBACK() | |
| #define | AST_VECTOR_MAX_SIZE(vec) (vec)->max | 
| Get the maximum number of elements the vector can currently hold. | |
| #define | AST_VECTOR_PTR_FREE(vec) | 
| Deallocates this vector pointer. | |
| #define | AST_VECTOR_REMOVE(vec, idx, preserve_ordered) | 
| Remove an element from a vector by index. | |
| #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. | |
| #define | AST_VECTOR_REMOVE_ALL_CMP_UNORDERED(vec, value, cmp, cleanup) | 
| Remove all elements from a vector that matches the given comparison. | |
| #define | AST_VECTOR_REMOVE_CMP_ORDERED(vec, value, cmp, cleanup) | 
| Remove an element from a vector that matches the given comparison while maintaining order. | |
| #define | AST_VECTOR_REMOVE_CMP_UNORDERED(vec, value, cmp, cleanup) | 
| Remove an element from a vector that matches the given comparison. | |
| #define | AST_VECTOR_REMOVE_ELEM_ORDERED(vec, elem, cleanup) | 
| Remove an element from a vector while maintaining order. | |
| #define | AST_VECTOR_REMOVE_ELEM_UNORDERED(vec, elem, cleanup) | 
| Remove an element from a vector. | |
| #define | AST_VECTOR_REMOVE_ORDERED(vec, idx) AST_VECTOR_REMOVE(vec, idx, 1) | 
| Remove an element from a vector by index while maintaining order. | |
| #define | AST_VECTOR_REMOVE_UNORDERED(vec, idx) AST_VECTOR_REMOVE(vec, idx, 0) | 
| Remove an element from an unordered vector by index. | |
| #define | AST_VECTOR_REPLACE(vec, idx, elem) | 
| Replace an element at a specific position in a vector, growing the vector if needed. | |
| #define | AST_VECTOR_RESET(vec, cleanup) | 
| Reset vector. | |
| #define | AST_VECTOR_RW(name, type) | 
| Define a vector structure with a read/write lock. | |
| #define | AST_VECTOR_RW_FREE(vec) | 
| Deallocates this locked vector. | |
| #define | AST_VECTOR_RW_INIT(vec, size) | 
| Initialize a vector with a read/write lock. | |
| #define | AST_VECTOR_RW_PTR_FREE(vec) | 
| Deallocates this locked vector pointer. | |
| #define | AST_VECTOR_RW_RDLOCK(vec) ast_rwlock_rdlock(&(vec)->lock) | 
| Obtain read lock on vector. | |
| #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. | |
| #define | AST_VECTOR_RW_RDLOCK_TRY(vec) ast_rwlock_tryrdlock(&(vec)->lock) | 
| Try to obtain read lock on vector failing immediately if unable. | |
| #define | AST_VECTOR_RW_UNLOCK(vec) ast_rwlock_unlock(&(vec)->lock) | 
| Unlock vector. | |
| #define | AST_VECTOR_RW_WRLOCK(vec) ast_rwlock_wrlock(&(vec)->lock) | 
| Obtain write lock on vector. | |
| #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. | |
| #define | AST_VECTOR_RW_WRLOCK_TRY(vec) ast_rwlock_trywrlock(&(vec)->lock) | 
| Try to obtain write lock on vector failing immediately if unable. | |
| #define | AST_VECTOR_SIZE(vec) (vec)->current | 
| Get the number of elements in a vector. | |
| #define | AST_VECTOR_SORT(vec, cmp) | 
| Sort a vector in-place. | |
| #define | AST_VECTOR_STEAL_ELEMENTS(vec) | 
| Steal the elements from a vector and reinitialize. | |
| Enumerations | |
| enum | ast_vector_string_split_flags { AST_VECTOR_STRING_SPLIT_NO_TRIM = 0x01 , AST_VECTOR_STRING_SPLIT_ALLOW_EMPTY = 0x02 } | 
| Functions | |
| char * | ast_vector_string_join (struct ast_vector_string *vec, const char *delim) | 
| Join the elements of a string vector into a single string. | |
| 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. | |
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 __make_room | ( | idx, | |
| vec | |||
| ) | 
Definition at line 234 of 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. | 
Definition at line 382 of file vector.h.
| #define AST_VECTOR_APPEND | ( | vec, | |
| elem | |||
| ) | 
Append an element to a vector, growing the vector if needed.
| vec | Vector to append to. | 
| elem | Element to append. | 
| 0 | on success. | 
| Non-zero | on failure. | 
Definition at line 267 of file vector.h.
| #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 | 
Definition at line 776 of file vector.h.
| #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.
Definition at line 840 of file vector.h.
| #define AST_VECTOR_CALLBACK_VOID | ( | vec, | |
| callback, | |||
| ... | |||
| ) | 
Execute a callback on every element in a vector disregarding callback return.
| vec | Vector to operate on. | 
| callback | A callback that takes at least 1 argument (the element) plus number of optional arguments | 
| #define AST_VECTOR_COMPACT | ( | vec | ) | 
Resize a vector so that its capacity is the same as its size.
| vec | Vector to compact. | 
| 0 | on success. | 
| Non-zero | on failure. | 
Definition at line 649 of file vector.h.
| #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 | 
Definition at line 320 of file vector.h.
| #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 | ) | 
Deallocates this vector.
If any code to free the elements of this vector needs to be run, that should be done prior to this call.
| vec | Vector to deallocate. | 
| #define AST_VECTOR_GET | ( | vec, | |
| idx | |||
| ) | 
Get an element from a vector.
| vec | Vector to query. | 
| idx | Index of the element to get. | 
| #define AST_VECTOR_GET_ADDR | ( | vec, | |
| idx | |||
| ) | 
Get an address of element in a vector.
| vec | Vector to query. | 
| idx | Index of the element to get address of. | 
| #define AST_VECTOR_GET_CMP | ( | vec, | |
| value, | |||
| cmp | |||
| ) | 
Get an element from a vector that matches the given comparison.
| vec | Vector to get from. | 
| value | Value to pass into comparator. | 
| cmp | Comparator function/macros (called as cmp(elem, value)) | 
| #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 | |||
| ) | 
Initialize a vector.
If size is 0, then no space will be allocated until the vector is appended to.
| vec | Vector to initialize. | 
| size | Initial size of the vector. | 
| 0 | on success. | 
| Non-zero | on failure. | 
| #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. | 
Definition at line 349 of file vector.h.
| #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 | ) | 
Deallocates this 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. | 
Definition at line 200 of file vector.h.
| #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. | 
Definition at line 609 of file vector.h.
| #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. | 
Definition at line 594 of file vector.h.
| #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. | 
Definition at line 295 of file vector.h.
| #define AST_VECTOR_RESET | ( | vec, | |
| cleanup | |||
| ) | 
Reset vector.
| vec | Vector to reset. | 
| cleanup | A cleanup callback or AST_VECTOR_ELEM_CLEANUP_NOOP. | 
| #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 | |||
| ) | 
Initialize a vector with a read/write lock.
If size is 0, then no space will be allocated until the vector is appended to.
| vec | Vector to initialize. | 
| size | Initial size of the vector. | 
| 0 | on success. | 
| Non-zero | on failure. | 
Definition at line 169 of file vector.h.
| #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. | 
Definition at line 226 of file vector.h.
| #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 | |||
| ) | 
Sort a vector in-place.
| vec | Vector to sort | 
| cmp | A memcmp compatible compare function | 
| #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.
| char * ast_vector_string_join | ( | struct ast_vector_string * | vec, | 
| const char * | delim | ||
| ) | 
Join the elements of a string vector into a single string.
| vec | Pointer to the vector. | 
| delim | String to separate elements with. | 
| Resulting | string. Must be freed with ast_free. | 
Definition at line 406 of file strings.c.
References ast_free, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_truncate(), ast_strdup, AST_VECTOR_GET, AST_VECTOR_SIZE, buf, and NULL.
Referenced by show_sessions_cb().
| 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 425 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, NULL, and strsep().
Referenced by module_post_register(), and outbound_websocket_validate_cb().