summaryrefslogtreecommitdiff
path: root/src/common/container.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-01-26 22:49:36 +0000
committerNick Mathewson <nickm@torproject.org>2008-01-26 22:49:36 +0000
commitc7fe633780bffe69d07a1655c6ecbe3c631d5483 (patch)
treede2ec0d8b4d0cbf7a7cf4204644cbc2697095fe5 /src/common/container.h
parentad07366da59386cda14af478e83fd2cf5cb22cc4 (diff)
downloadtor-c7fe633780bffe69d07a1655c6ecbe3c631d5483.tar.gz
tor-c7fe633780bffe69d07a1655c6ecbe3c631d5483.zip
New macros to simplify writing loops over map key-value pairs.
svn:r13302
Diffstat (limited to 'src/common/container.h')
-rw-r--r--src/common/container.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/common/container.h b/src/common/container.h
index f8660c74d9..3b5d72b1c2 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -208,6 +208,24 @@ DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
#undef DECLARE_MAP_FNS
+#define MAP_FOREACH(prefix, map, keytype, keyvar, valtype, valvar) \
+ STMT_BEGIN \
+ prefix##iter_t *key##_iter; \
+ for (key##_iter = prefix##iter_init(map); \
+ !prefix##iter_done(key##_iter); \
+ key##_iter = prefix##iter_next(map, key##_iter)) { \
+ keytype keyvar; \
+ void *valvar##_voidp; \
+ valtype valvar; \
+ prefix##iter_get(key##_iter, &keyvar, &valvar##_voidp); \
+ valvar = valvar##_voidp;
+
+#define MAP_FOREACH_END } STMT_END ;
+
+#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar) \
+ MAP_FOREACH(digestmap_, map, const char *, keyvar, valtype, valvar)
+#define DIGESTMAP_FOREACH_END MAP_FOREACH_END
+
void* strmap_set_lc(strmap_t *map, const char *key, void *val);
void* strmap_get_lc(const strmap_t *map, const char *key);
void* strmap_remove_lc(strmap_t *map, const char *key);