apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Striker <stri...@apache.org>
Subject [PATCH] Convenience macros for apr array manipulation
Date Fri, 12 Dec 2003 18:07:20 GMT
Hi,

We've been using macros similar to these in Subversion for
a while (courtesy of Mike Pilato).  It saves users from
(mis)typing the regular syntax.

Comments?

Sander

> Index: apr_tables.h
> ===================================================================
> RCS file: /home/cvs/apr/include/apr_tables.h,v
> retrieving revision 1.38
> diff -u -r1.38 apr_tables.h
> --- apr_tables.h        22 Jun 2003 21:50:25 -0000      1.38
> +++ apr_tables.h        12 Dec 2003 17:53:30 -0000
> @@ -224,6 +224,23 @@
>                                       const char sep);
>   
>  /**
> + * Push a new item of a certain type into an array.
> + * @param arr  The array to add the item to
> + * @param type Type of the item
> + * @param item The item to add
> + */
> +#define APR_ARRAY_PUSH(arr, type, item) \
> +  (*((type *)apr_array_push(arr))) = (item)
> +
> +/**
> + * Get an item at a specified index in an array
> + * @param arr  The array to get the item from
> + * @param idx  The index into the array
> + * @param type The type of the item
> + */
> +#define APR_ARRAY_IDX(arr, idx, type) (((type *)(arr)->elts)[idx])
> +
> +/**
>   * Make a new table
>   * @param p The pool to allocate the pool out of
>   * @param nelts The number of elements in the initial table.


Mime
View raw message