summaryrefslogtreecommitdiffstats
path: root/dive.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 13:34:27 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-07-03 13:34:27 -0700
commit47f9f59c1a8c9a6a10b6169562066a58da7aee76 (patch)
tree80fd805a242acf265609ec17ded2a9487ec3295c /dive.c
parent6b1b2bc919e311cc7e83f336017f35216c8da538 (diff)
downloadsubsurface-47f9f59c1a8c9a6a10b6169562066a58da7aee76.tar.gz
UI restructure: add clone_dive helper
This is kind of the inverse to copy_dive(). Instead of duplicating all the data that the dive points to, it moves it to a new struct dive and zeroes out the old one so there are no two sets of pointers to these data. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'dive.c')
-rw-r--r--dive.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index 5bebba3b2..6bbb72e1e 100644
--- a/dive.c
+++ b/dive.c
@@ -326,6 +326,9 @@ void clear_dive(struct dive *d)
memset(d, 0, sizeof(struct dive));
}
+/* make a true copy that is independent of the source dive;
+ * all data structures are duplicated, so the copy can be modified without
+ * any impact on the source */
void copy_dive(struct dive *s, struct dive *d)
{
clear_dive(d);
@@ -343,6 +346,18 @@ void copy_dive(struct dive *s, struct dive *d)
STRUCTURED_LIST_COPY(struct tag_entry, s->tag_list, d->tag_list, copy_tl);
}
+/* make a clone of the source dive and clean out the source dive;
+ * this is specifically so we can create a dive in the displayed_dive and then
+ * add it to the divelist.
+ * Note the difference to copy_dive() / clean_dive() */
+struct dive *clone_dive(struct dive *s)
+{
+ struct dive *dive = alloc_dive();
+ *dive = *s; // so all the pointers in dive point to the things s pointed to
+ memset(s, 0, sizeof(struct dive)); // and now the pointers in s are gone
+ return dive;
+}
+
/* only copies events from the first dive computer */
void copy_events(struct divecomputer *s, struct divecomputer *d)
{