summaryrefslogtreecommitdiffstats
path: root/core/divesite.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-10-23 12:42:01 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-10-29 00:09:31 +0000
commit68961a169efc37039cd3fda334efb9ad9927444f (patch)
tree19365422501eacee57b4cc71722a8a5d8a54f323 /core/divesite.c
parent4cea7b49016923e3f9bb00b60976d7635907e038 (diff)
downloadsubsurface-68961a169efc37039cd3fda334efb9ad9927444f.tar.gz
Dive site: return pointer to dive_site in get_dive_site_*()
As a first step in removing dive-site uuids, change the interface of the get_dive_site_*() functions to return pointers instead of uuids. This makes code a bit more complicated in places where the uuid is extracted afterwards (needed NULL check). Nevertheless, these places should disappear once pointers instead of uuids are stored in the dive-structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divesite.c')
-rw-r--r--core/divesite.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/core/divesite.c b/core/divesite.c
index ee394d9d1..bef505814 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -11,47 +11,41 @@
struct dive_site_table dive_site_table;
/* there could be multiple sites of the same name - return the first one */
-uint32_t get_dive_site_uuid_by_name(const char *name, struct dive_site **dsp)
+struct dive_site *get_dive_site_by_name(const char *name)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds) {
- if (same_string(ds->name, name)) {
- if (dsp)
- *dsp = ds;
- return ds->uuid;
- }
+ if (same_string(ds->name, name))
+ return ds;
}
- return 0;
+ return NULL;
}
/* there could be multiple sites at the same GPS fix - return the first one */
-uint32_t get_dive_site_uuid_by_gps(const location_t *loc, struct dive_site **dsp)
+struct dive_site *get_dive_site_by_gps(const location_t *loc)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds) {
- if (same_location(loc, &ds->location)) {
- if (dsp)
- *dsp = ds;
- return ds->uuid;
- }
+ if (same_location(loc, &ds->location))
+ return ds;
}
- return 0;
+ return NULL;
}
/* to avoid a bug where we have two dive sites with different name and the same GPS coordinates
* and first get the gps coordinates (reading a V2 file) and happen to get back "the other" name,
* this function allows us to verify if a very specific name/GPS combination already exists */
-uint32_t get_dive_site_uuid_by_gps_and_name(char *name, const location_t *loc)
+struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *loc)
{
int i;
struct dive_site *ds;
for_each_dive_site (i, ds) {
if (same_location(loc, &ds->location) && same_string(ds->name, name))
- return ds->uuid;
+ return ds;
}
- return 0;
+ return NULL;
}
// Calculate the distance in meters between two coordinates.
@@ -70,22 +64,19 @@ unsigned int get_distance(const location_t *loc1, const location_t *loc2)
}
/* find the closest one, no more than distance meters away - if more than one at same distance, pick the first */
-uint32_t get_dive_site_uuid_by_gps_proximity(const location_t *loc, int distance, struct dive_site **dsp)
+struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int distance)
{
int i;
- int uuid = 0;
- struct dive_site *ds;
+ struct dive_site *ds, *res = NULL;
unsigned int cur_distance, min_distance = distance;
for_each_dive_site (i, ds) {
if (dive_site_has_gps_location(ds) &&
(cur_distance = get_distance(&ds->location, loc)) < min_distance) {
min_distance = cur_distance;
- uuid = ds->uuid;
- if (dsp)
- *dsp = ds;
+ res = ds;
}
}
- return uuid;
+ return res;
}
/* try to create a uniqe ID - fingers crossed */