diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-04 23:20:29 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | c22fd9f4fd6699333629b8acb1e9c135a9783082 (patch) | |
tree | 7fad8249eb4fb3fa2797329716b1038d115a62d9 /core | |
parent | f2cdca7bccfcdfa04639600689b2b13b38b56898 (diff) | |
download | subsurface-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')
-rw-r--r-- | core/datatrak.c | 1 | ||||
-rw-r--r-- | core/dive.c | 1 | ||||
-rw-r--r-- | core/dive.h | 7 | ||||
-rw-r--r-- | core/divelist.c | 6 | ||||
-rw-r--r-- | core/divelist.h | 6 | ||||
-rw-r--r-- | core/divesite.c | 23 | ||||
-rw-r--r-- | core/divesite.h | 7 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 2 | ||||
-rw-r--r-- | core/gpslocation.cpp | 1 | ||||
-rw-r--r-- | core/import-cobalt.c | 2 | ||||
-rw-r--r-- | core/import-divinglog.c | 2 | ||||
-rw-r--r-- | core/libdivecomputer.c | 2 | ||||
-rw-r--r-- | core/liquivision.c | 2 | ||||
-rw-r--r-- | core/load-git.c | 2 | ||||
-rw-r--r-- | core/parse-xml.c | 2 | ||||
-rw-r--r-- | core/parse.c | 2 | ||||
-rw-r--r-- | core/save-git.c | 2 | ||||
-rw-r--r-- | core/save-html.c | 3 | ||||
-rw-r--r-- | core/save-xml.c | 2 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 1 | ||||
-rw-r--r-- | core/uemis-downloader.c | 1 | ||||
-rw-r--r-- | core/uemis.c | 1 | ||||
-rw-r--r-- | core/worldmap-save.c | 1 |
23 files changed, 60 insertions, 19 deletions
diff --git a/core/datatrak.c b/core/datatrak.c index fa5f3cbcd..0f7886158 100644 --- a/core/datatrak.c +++ b/core/datatrak.c @@ -15,6 +15,7 @@ #include "units.h" #include "device.h" #include "file.h" +#include "divesite.h" #include "ssrf.h" static unsigned int two_bytes_to_int(unsigned char x, unsigned char y) diff --git a/core/dive.c b/core/dive.c index bd7181361..b05030c60 100644 --- a/core/dive.c +++ b/core/dive.c @@ -10,6 +10,7 @@ #include "libdivecomputer.h" #include "device.h" #include "divelist.h" +#include "divesite.h" #include "qthelper.h" #include "metadata.h" #include "membuffer.h" diff --git a/core/dive.h b/core/dive.h index fd03bc4ae..7c41f6c73 100644 --- a/core/dive.h +++ b/core/dive.h @@ -12,7 +12,6 @@ #include <zip.h> #include <string.h> #include <sys/stat.h> -#include "divesite.h" #include "units.h" @@ -289,6 +288,8 @@ typedef struct trip_table { } trip_table_t; struct picture; +struct dive_site; +struct dive_site_table; struct dive { int number; bool notrip; /* Don't autogroup this dive to a trip */ @@ -747,12 +748,12 @@ extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de * Note: we have to use the typedef "dive_table_t" instead of "struct dive_table", * because MOC removes the "struct", but dive_table is already the name of a global * variable, leading to compilation errors. Likewise for "struct trip_table" and - * "struct dive_site_table". */ + * "struct dive_site_table" (defined in "divesite.h"). */ +#include <QObject> Q_DECLARE_METATYPE(struct dive *); Q_DECLARE_METATYPE(struct dive_trip *); Q_DECLARE_METATYPE(dive_table_t *); Q_DECLARE_METATYPE(trip_table_t *); -Q_DECLARE_METATYPE(dive_site_table_t *); #endif diff --git a/core/divelist.c b/core/divelist.c index 09f08acd0..67a71ca14 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -12,8 +12,8 @@ #include <zip.h> #include <libxslt/transform.h> -#include "dive.h" #include "subsurface-string.h" +#include "divesite.h" #include "divelist.h" #include "display.h" #include "planner.h" @@ -872,7 +872,7 @@ static MAKE_GET_INSERTION_INDEX(trip_table, struct dive_trip *, trips, trip_less } \ } -static MAKE_ADD_TO(dive_table, struct dive *, dives) +MAKE_ADD_TO(dive_table, struct dive *, dives) static MAKE_ADD_TO(trip_table, struct dive_trip *, trips) #define MAKE_REMOVE_FROM(table_type, array_name) \ @@ -916,7 +916,7 @@ static MAKE_GET_IDX(trip_table, struct dive_trip *, trips) MAKE_SORT(dive_table, struct dive *, dives, comp_dives) MAKE_SORT(trip_table, struct dive_trip *, trips, comp_trips) -static void remove_dive(struct dive_table *table, const struct dive *dive) +void remove_dive(struct dive_table *table, const struct dive *dive) { int idx = get_idx_in_dive_table(table, dive); if (idx >= 0) diff --git a/core/divelist.h b/core/divelist.h index 1880856df..831d5a3c1 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -2,6 +2,8 @@ #ifndef DIVELIST_H #define DIVELIST_H +#include "dive.h" + #ifdef __cplusplus extern "C" { #endif @@ -9,8 +11,6 @@ extern "C" { /* this is used for both git and xml format */ #define DATAFORMAT_VERSION 3 -struct dive; - extern void update_cylinder_related_info(struct dive *); extern void mark_divelist_changed(bool); extern int unsaved_changes(void); @@ -33,10 +33,12 @@ extern char *get_dive_gas_string(const struct dive *dive); extern struct dive **grow_dive_table(struct dive_table *table); extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive); +extern void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive); extern void add_single_dive(int idx, struct dive *dive); extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p); extern int get_divenr(const struct dive *dive); extern struct dive_trip *unregister_dive_from_trip(struct dive *dive); +extern void remove_dive(struct dive_table *table, const struct dive *dive); extern void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg); extern dive_trip_t *alloc_trip(void); extern dive_trip_t *create_trip_from_dive(struct dive *dive); 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; diff --git a/core/divesite.h b/core/divesite.h index 09e86bb8c..2210aced1 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -4,6 +4,7 @@ #include "units.h" #include "taxonomy.h" +#include "dive.h" #include <stdlib.h> #ifdef __cplusplus @@ -18,6 +19,7 @@ struct dive_site { uint32_t uuid; char *name; + struct dive_table dives; location_t location; char *description; char *notes; @@ -54,6 +56,8 @@ struct dive_site *alloc_dive_site(); int nr_of_dives_at_dive_site(struct dive_site *ds, bool select_only); bool is_dive_site_used(struct dive_site *ds, bool select_only); void free_dive_site(struct dive_site *ds); +void unregister_dive_site(struct dive_site *ds); +void register_dive_site(struct dive_site *ds); void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table); struct dive_site *create_dive_site(const char *name, struct dive_site_table *ds_table); struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, struct dive_site_table *ds_table); @@ -71,6 +75,8 @@ struct dive_site *find_or_create_dive_site_with_name(const char *name, struct di void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count); void purge_empty_dive_sites(struct dive_site_table *ds_table); void clear_dive_site_table(struct dive_site_table *ds_table); +void add_dive_to_dive_site(struct dive *d, struct dive_site *ds); +struct dive_site *unregister_dive_from_dive_site(struct dive *d); #ifdef __cplusplus } @@ -78,6 +84,7 @@ QString constructLocationTags(struct taxonomy_data *taxonomy, bool for_maintab); /* Make pointer-to-dive_site a "Qt metatype" so that we can pass it through QVariants */ Q_DECLARE_METATYPE(dive_site *); +Q_DECLARE_METATYPE(dive_site_table_t *); #endif diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h index d14a5402b..a5cf84073 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -6,7 +6,7 @@ #include <QHash> #include <QLoggingCategory> -#include "dive.h" +#include "divesite.h" #include "libdivecomputer.h" #include "connectionlistmodel.h" #if BT_SUPPORT diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 8a2719a8b..188cfd81c 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include "core/gpslocation.h" +#include "core/divesite.h" #include "qt-models/gpslistmodel.h" #include "core/pref.h" #include "core/qthelper.h" diff --git a/core/import-cobalt.c b/core/import-cobalt.c index ce5048244..a51d4b9fa 100644 --- a/core/import-cobalt.c +++ b/core/import-cobalt.c @@ -5,7 +5,7 @@ #endif #include "ssrf.h" -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "parse.h" #include "divelist.h" diff --git a/core/import-divinglog.c b/core/import-divinglog.c index 7716ddf8e..4f2b1e932 100644 --- a/core/import-divinglog.c +++ b/core/import-divinglog.c @@ -5,7 +5,7 @@ #endif #include "ssrf.h" -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "parse.h" #include "divelist.h" diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index 9a2991bc3..5519afe46 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -14,7 +14,7 @@ #include <fcntl.h> #include <time.h> #include "gettext.h" -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "device.h" #include "divelist.h" diff --git a/core/liquivision.c b/core/liquivision.c index bfe970e15..621a921be 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -2,7 +2,7 @@ #include <string.h> #include "ssrf.h" -#include "dive.h" +#include "divesite.h" #include "divelist.h" #include "file.h" #include "strndup.h" diff --git a/core/load-git.c b/core/load-git.c index 5ed6ca07d..84af37196 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -15,7 +15,7 @@ #include "gettext.h" -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "divelist.h" #include "device.h" diff --git a/core/parse-xml.c b/core/parse-xml.c index fb2982986..99aef7904 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -22,7 +22,7 @@ #include "gettext.h" -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "parse.h" #include "divelist.h" diff --git a/core/parse.c b/core/parse.c index 5dceef0f9..87d2b8ea3 100644 --- a/core/parse.c +++ b/core/parse.c @@ -7,7 +7,7 @@ #include <unistd.h> #include <libdivecomputer/parser.h> -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "parse.h" #include "divelist.h" diff --git a/core/save-git.c b/core/save-git.c index ce4f52f5e..13d0b4870 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -17,7 +17,7 @@ #include <fcntl.h> #include <git2.h> -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "divelist.h" #include "device.h" diff --git a/core/save-html.c b/core/save-html.c index aeb74bf95..f9d7049a9 100644 --- a/core/save-html.c +++ b/core/save-html.c @@ -7,7 +7,8 @@ #include "save-html.h" #include "qthelper.h" #include "gettext.h" -#include "stdio.h" +#include "divesite.h" +#include <stdio.h> void write_attribute(struct membuffer *b, const char *att_name, const char *value, const char *separator) { diff --git a/core/save-xml.c b/core/save-xml.c index 7df5d3de0..93dfc7f85 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -13,7 +13,7 @@ #include <unistd.h> #include <fcntl.h> -#include "dive.h" +#include "divesite.h" #include "subsurface-string.h" #include "divelist.h" #include "device.h" diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index e126298ac..da664a1ce 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -5,6 +5,7 @@ #include <QTextDocument> #include "core/qthelper.h" +#include "core/divesite.h" #include "core/subsurface-string.h" #include "qt-models/tankinfomodel.h" diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index 56617a0ae..76e6dcf09 100644 --- a/core/uemis-downloader.c +++ b/core/uemis-downloader.c @@ -25,6 +25,7 @@ #include "libdivecomputer.h" #include "uemis.h" #include "divelist.h" +#include "divesite.h" #include "core/subsurface-string.h" #define ERR_FS_ALMOST_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is almost full.\nDisconnect/reconnect the dive computer\nand click \'Retry\'") diff --git a/core/uemis.c b/core/uemis.c index a5b07a8e8..88f402400 100644 --- a/core/uemis.c +++ b/core/uemis.c @@ -13,6 +13,7 @@ #include "gettext.h" #include "uemis.h" +#include "divesite.h" #include <libdivecomputer/parser.h> #include <libdivecomputer/version.h> diff --git a/core/worldmap-save.c b/core/worldmap-save.c index c12d27de2..27e31f482 100644 --- a/core/worldmap-save.c +++ b/core/worldmap-save.c @@ -10,6 +10,7 @@ #include <stdio.h> #include "membuffer.h" +#include "divesite.h" #include "save-html.h" #include "worldmap-save.h" #include "worldmap-options.h" |