Add the A() macro to get the array type.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 12 Sep 2008 20:37:14 +0000 (22:37 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 12 Sep 2008 20:37:14 +0000 (22:37 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/array.h
common/buffer.h
common/trie.c

index b85fc50..04a632b 100644 (file)
@@ -60,6 +60,7 @@
             p_delete(array);                                                   \
         }                                                                      \
     }
+#define A(Type) Type ## _array_t
 
 #define ARRAY_INIT { NULL, 0, 0 }
 
 #define array_elt(array, n) (array).data[(n)]
 #define array_ptr(array, n) (array).data + (n)
 
+#define array_foreach(array, action)                                           \
+    for (int __Ai = 0 ; __Ai < (array).len ; ++__Ai) {                         \
+        action(array_ptr(array, __Ai));                                        \
+    }
+#define array_deep_wipe(array, wipe)                                           \
+    do {                                                                       \
+        array_foreach(array, wipe);                                            \
+        array_wipe(array);                                                     \
+    } while (0)
+
 ARRAY(char)
 ARRAY(int)
 
index d044114..a1a96ec 100644 (file)
@@ -41,7 +41,7 @@
 #include "str.h"
 #include "array.h"
 
-typedef char_array_t buffer_t;
+typedef A(char) buffer_t;
 
 #define BUFFER_INIT {NULL, 0, 0}
 
index 9ffa9b5..5bf18ec 100644 (file)
@@ -52,10 +52,10 @@ struct trie_entry_t {
 ARRAY(trie_entry_t)
 
 struct trie_t {
-    trie_entry_t_array_t entries;
-    char_array_t         c;
-    char_array_t         keys;
-    int_array_t          keys_offset;
+    A(trie_entry_t) entries;
+    A(char)         c;
+    A(char)         keys;
+    A(int)          keys_offset;
 
     bool locked;
 };