summaryrefslogtreecommitdiffstats
path: root/core/divesite.c
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-03-04 23:20:29 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitc22fd9f4fd6699333629b8acb1e9c135a9783082 (patch)
tree7fad8249eb4fb3fa2797329716b1038d115a62d9 /core/divesite.c
parentf2cdca7bccfcdfa04639600689b2b13b38b56898 (diff)
downloadsubsurface-c22fd9f4fd6699333629b8acb1e9c135a9783082.tar.gz
Dive sites: prepare for dive site ref-counting
Add a dive site table to each dive site to keep track of dives that have been added to a dive site. Add two functions to add dives to / remove dives from dive sites. Since dive sites now contain a dive table, the order of includes had to be changed: "divesite.h" now includes "dive.h" and not vice-versa. This caused some include churn. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/divesite.c')
-rw-r--r--core/divesite.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/divesite.c b/core/divesite.c
index a71780faf..d53b72b4b 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -382,6 +382,29 @@ void purge_empty_dive_sites(struct dive_site_table *ds_table)
}
}
+void add_dive_to_dive_site(struct dive *d, struct dive_site *ds)
+{
+ int idx;
+ if (d->dive_site == ds)
+ return;
+ if (d->dive_site)
+ fprintf(stderr, "Warning: adding dive that already belongs to a dive site to a different site\n");
+ idx = dive_table_get_insertion_index(&ds->dives, d);
+ add_to_dive_table(&ds->dives, idx, d);
+ d->dive_site = ds;
+}
+
+struct dive_site *unregister_dive_from_dive_site(struct dive *d)
+{
+ struct dive_site *ds = d->dive_site;
+ if (!ds)
+ return NULL;
+ remove_dive(&ds->dives, d);
+ d->dive_site = NULL;
+ return ds;
+}
+
+/* Assign arbitrary UUIDs to dive sites. This is called by before writing the dive log to XML or git. */
static int compare_sites(const void *_a, const void *_b)
{
const struct dive_site *a = (const struct dive_site *)*(void **)_a;