From 24bfac635d6536eb7ad97da71256803a6e99cbe1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sun, 11 Sep 2005 23:14:14 +0000 Subject: Document SMARTLIST_FOREACH macro, along with previously-naughty foo_sl_idx variable. svn:r5000 --- src/common/container.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/common/container.h') diff --git a/src/common/container.h b/src/common/container.h index 98b8ab1a8e..5df4e9e897 100644 --- a/src/common/container.h +++ b/src/common/container.h @@ -64,6 +64,22 @@ char *smartlist_join_strings(smartlist_t *sl, const char *join, int terminate, char *smartlist_join_strings2(smartlist_t *sl, const char *join, size_t join_len, int terminate, size_t *len_out); +/** Iterate over the items in a smartlist sl, in order. For each item, + * assign it to a new local variable of type type named var, and + * execute the statement cmd. Inside the loop, the loop index can + * be accessed as var_sl_idx. + * + * Example use: + *
+ *   smartlist_t *list = smartlist_split("A:B:C", ":", 0, 0);
+ *   SMARTLIST_FOREACH(list, char *, cp,
+ *   {
+ *     printf("%d: %s\n", cp_sl_idx, cp);
+ *     tor_free(cp);
+ *   });
+ *   smarlitst_free(list);
+ * 
+ */ #define SMARTLIST_FOREACH(sl, type, var, cmd) \ do { \ int var ## _sl_idx, var ## _sl_len=smartlist_len(sl); \ -- cgit v1.2.3-54-g00ecf