libref_array  0.1.2
ref_array.h
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 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 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 
00087 typedef void (*ref_array_fn)(void *elem,
00088                              ref_array_del_enum type,
00089                              void *data);
00090 
00091 
00108 int ref_array_create(struct ref_array **ra,
00109                      size_t elem,
00110                      uint32_t grow_by,
00111                      ref_array_fn cb,
00112                      void *data);
00113 
00122 struct ref_array *ref_array_getref(struct ref_array *ra);
00123 
00131 void ref_array_destroy(struct ref_array *ra);
00132 
00149 int ref_array_append(struct ref_array *ra, void *element);
00150 
00175 void *ref_array_get(struct ref_array *ra, uint32_t idx, void *acptr);
00176 
00189 int ref_array_getlen(struct ref_array *ra, uint32_t *len);
00190 
00200 uint32_t ref_array_len(struct ref_array *ra);
00201 
00228 int ref_array_insert(struct ref_array *ra,
00229                      uint32_t idx,
00230                      void *element);
00253 int ref_array_replace(struct ref_array *ra,
00254                       uint32_t idx,
00255                       void *element);
00256 
00257 
00274 int ref_array_remove(struct ref_array *ra,
00275                      uint32_t idx);
00276 
00277 
00294 int ref_array_swap(struct ref_array *ra,
00295                    uint32_t idx1,
00296                    uint32_t idx2);
00297 
00298 
00314 void ref_array_reset(struct ref_array *ra);
00315 
00321 #endif