mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
d488c37cc1
commit
801e584029
1 changed files with 13 additions and 5 deletions
18
divesite.h
18
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue