[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r13302: New macros to simplify writing loops over map key-value pair (tor/trunk/src/common)
Author: nickm
Date: 2008-01-26 17:49:36 -0500 (Sat, 26 Jan 2008)
New Revision: 13302
Modified:
tor/trunk/src/common/container.h
Log:
New macros to simplify writing loops over map key-value pairs.
Modified: tor/trunk/src/common/container.h
===================================================================
--- tor/trunk/src/common/container.h 2008-01-26 22:03:13 UTC (rev 13301)
+++ tor/trunk/src/common/container.h 2008-01-26 22:49:36 UTC (rev 13302)
@@ -208,6 +208,24 @@
#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);