|
libref_array 0.5.0
|
00001 /* 00002 REF ARRAY 00003 00004 Header file for of the dynamic array with reference count. 00005 00006 Copyright (C) Dmitri Pal <dpal@redhat.com> 2009 00007 00008 This program is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #ifndef REF_ARRAY_H 00021 #define REF_ARRAY_H 00022 00023 #include <stdint.h> 00024 #include <stdlib.h> 00025 00026 struct ref_array; 00027 00028 #ifndef EOK 00029 #define EOK 0 00030 #endif 00031 00074 typedef enum 00075 { 00076 REF_ARRAY_DESTROY, 00077 REF_ARRAY_DELETE, 00078 } ref_array_del_enum; 00079 00080 00093 typedef void (*ref_array_fn)(void *elem, 00094 ref_array_del_enum type, 00095 void *data); 00096 00112 typedef int (*ref_array_copy_cb)(void *elem, 00113 void *new_elem); 00114 00131 int ref_array_create(struct ref_array **ra, 00132 size_t elem, 00133 uint32_t grow_by, 00134 ref_array_fn cb, 00135 void *data); 00136 00145 struct ref_array *ref_array_getref(struct ref_array *ra); 00146 00154 void ref_array_destroy(struct ref_array *ra); 00155 00172 int ref_array_append(struct ref_array *ra, void *element); 00173 00198 void *ref_array_get(struct ref_array *ra, uint32_t idx, void *acptr); 00199 00212 int ref_array_getlen(struct ref_array *ra, uint32_t *len); 00213 00223 uint32_t ref_array_len(struct ref_array *ra); 00224 00251 int ref_array_insert(struct ref_array *ra, 00252 uint32_t idx, 00253 void *element); 00276 int ref_array_replace(struct ref_array *ra, 00277 uint32_t idx, 00278 void *element); 00279 00280 00297 int ref_array_remove(struct ref_array *ra, 00298 uint32_t idx); 00299 00300 00317 int ref_array_swap(struct ref_array *ra, 00318 uint32_t idx1, 00319 uint32_t idx2); 00320 00321 00337 void ref_array_reset(struct ref_array *ra); 00338 00339 00359 int ref_array_copy(struct ref_array *ra, 00360 ref_array_copy_cb copy_cb, 00361 ref_array_fn cb, 00362 void *data, 00363 struct ref_array **copy_ra); 00364 00365 00366 00380 void ref_array_debug(struct ref_array *ra, int num); 00381 00387 #endif
1.7.3