Mercurial > code
comparison array.h @ 69:8f6d3850fac1
Remove useless attributes and add [P]ARRAY_FULL
author | David Demelier <markand@malikania.fr> |
---|---|
date | Fri, 11 Nov 2011 02:21:59 +0100 |
parents | cff6869fbc94 |
children | b3ba5f5df3b9 |
comparison
equal
deleted
inserted
replaced
68:18e8c7911825 | 69:8f6d3850fac1 |
---|---|
21 | 21 |
22 #ifdef __cplusplus | 22 #ifdef __cplusplus |
23 extern "C" { | 23 extern "C" { |
24 #endif | 24 #endif |
25 | 25 |
26 /* Add some nonnull attributes for gcc/clang */ | |
27 #ifdef __GNUC__ | |
28 # define __at_malloc __attribute__ ((malloc)) | |
29 # define __at_nonnull(...) __attribute__ ((nonnull (__VA_ARGS__))) | |
30 #else | |
31 # define __at_malloc | |
32 # define __at_nonnull(...) | |
33 #endif | |
34 | |
35 #define ARRAY_DEFAULT_BSIZE 128 | 26 #define ARRAY_DEFAULT_BSIZE 128 |
36 | 27 |
37 enum array_type { | 28 enum array_type { |
38 ARRAY_FIXED = 0, | 29 ARRAY_FIXED = 0, |
39 ARRAY_AUTO = 1 | 30 ARRAY_AUTO = 1 |
50 }; | 41 }; |
51 | 42 |
52 typedef void (*array_map_fn)(void *, void *); | 43 typedef void (*array_map_fn)(void *, void *); |
53 typedef int (*array_cmp_fn)(void *, void *); | 44 typedef int (*array_cmp_fn)(void *, void *); |
54 | 45 |
55 struct array *array_new(enum array_type, size_t, int) __at_malloc; | 46 struct array *array_new(enum array_type, size_t, int); |
56 int array_push(struct array *, const void *) __at_nonnull(1, 2); | 47 int array_push(struct array *, const void *); |
57 int array_insert(struct array *, const void *, int) __at_nonnull(1, 2); | 48 int array_insert(struct array *, const void *, int); |
58 int array_append(struct array *, const void *) __at_nonnull(1, 2); | 49 int array_append(struct array *, const void *); |
59 void array_pop(struct array *) __at_nonnull(1); | 50 void array_pop(struct array *); |
60 void array_unqueue(struct array *) __at_nonnull(1); | 51 void array_unqueue(struct array *); |
61 void array_remove(struct array *, int) __at_nonnull(1); | 52 void array_remove(struct array *, int); |
62 void array_unref(struct array *, const void *) __at_nonnull(1); | 53 void array_unref(struct array *, const void *); |
63 int array_iswap(struct array *, int, int) __at_nonnull(1); | 54 int array_iswap(struct array *, int, int); |
64 int array_pswap(struct array *, const void *, const void *) __at_nonnull(1); | 55 int array_pswap(struct array *, const void *, const void *); |
65 void array_map(const struct array *, array_map_fn, void *) __at_nonnull(1, 2); | 56 void array_map(const struct array *, array_map_fn, void *); |
66 int array_find(const struct array *, array_cmp_fn, void *, void *) __at_nonnull(1, 2); | 57 int array_find(const struct array *, array_cmp_fn, void *, void *); |
67 void array_clear(struct array *) __at_nonnull(1); | 58 void array_clear(struct array *); |
68 void array_free(struct array *) __at_nonnull(1); | 59 void array_free(struct array *); |
69 | 60 |
70 #define ARRAY_HEAD(a, type) \ | 61 #define ARRAY_HEAD(a, type) \ |
71 (((type *)a->data)[0]) | 62 (((type *)a->data)[0]) |
72 #define ARRAY_TAIL(a, type) \ | 63 #define ARRAY_TAIL(a, type) \ |
73 (((type *)a->data)[(a->length == 0) ? 0 : a->length - 1]) | 64 (((type *)a->data)[(a->length == 0) ? 0 : a->length - 1]) |
82 #define ARRAY_FOREACH(a, var, type) \ | 73 #define ARRAY_FOREACH(a, var, type) \ |
83 for ((a)->i = 0, var = ARRAY_HEAD((a), type); \ | 74 for ((a)->i = 0, var = ARRAY_HEAD((a), type); \ |
84 (a)->i < (a)->length; \ | 75 (a)->i < (a)->length; \ |
85 ++(a)->i, var = ARRAY_INDEX((a), (a)->i, type)) | 76 ++(a)->i, var = ARRAY_INDEX((a), (a)->i, type)) |
86 | 77 |
78 /* Only for ARRAY_FIXED */ | |
79 #define ARRAY_FULL(a) \ | |
80 ((a)->length == (a)->bsize) | |
81 | |
87 #ifdef __cplusplus | 82 #ifdef __cplusplus |
88 } | 83 } |
89 #endif | 84 #endif |
90 | 85 |
91 #endif /* _ARRAY_H_ */ | 86 #endif /* _ARRAY_H_ */ |