summaryrefslogtreecommitdiffstats
path: root/divesite.h
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-12 01:26:57 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-12 11:19:27 -0800
commit801e584029688eca38d35542e8ab3d644833231b (patch)
tree330486d042dcd7584408a8d14ece593c51c512a1 /divesite.h
parentd488c37cc11a6051f94715465264a38bf7cf4dc2 (diff)
downloadsubsurface-801e584029688eca38d35542e8ab3d644833231b.tar.gz
Another helper: for_each_dive_site()
This doesn't make the code necessarily more compact, but easier to read and is consistent with our other patterns. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divesite.h')
-rw-r--r--divesite.h18
1 files changed, 13 insertions, 5 deletions
diff --git a/divesite.h b/divesite.h
index da0a78983..2a4d8c616 100644
--- a/divesite.h
+++ b/divesite.h
@@ -27,10 +27,16 @@ static inline struct dive_site *get_dive_site(int nr)
return dive_site_table.dive_sites[nr];
}
+/* iterate over each dive site */
+#define for_each_dive_site(_i, _x) \
+ for ((_i) = 0; ((_x) = get_dive_site(_i)) != NULL; (_i)++)
+
static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
{
- for (int i = 0; i < dive_site_table.nr; i++)
- if (get_dive_site(i)->uuid == uuid)
+ int i;
+ struct dive_site *ds;
+ for_each_dive_site (i, ds)
+ if (ds->uuid == uuid)
return get_dive_site(i);
return NULL;
}
@@ -38,9 +44,11 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
/* there could be multiple sites of the same name - return the first one */
static inline uint32_t get_dive_site_uuid_by_name(const char *name)
{
- for (int i = 0; i < dive_site_table.nr; i++)
- if (get_dive_site(i)->name == name)
- return get_dive_site(i)->uuid;
+ int i;
+ struct dive_site *ds;
+ for_each_dive_site (i, ds)
+ if (ds->name == name)
+ return ds->uuid;
return 0;
}