summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2017-11-07 15:00:33 -0500
committerCorey Farrell <git@cfware.com>2017-11-13 13:38:26 -0500
commit2ad6210dd7b9071de3a2d3fb6ebdcb243ec470da (patch)
treebfa92e797ae57bbc6c936b314d7dfda08b3a6600 /include
parentb1743cb3c75a943a8a9cb55a3e4355f0133156fe (diff)
vectors: Add new macro and a string vector definition.
* AST_VECTOR_STEAL_ELEMENTS - steal the array of elements for use with non-vector code. * struct ast_vector_string - a vector of 'char *'. Change-Id: I104d1b204be03fccf67e02a195596adcb5ab1e42
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/vector.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/asterisk/vector.h b/include/asterisk/vector.h
index 8270e25a9..2ee5e29a6 100644
--- a/include/asterisk/vector.h
+++ b/include/asterisk/vector.h
@@ -51,6 +51,9 @@
/*! \brief Integer vector definition */
AST_VECTOR(ast_vector_int, int);
+/*! \brief String vector definition */
+AST_VECTOR(ast_vector_string, char *);
+
/*!
* \brief Define a vector structure with a read/write lock
*
@@ -91,6 +94,26 @@ AST_VECTOR(ast_vector_int, int);
})
/*!
+ * \brief Steal the elements from a vector and reinitialize.
+ *
+ * \param vec Vector to operate on.
+ *
+ * This allows you to use vector.h to construct a list and use the
+ * data as a bare array.
+ *
+ * \note The stolen array must eventually be released using ast_free.
+ *
+ * \warning AST_VECTOR_SIZE and AST_VECTOR_MAX_SIZE are both reset
+ * to 0. If either are needed they must be saved to a local
+ * variable before stealing the elements.
+ */
+#define AST_VECTOR_STEAL_ELEMENTS(vec) ({ \
+ typeof((vec)->elems) __elems = (vec)->elems; \
+ AST_VECTOR_INIT((vec), 0); \
+ (__elems); \
+})
+
+/*!
* \brief Initialize a vector with a read/write lock
*
* If \a size is 0, then no space will be allocated until the vector is