2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
20 #ifndef MUTT_LIB_LIB_ARRAY_H
21 #define MUTT_LIB_LIB_ARRAY_H
23 #define DO_ARRAY_TYPE(type, prefix) \
24 typedef struct prefix##_array { \
30 #define DO_ARRAY_FUNCS(type, prefix, dtor) \
32 static inline void prefix##_array_init(prefix##_array *array) { \
36 prefix##_array_wipe(prefix##_array *array) { \
37 while (array->len) { \
38 dtor(&array->arr[--array->len]); \
40 p_delete(&array->arr); \
44 prefix##_array_insert(prefix##_array *array, ssize_t pos, type *item) { \
45 __array_insert((__array *)array, pos, (void*)item); \
48 prefix##_array_append(prefix##_array *array, type *item) { \
49 __array_insert((__array *)array, array->len, (void*)item); \
51 static inline type * \
52 prefix##_array_take(prefix##_array *array, ssize_t pos) { \
53 return (type *)__array_take((__array *)array, pos); \
56 DO_ARRAY_TYPE(void, _);
57 void __array_insert(__array *array, ssize_t pos, void *item);
58 void *__array_take(__array *array, ssize_t pos);
60 DO_ARRAY_TYPE(char *, string);
61 DO_ARRAY_FUNCS(char *, string, p_delete);
63 #endif /* MUTT_LIB_LIB_ARRAY_H */