]>
code.delx.au - pulseaudio/blob - polyp/dynarray.c
23adb5819c6bd10d8f90ec8d97cb90bf2dd91d22
4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
35 unsigned n_allocated
, n_entries
;
38 struct pa_dynarray
* pa_dynarray_new(void) {
39 struct pa_dynarray
*a
;
40 a
= pa_xmalloc(sizeof(struct pa_dynarray
));
47 void pa_dynarray_free(struct pa_dynarray
* a
, void (*func
)(void *p
, void *userdata
), void *userdata
) {
52 for (i
= 0; i
< a
->n_entries
; i
++)
54 func(a
->data
[i
], userdata
);
60 void pa_dynarray_put(struct pa_dynarray
*a
, unsigned i
, void *p
) {
63 if (i
>= a
->n_allocated
) {
70 a
->data
= pa_xrealloc(a
->data
, sizeof(void*)*n
);
71 memset(a
->data
+a
->n_allocated
, 0, sizeof(void*)*(n
-a
->n_allocated
));
77 if (i
>= a
->n_entries
)
81 unsigned pa_dynarray_append(struct pa_dynarray
*a
, void *p
) {
82 unsigned i
= a
->n_entries
;
83 pa_dynarray_put(a
, i
, p
);
87 void *pa_dynarray_get(struct pa_dynarray
*a
, unsigned i
) {
89 if (i
>= a
->n_allocated
)
95 unsigned pa_dynarray_ncontents(struct pa_dynarray
*a
) {