summaryrefslogtreecommitdiff
path: root/src/common/container.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-06-11 22:19:37 +0000
committerNick Mathewson <nickm@torproject.org>2007-06-11 22:19:37 +0000
commitf45732513ea352a5588d503d0664a33002344173 (patch)
tree355eba860b275ae3a3cb194fe50c79783abb2e34 /src/common/container.h
parentbde82e737b7e049e7de2e3edd21e4ce88932f3d9 (diff)
downloadtor-f45732513ea352a5588d503d0664a33002344173.tar.gz
tor-f45732513ea352a5588d503d0664a33002344173.zip
r13354@catbus: nickm | 2007-06-11 18:17:40 -0400
Add typechecking wrappers to digestmap, so we can work with "map from digest to [FOO]" for arbitrary FOOs and still have some typesafety. svn:r10562
Diffstat (limited to 'src/common/container.h')
-rw-r--r--src/common/container.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/common/container.h b/src/common/container.h
index 782c4a491f..d0d893a989 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -198,10 +198,72 @@ char *smartlist_join_strings2(smartlist_t *sl, const char *join,
/* Map from const char * to void *. Implemented with a hash table. */
DECLARE_MAP_FNS(strmap_t, const char *, strmap_);
DECLARE_MAP_FNS(digestmap_t, const char *, digestmap_);
+#undef DECLARE_MAP_FNS
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);
+#define DECLARE_TYPED_DIGESTMAP_FNS(prefix, maptype, valtype) \
+ typedef struct maptype maptype; \
+ typedef struct prefix##iter_t prefix##iter_t; \
+ static INLINE maptype* prefix##new(void) \
+ { \
+ return (maptype*)digestmap_new(); \
+ } \
+ static INLINE valtype* prefix##get(maptype *map, const char *key) \
+ { \
+ return (valtype*)digestmap_get((digestmap_t*)map, key); \
+ } \
+ static INLINE valtype* prefix##set(maptype *map, const char *key, \
+ valtype *val) \
+ { \
+ return (valtype*)digestmap_set((digestmap_t*)map, key, val); \
+ } \
+ static INLINE valtype* prefix##remove(maptype *map, const char *key) \
+ { \
+ return (valtype*)digestmap_get((digestmap_t*)map, key); \
+ } \
+ static INLINE void prefix##free(maptype *map, void (*free_val)(void*)) \
+ { \
+ digestmap_free((digestmap_t*)map, free_val); \
+ } \
+ static INLINE int prefix##isempty(maptype *map) \
+ { \
+ return digestmap_isempty((digestmap_t*)map); \
+ } \
+ static INLINE int prefix##size(maptype *map) \
+ { \
+ return digestmap_isempty((digestmap_t*)map); \
+ } \
+ static INLINE prefix##iter_t *prefix##iter_init(maptype *map) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_init((digestmap_t*)map); \
+ } \
+ static INLINE prefix##iter_t *prefix##iter_next(maptype *map, \
+ prefix##iter_t *iter) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_next( \
+ (digestmap_t*)map, (digestmap_iter_t*)iter); \
+ } \
+ static INLINE prefix##iter_t *prefix##iter_next_rmv(maptype *map, \
+ prefix##iter_t *iter) \
+ { \
+ return (prefix##iter_t*) digestmap_iter_next_rmv( \
+ (digestmap_t*)map, (digestmap_iter_t*)iter); \
+ } \
+ static INLINE void prefix##iter_get(prefix##iter_t *iter, \
+ const char **keyp, \
+ valtype **valp) \
+ { \
+ void *v; \
+ digestmap_iter_get((digestmap_iter_t*) iter, keyp, &v); \
+ *valp = v; \
+ } \
+ static INLINE int prefix##iter_done(prefix##iter_t *iter) \
+ { \
+ return digestmap_iter_done((digestmap_iter_t*)iter); \
+ }
+
#endif