From ac294568caf6b7c4572a62809be531a117108e8b Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Sun, 15 Feb 2009 12:09:03 +0000 Subject: Add ability to retrieve vector length. Fix missing note in iteration api svn path=/trunk/libparserutils/; revision=6527 --- src/utils/vector.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/utils/vector.c') diff --git a/src/utils/vector.c b/src/utils/vector.c index 2571ba4..ab895e3 100644 --- a/src/utils/vector.c +++ b/src/utils/vector.c @@ -164,12 +164,35 @@ parserutils_error parserutils_vector_remove_last(parserutils_vector *vector) return PARSERUTILS_OK; } +/** + * Acquire the length (in items) of the vector. + * + * \param vector The vector to interrogate. + * \param length Pointer to location to receive length information. + * \return PARSERUTILS_OK on success, appropriate error otherwise + */ +parserutils_error parserutils_vector_get_length(parserutils_vector *vector, + size_t *length) +{ + if (vector == NULL) + return PARSERUTILS_BADPARM; + + if (length == NULL) + return PARSERUTILS_BADPARM; + + *length = vector->current_item + 1; + + return PARSERUTILS_OK; +} + /** * Iterate over a vector * * \param vector The vector to iterate over * \param ctx Pointer to an integer for the iterator to use as context. * \return Pointer to current item, or NULL if no more + * + * \note The value pointed to by \a ctx must be zero to begin the iteration. */ const void *parserutils_vector_iterate(const parserutils_vector *vector, int32_t *ctx) -- cgit v1.2.3