summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-09-11 23:14:14 +0000
committerNick Mathewson <nickm@torproject.org>2005-09-11 23:14:14 +0000
commit24bfac635d6536eb7ad97da71256803a6e99cbe1 (patch)
treedaeb1deb4e4c0984218fb872d4ba748f53ca7621
parent70958407f7efd27463f7ba5fc98a29f920de2c94 (diff)
downloadtor-24bfac635d6536eb7ad97da71256803a6e99cbe1.tar.gz
tor-24bfac635d6536eb7ad97da71256803a6e99cbe1.zip
Document SMARTLIST_FOREACH macro, along with previously-naughty foo_sl_idx variable.
svn:r5000
-rw-r--r--src/common/container.h16
1 files changed, 16 insertions, 0 deletions
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 <b>sl</b>, in order. For each item,
+ * assign it to a new local variable of type <b>type</b> named <b>var</b>, and
+ * execute the statement <b>cmd</b>. Inside the loop, the loop index can
+ * be accessed as <b>var</b>_sl_idx.
+ *
+ * Example use:
+ * <pre>
+ * 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);
+ * </pre>
+ */
#define SMARTLIST_FOREACH(sl, type, var, cmd) \
do { \
int var ## _sl_idx, var ## _sl_len=smartlist_len(sl); \