libref_array  0.3.0.1
 All Functions Typedefs Enumerations Groups Pages
ref_array.h
1 /*
2  REF ARRAY
3 
4  Header file for of the dynamic array with reference count.
5 
6  Copyright (C) Dmitri Pal <dpal@redhat.com> 2009
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16  You should have received a copy of the GNU Lesser General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef REF_ARRAY_H
21 #define REF_ARRAY_H
22 
23 #include <stdint.h>
24 #include <stdlib.h>
25 
26 struct ref_array;
27 
28 #ifndef EOK
29 #define EOK 0
30 #endif
31 
74 typedef enum
75 {
76  REF_ARRAY_DESTROY,
77  REF_ARRAY_DELETE,
79 
80 
93 typedef void (*ref_array_fn)(void *elem,
94  ref_array_del_enum type,
95  void *data);
96 
112 typedef int (*ref_array_copy_cb)(void *elem,
113  void *new_elem);
114 
131 int ref_array_create(struct ref_array **ra,
132  size_t elem,
133  uint32_t grow_by,
134  ref_array_fn cb,
135  void *data);
136 
145 struct ref_array *ref_array_getref(struct ref_array *ra);
146 
154 void ref_array_destroy(struct ref_array *ra);
155 
172 int ref_array_append(struct ref_array *ra, void *element);
173 
198 void *ref_array_get(struct ref_array *ra, uint32_t idx, void *acptr);
199 
212 int ref_array_getlen(struct ref_array *ra, uint32_t *len);
213 
223 uint32_t ref_array_len(struct ref_array *ra);
224 
251 int ref_array_insert(struct ref_array *ra,
252  uint32_t idx,
253  void *element);
276 int ref_array_replace(struct ref_array *ra,
277  uint32_t idx,
278  void *element);
279 
280 
297 int ref_array_remove(struct ref_array *ra,
298  uint32_t idx);
299 
300 
317 int ref_array_swap(struct ref_array *ra,
318  uint32_t idx1,
319  uint32_t idx2);
320 
321 
337 void ref_array_reset(struct ref_array *ra);
338 
339 
359 int ref_array_copy(struct ref_array *ra,
360  ref_array_copy_cb copy_cb,
361  ref_array_fn cb,
362  void *data,
363  struct ref_array **copy_ra);
364 
365 
371 #endif