aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-02-26 22:26:11 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-04-12 18:19:07 +0300
commitf6e7bdc5ef99d5a5fe71ac4f32511900fa82e804 (patch)
tree398efefad3b84b33eb5e488bdfa5b2482f345cdd
parent36644dc9f7540886801bda6131dff36241d9e879 (diff)
downloadsubsurface-f6e7bdc5ef99d5a5fe71ac4f32511900fa82e804.tar.gz
Dive site: add dive site table parameter to dive site functions
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/datatrak.c4
-rw-r--r--core/dive.c6
-rw-r--r--core/divelist.c2
-rw-r--r--core/divesite.c88
-rw-r--r--core/divesite.h36
-rw-r--r--core/gpslocation.cpp2
-rw-r--r--core/import-cobalt.c2
-rw-r--r--core/import-divinglog.c2
-rw-r--r--core/libdivecomputer.c2
-rw-r--r--core/liquivision.c2
-rw-r--r--core/load-git.c12
-rw-r--r--core/parse-xml.c16
-rw-r--r--core/parse.c10
-rw-r--r--core/save-git.c4
-rw-r--r--core/save-xml.c6
-rw-r--r--core/uemis-downloader.c8
-rw-r--r--desktop-widgets/locationinformation.cpp6
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp4
-rw-r--r--mobile-widgets/qmlmanager.cpp10
-rw-r--r--qt-models/divelocationmodel.cpp6
-rw-r--r--smtk-import/smartrak.c6
-rw-r--r--tests/testparse.cpp2
22 files changed, 118 insertions, 118 deletions
diff --git a/core/datatrak.c b/core/datatrak.c
index 974f44441..4c2a910bc 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -193,10 +193,10 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
* Locality and Dive points.
*/
snprintf(buffer, sizeof(buffer), "%s, %s", locality, dive_point);
- ds = get_dive_site_by_name(buffer);
+ ds = get_dive_site_by_name(buffer, &dive_site_table);
dt_dive->dive_site = ds;
if (!dt_dive->dive_site)
- dt_dive->dive_site = create_dive_site(buffer, dt_dive->when);
+ dt_dive->dive_site = create_dive_site(buffer, dt_dive->when, &dive_site_table);
free(locality);
locality = NULL;
free(dive_point);
diff --git a/core/dive.c b/core/dive.c
index 7e3b30be9..832f83759 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -4026,14 +4026,14 @@ bool picture_check_valid_time(timestamp_t timestamp, int shift_time)
return false;
}
-static void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
+static void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture, struct dive_site_table *table)
{
struct dive_site *ds = dive->dive_site;
if (!dive_site_has_gps_location(ds) && has_location(&picture->location)) {
if (ds) {
ds->location = picture->location;
} else {
- dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when);
+ dive->dive_site = create_dive_site_with_gps("", &picture->location, dive->when, table);
invalidate_dive_cache(dive);
}
}
@@ -4062,7 +4062,7 @@ void create_picture(const char *filename, int shift_time, bool match_all)
picture->location = metadata.location;
dive_add_picture(dive, picture);
- dive_set_geodata_from_picture(dive, picture);
+ dive_set_geodata_from_picture(dive, picture, &dive_site_table);
invalidate_dive_cache(dive);
}
diff --git a/core/divelist.c b/core/divelist.c
index 9f9ab8140..0b772f201 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -1823,7 +1823,7 @@ void clear_dive_file_data()
while (dive_table.nr)
delete_single_dive(0);
while (dive_site_table.nr)
- delete_dive_site(get_dive_site(0));
+ delete_dive_site(get_dive_site(0, &dive_site_table), &dive_site_table);
if (trip_table.nr != 0) {
fprintf(stderr, "Warning: trip table not empty in clear_dive_file_data()!\n");
trip_table.nr = 0;
diff --git a/core/divesite.c b/core/divesite.c
index 1ee399168..9baabd872 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -10,35 +10,35 @@
struct dive_site_table dive_site_table;
-int get_divesite_idx(const struct dive_site *ds)
+int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table)
{
int i;
const struct dive_site *d;
// tempting as it may be, don't die when called with dive=NULL
if (ds)
- for_each_dive_site(i, d) {
+ for_each_dive_site(i, d, ds_table) {
if (d->uuid == ds->uuid) // don't compare pointers, we could be passing in a copy of the dive
return i;
}
return -1;
}
-struct dive_site *get_dive_site_by_uuid(uint32_t uuid)
+struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
- for_each_dive_site (i, ds)
+ for_each_dive_site (i, ds, ds_table)
if (ds->uuid == uuid)
- return get_dive_site(i);
+ return get_dive_site(i, ds_table);
return NULL;
}
/* there could be multiple sites of the same name - return the first one */
-struct dive_site *get_dive_site_by_name(const char *name)
+struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
- for_each_dive_site (i, ds) {
+ for_each_dive_site (i, ds, ds_table) {
if (same_string(ds->name, name))
return ds;
}
@@ -46,11 +46,11 @@ struct dive_site *get_dive_site_by_name(const char *name)
}
/* there could be multiple sites at the same GPS fix - return the first one */
-struct dive_site *get_dive_site_by_gps(const location_t *loc)
+struct dive_site *get_dive_site_by_gps(const location_t *loc, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
- for_each_dive_site (i, ds) {
+ for_each_dive_site (i, ds, ds_table) {
if (same_location(loc, &ds->location))
return ds;
}
@@ -60,11 +60,11 @@ struct dive_site *get_dive_site_by_gps(const location_t *loc)
/* 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 */
-struct dive_site *get_dive_site_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, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
- for_each_dive_site (i, ds) {
+ for_each_dive_site (i, ds, ds_table) {
if (same_location(loc, &ds->location) && same_string(ds->name, name))
return ds;
}
@@ -87,12 +87,12 @@ 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 */
-struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int distance)
+struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int distance, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds, *res = NULL;
unsigned int cur_distance, min_distance = distance;
- for_each_dive_site (i, ds) {
+ for_each_dive_site (i, ds, ds_table) {
if (dive_site_has_gps_location(ds) &&
(cur_distance = get_distance(&ds->location, loc)) < min_distance) {
min_distance = cur_distance;
@@ -103,11 +103,11 @@ struct dive_site *get_dive_site_by_gps_proximity(const location_t *loc, int dist
}
/* try to create a uniqe ID - fingers crossed */
-static uint32_t dive_site_getUniqId()
+static uint32_t dive_site_getUniqId(struct dive_site_table *ds_table)
{
uint32_t id = 0;
- while (id == 0 || get_dive_site_by_uuid(id)) {
+ while (id == 0 || get_dive_site_by_uuid(id, ds_table)) {
id = rand() & 0xff;
id |= (rand() & 0xff) << 8;
id |= (rand() & 0xff) << 16;
@@ -118,30 +118,30 @@ static uint32_t dive_site_getUniqId()
}
/* we never allow a second dive site with the same uuid */
-struct dive_site *alloc_or_get_dive_site(uint32_t uuid)
+struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table)
{
struct dive_site *ds;
- if (uuid && (ds = get_dive_site_by_uuid(uuid)) != NULL)
+ if (uuid && (ds = get_dive_site_by_uuid(uuid, ds_table)) != NULL)
return ds;
- int nr = dive_site_table.nr;
- int allocated = dive_site_table.allocated;
- struct dive_site **sites = dive_site_table.dive_sites;
+ int nr = ds_table->nr;
+ int allocated = ds_table->allocated;
+ struct dive_site **sites = ds_table->dive_sites;
if (nr >= allocated) {
allocated = (nr + 32) * 3 / 2;
sites = realloc(sites, allocated * sizeof(struct dive_site *));
if (!sites)
exit(1);
- dive_site_table.dive_sites = sites;
- dive_site_table.allocated = allocated;
+ ds_table->dive_sites = sites;
+ ds_table->allocated = allocated;
}
ds = calloc(1, sizeof(*ds));
if (!ds)
exit(1);
sites[nr] = ds;
- dive_site_table.nr = nr + 1;
+ ds_table->nr = nr + 1;
// we should always be called with a valid uuid except in the special
// case where we want to copy a dive site into the memory we allocated
// here - then we need to pass in 0 and create a temporary uuid here
@@ -149,7 +149,7 @@ struct dive_site *alloc_or_get_dive_site(uint32_t uuid)
if (uuid)
ds->uuid = uuid;
else
- ds->uuid = dive_site_getUniqId();
+ ds->uuid = dive_site_getUniqId(ds_table);
return ds;
}
@@ -195,17 +195,17 @@ void free_dive_site(struct dive_site *ds)
}
}
-void delete_dive_site(struct dive_site *ds)
+void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table)
{
- int nr = dive_site_table.nr;
+ int nr = ds_table->nr;
for (int i = 0; i < nr; i++) {
- if (ds == get_dive_site(i)) {
+ if (ds == get_dive_site(i, ds_table)) {
free_dive_site(ds);
if (nr - 1 > i)
- memmove(&dive_site_table.dive_sites[i],
- &dive_site_table.dive_sites[i+1],
- (nr - 1 - i) * sizeof(dive_site_table.dive_sites[0]));
- dive_site_table.nr = nr - 1;
+ memmove(&ds_table->dive_sites[i],
+ &ds_table->dive_sites[i+1],
+ (nr - 1 - i) * sizeof(ds_table->dive_sites[0]));
+ ds_table->nr = nr - 1;
break;
}
}
@@ -229,19 +229,19 @@ static uint32_t create_divesite_uuid(const char *name, timestamp_t divetime)
}
/* allocate a new site and add it to the table */
-struct dive_site *create_dive_site(const char *name, timestamp_t divetime)
+struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table)
{
uint32_t uuid = create_divesite_uuid(name, divetime);
- struct dive_site *ds = alloc_or_get_dive_site(uuid);
+ struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table);
ds->name = copy_string(name);
return ds;
}
/* same as before, but with GPS data */
-struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime)
+struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime, struct dive_site_table *ds_table)
{
uint32_t uuid = create_divesite_uuid(name, divetime);
- struct dive_site *ds = alloc_or_get_dive_site(uuid);
+ struct dive_site *ds = alloc_or_get_dive_site(uuid, ds_table);
ds->name = copy_string(name);
ds->location = *loc;
@@ -323,32 +323,32 @@ void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int
for(i = 0; i < count; i++) {
if (dive_sites[i] == ref)
continue;
- delete_dive_site(dive_sites[i]);
+ delete_dive_site(dive_sites[i], &dive_site_table);
}
mark_divelist_changed(true);
}
-struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime)
+struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table)
{
int i;
struct dive_site *ds;
- for_each_dive_site(i,ds) {
+ for_each_dive_site(i,ds, ds_table) {
if (same_string(name, ds->name))
break;
}
if (ds)
return ds;
- return create_dive_site(name, divetime);
+ return create_dive_site(name, divetime, ds_table);
}
-void purge_empty_dive_sites()
+void purge_empty_dive_sites(struct dive_site_table *ds_table)
{
int i, j;
struct dive *d;
struct dive_site *ds;
- for (i = 0; i < dive_site_table.nr; i++) {
- ds = get_dive_site(i);
+ for (i = 0; i < ds_table->nr; i++) {
+ ds = get_dive_site(i, ds_table);
if (!dive_site_is_empty(ds))
continue;
for_each_dive(j, d) {
@@ -365,7 +365,7 @@ static int compare_sites(const void *_a, const void *_b)
return a->uuid > b->uuid ? 1 : a->uuid == b->uuid ? 0 : -1;
}
-void dive_site_table_sort()
+void dive_site_table_sort(struct dive_site_table *ds_table)
{
- qsort(dive_site_table.dive_sites, dive_site_table.nr, sizeof(struct dive_site *), compare_sites);
+ qsort(ds_table->dive_sites, ds_table->nr, sizeof(struct dive_site *), compare_sites);
}
diff --git a/core/divesite.h b/core/divesite.h
index b3ae0657c..aca00f9b0 100644
--- a/core/divesite.h
+++ b/core/divesite.h
@@ -31,39 +31,39 @@ struct dive_site_table {
extern struct dive_site_table dive_site_table;
-static inline struct dive_site *get_dive_site(int nr)
+static inline struct dive_site *get_dive_site(int nr, struct dive_site_table *ds_table)
{
- if (nr >= dive_site_table.nr || nr < 0)
+ if (nr >= ds_table->nr || nr < 0)
return NULL;
- return dive_site_table.dive_sites[nr];
+ return ds_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)++)
+#define for_each_dive_site(_i, _x, _ds_table) \
+ for ((_i) = 0; ((_x) = get_dive_site(_i, _ds_table)) != NULL; (_i)++)
-int get_divesite_idx(const struct dive_site *ds);
-struct dive_site *get_dive_site_by_uuid(uint32_t uuid);
-void dive_site_table_sort();
-struct dive_site *alloc_or_get_dive_site(uint32_t uuid);
+int get_divesite_idx(const struct dive_site *ds, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_uuid(uint32_t uuid, struct dive_site_table *ds_table);
+void dive_site_table_sort(struct dive_site_table *ds_table);
+struct dive_site *alloc_or_get_dive_site(uint32_t uuid, struct dive_site_table *ds_table);
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 delete_dive_site(struct dive_site *ds);
-struct dive_site *create_dive_site(const char *name, timestamp_t divetime);
-struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime);
-struct dive_site *get_dive_site_by_name(const char *name);
-struct dive_site *get_dive_site_by_gps(const location_t *);
-struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *);
-struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance);
+void delete_dive_site(struct dive_site *ds, struct dive_site_table *ds_table);
+struct dive_site *create_dive_site(const char *name, timestamp_t divetime, struct dive_site_table *ds_table);
+struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_name(const char *name, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_gps(const location_t *, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *, struct dive_site_table *ds_table);
+struct dive_site *get_dive_site_by_gps_proximity(const location_t *, int distance, struct dive_site_table *ds_table);
bool dive_site_is_empty(struct dive_site *ds);
void copy_dive_site_taxonomy(struct dive_site *orig, struct dive_site *copy);
void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
void merge_dive_site(struct dive_site *a, struct dive_site *b);
unsigned int get_distance(const location_t *loc1, const location_t *loc2);
-struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime);
+struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime, struct dive_site_table *ds_table);
void merge_dive_sites(struct dive_site *ref, struct dive_site *dive_sites[], int count);
-void purge_empty_dive_sites();
+void purge_empty_dive_sites(struct dive_site_table *ds_table);
#ifdef __cplusplus
}
diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp
index e0b176f58..6271f42c4 100644
--- a/core/gpslocation.cpp
+++ b/core/gpslocation.cpp
@@ -211,7 +211,7 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d)
{
struct dive_site *ds = d->dive_site;
if (!ds) {
- ds = create_dive_site(qPrintable(gps.name), gps.when);
+ ds = create_dive_site(qPrintable(gps.name), gps.when, &dive_site_table);
d->dive_site = ds;
}
ds->location = gps.location;
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index ae36707af..9bb78d6fd 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -197,7 +197,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column)
return 1;
}
sprintf(tmp, "%s / %s", location, location_site);
- state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when);
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(tmp, state->cur_dive->when, &dive_site_table);
free(tmp);
}
free(location);
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index ee5dccbd0..59ed75404 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -287,7 +287,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column)
state->cur_dive->when = (time_t)(atol(data[1]));
if (data[2])
- state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when);
+ state->cur_dive->dive_site = find_or_create_dive_site_with_name(data[2], state->cur_dive->when, &dive_site_table);
if (data[3])
utf8_string(data[3], &state->cur_dive->buddy);
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 18e365a11..668661ce8 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -596,7 +596,7 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str)
parse_location(line, &location);
if (location.lat.udeg && location.lon.udeg)
- dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL));
+ dive->dive_site = create_dive_site_with_gps(str->value, &location, time(NULL), &dive_site_table);
}
}
#endif
diff --git a/core/liquivision.c b/core/liquivision.c
index 5d9fa0a73..bec4b771b 100644
--- a/core/liquivision.c
+++ b/core/liquivision.c
@@ -227,7 +227,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int
// now that we have the dive time we can store the divesite
// (we need the dive time to create deterministic uuids)
if (found_divesite) {
- dive->dive_site = find_or_create_dive_site_with_name(location, dive->when);
+ dive->dive_site = find_or_create_dive_site_with_name(location, dive->when, &dive_site_table);
free(location);
}
//unsigned int end_time = array_uint32_le(buf + ptr);
diff --git a/core/load-git.c b/core/load-git.c
index 28b33f036..be8a839da 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -157,9 +157,9 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
parse_location(line, &location);
if (!ds) {
- ds = get_dive_site_by_gps(&location);
+ ds = get_dive_site_by_gps(&location, &dive_site_table);
if (!ds)
- dive->dive_site = create_dive_site_with_gps("", &location, dive->when);
+ dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table);
else
dive->dive_site = ds;
} else {
@@ -181,9 +181,9 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
struct dive *dive = _dive;
struct dive_site *ds = get_dive_site_for_dive(dive);
if (!ds) {
- ds = get_dive_site_by_name(name);
+ ds = get_dive_site_by_name(name, &dive_site_table);
if (!ds)
- dive->dive_site = create_dive_site(name, dive->when);
+ dive->dive_site = create_dive_site(name, dive->when, &dive_site_table);
else
dive->dive_site = ds;
} else {
@@ -212,7 +212,7 @@ static void parse_dive_notes(char *line, struct membuffer *str, void *_dive)
{ UNUSED(line); struct dive *dive = _dive; dive->notes = get_utf8(str); }
static void parse_dive_divesiteid(char *line, struct membuffer *str, void *_dive)
-{ UNUSED(str); struct dive *dive = _dive; dive->dive_site = get_dive_site_by_uuid(get_hex(line)); }
+{ UNUSED(str); struct dive *dive = _dive; dive->dive_site = get_dive_site_by_uuid(get_hex(line), &dive_site_table); }
/*
* We can have multiple tags in the membuffer. They are separated by
@@ -1504,7 +1504,7 @@ static int parse_site_entry(git_repository *repo, const git_tree_entry *entry, c
if (*suffix == '\0')
return report_error("Dive site without uuid");
uint32_t uuid = strtoul(suffix, NULL, 16);
- struct dive_site *ds = alloc_or_get_dive_site(uuid);
+ struct dive_site *ds = alloc_or_get_dive_site(uuid, &dive_site_table);
git_blob *blob = git_tree_entry_blob(repo, entry);
if (!blob)
return report_error("Unable to read dive site file");
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 1244e0003..68b78a861 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -562,7 +562,7 @@ static void dive_site(char *buffer, struct dive_site **ds)
{
uint32_t uuid;
hex_value(buffer, &uuid);
- *ds = get_dive_site_by_uuid(uuid);
+ *ds = get_dive_site_by_uuid(uuid, &dive_site_table);
}
static void get_notrip(char *buffer, bool *notrip)
@@ -983,9 +983,9 @@ static void divinglog_place(char *place, struct dive_site **ds, struct parser_st
state->city ? state->city : "",
state->country ? ", " : "",
state->country ? state->country : "");
- *ds = get_dive_site_by_name(buffer);
+ *ds = get_dive_site_by_name(buffer, &dive_site_table);
if (!*ds)
- *ds = create_dive_site(buffer, state->cur_dive->when);
+ *ds = create_dive_site(buffer, state->cur_dive->when, &dive_site_table);
// TODO: capture the country / city info in the taxonomy instead
free(state->city);
@@ -1137,7 +1137,7 @@ static void gps_lat(char *buffer, struct dive *dive)
location.lat = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when);
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table);
} else {
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
@@ -1153,7 +1153,7 @@ static void gps_long(char *buffer, struct dive *dive)
location.lon = parse_degrees(buffer, &end);
if (!ds) {
- dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when);
+ dive->dive_site = create_dive_site_with_gps(NULL, &location, dive->when, &dive_site_table);
} else {
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)");
@@ -1184,7 +1184,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
parse_location(buffer, &location);
if (!ds) {
// check if we have a dive site within 20 meters of that gps fix
- ds = get_dive_site_by_gps_proximity(&location, 20);
+ ds = get_dive_site_by_gps_proximity(&location, 20, &dive_site_table);
if (ds) {
// found a site nearby; in case it turns out this one had a different name let's
@@ -1192,7 +1192,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
state->cur_location = location;
dive->dive_site = ds;
} else {
- dive->dive_site = create_dive_site_with_gps("", &location, dive->when);
+ dive->dive_site = create_dive_site_with_gps("", &location, dive->when, &dive_site_table);
}
} else {
if (dive_site_has_gps_location(ds) &&
@@ -2120,7 +2120,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
/* Measure GPS */
state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0));
state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0));
- state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when);
+ state.cur_dive->dive_site = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when, &dive_site_table);
break;
default:
break;
diff --git a/core/parse.c b/core/parse.c
index af1046014..ba12cfddc 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -225,7 +225,7 @@ void dive_site_end(struct parser_state *state)
state->cur_dive_site->taxonomy.category = NULL;
}
if (state->cur_dive_site->uuid) {
- struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid);
+ struct dive_site *ds = alloc_or_get_dive_site(state->cur_dive_site->uuid, &dive_site_table);
merge_dive_site(ds, state->cur_dive_site);
if (verbose > 3)
@@ -419,7 +419,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
struct dive_site *ds = dive->dive_site;
if (!ds) {
// if the dive doesn't have a uuid, check if there's already a dive site by this name
- ds = get_dive_site_by_name(buffer);
+ ds = get_dive_site_by_name(buffer, &dive_site_table);
}
if (ds) {
// we have a uuid, let's hope there isn't a different name
@@ -430,11 +430,11 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
// but wait, we could have gotten this one based on GPS coords and could
// have had two different names for the same site... so let's search the other
// way around
- struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location);
+ struct dive_site *exact_match = get_dive_site_by_gps_and_name(buffer, &ds->location, &dive_site_table);
if (exact_match) {
dive->dive_site = exact_match;
} else {
- struct dive_site *newds = create_dive_site(buffer, dive->when);
+ struct dive_site *newds = create_dive_site(buffer, dive->when, &dive_site_table);
dive->dive_site = newds;
if (has_location(&state->cur_location)) {
// we started this uuid with GPS data, so lets use those
@@ -449,7 +449,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
dive->dive_site = ds;
}
} else {
- dive->dive_site = create_dive_site(buffer, dive->when);
+ dive->dive_site = create_dive_site(buffer, dive->when, &dive_site_table);
}
}
free(to_free);
diff --git a/core/save-git.c b/core/save-git.c
index d7143e8db..ce4f52f5e 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -879,10 +879,10 @@ static void save_divesites(git_repository *repo, struct dir *tree)
subdir = new_directory(repo, tree, &dirname);
free_buffer(&dirname);
- purge_empty_dive_sites();
+ purge_empty_dive_sites(&dive_site_table);
for (int i = 0; i < dive_site_table.nr; i++) {
struct membuffer b = { 0 };
- struct dive_site *ds = get_dive_site(i);
+ struct dive_site *ds = get_dive_site(i, &dive_site_table);
/* Only write used dive sites */
if (!is_dive_site_used(ds, false))
continue;
diff --git a/core/save-xml.c b/core/save-xml.c
index fa71773c7..7df5d3de0 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -591,11 +591,11 @@ void save_dives_buffer(struct membuffer *b, const bool select_only, bool anonymi
put_format(b, "</settings>\n");
/* save the dive sites - to make the output consistent let's sort the table, first */
- dive_site_table_sort();
- purge_empty_dive_sites();
+ dive_site_table_sort(&dive_site_table);
+ purge_empty_dive_sites(&dive_site_table);
put_format(b, "<divesites>\n");
for (i = 0; i < dive_site_table.nr; i++) {
- struct dive_site *ds = get_dive_site(i);
+ struct dive_site *ds = get_dive_site(i, &dive_site_table);
/* Only write used dive sites */
if (!is_dive_site_used(ds, false))
continue;
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 930abbc18..36cac2c5a 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -993,7 +993,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *
} else if (!is_log && dive && !strcmp(tag, "divespot_id")) {
int divespot_id = atoi(val);
if (divespot_id != -1) {
- struct dive_site *ds = create_dive_site("from Uemis", dive->when);
+ struct dive_site *ds = create_dive_site("from Uemis", dive->when, &dive_site_table);
dive->dive_site = ds;
uemis_mark_divelocation(dive->dc.diveid, divespot_id, ds);
}
@@ -1191,11 +1191,11 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di
* we search all existing divesites if we have one with the same name already. The function
* returns the first found which is luckily not the newly created.
*/
- ods = get_dive_site_by_name(nds->name);
+ ods = get_dive_site_by_name(nds->name, &dive_site_table);
if (ods) {
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
if (nds->uuid != ods->uuid) {
- delete_dive_site(nds);
+ delete_dive_site(nds, &dive_site_table);
dive->dive_site = ods;
}
}
@@ -1204,7 +1204,7 @@ static void get_uemis_divespot(const char *mountpath, int divespot_id, struct di
/* if we can't load the dive site details, delete the site we
* created in process_raw_buffer
*/
- delete_dive_site(dive->dive_site);
+ delete_dive_site(dive->dive_site, &dive_site_table);
}
}
}
diff --git a/desktop-widgets/locationinformation.cpp b/desktop-widgets/locationinformation.cpp
index 24f45058a..ea52dd8c6 100644
--- a/desktop-widgets/locationinformation.cpp
+++ b/desktop-widgets/locationinformation.cpp
@@ -198,7 +198,7 @@ void LocationInformationWidget::acceptChanges()
if (!ui.diveSiteCoordinates->text().isEmpty())
parseGpsText(ui.diveSiteCoordinates->text(), diveSite->location);
if (dive_site_is_empty(diveSite)) {
- LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite));
+ LocationInformationModel::instance()->removeRow(get_divesite_idx(diveSite, &dive_site_table));
displayed_dive.dive_site = nullptr;
diveSite = nullptr;
}
@@ -388,7 +388,7 @@ QVariant DiveLocationModel::data(const QModelIndex &index, int role) const
}
// The dive sites are -2 because of the first two items.
- struct dive_site *ds = get_dive_site(index.row() - 2);
+ struct dive_site *ds = get_dive_site(index.row() - 2, &dive_site_table);
return LocationInformationModel::getDiveSiteData(ds, index.column(), role);
}
@@ -522,7 +522,7 @@ static struct dive_site *get_dive_site_name_start_which_str(const QString &str)
{
struct dive_site *ds;
int i;
- for_each_dive_site (i, ds) {
+ for_each_dive_site (i, ds, &dive_site_table) {
QString dsName(ds->name);
if (dsName.toLower().startsWith(str.toLower())) {
return ds;
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index d1f13dd13..7f30c8962 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -658,7 +658,7 @@ struct dive_site *MainTab::updateDiveSite(struct dive_site *pickedDs, dive *d)
if (pickedDs == RECENTLY_ADDED_DIVESITE) {
QString name = ui.location->text().isEmpty() ? tr("New dive site") : ui.location->text();
- pickedDs = create_dive_site(qPrintable(name), displayed_dive.when);
+ pickedDs = create_dive_site(qPrintable(name), displayed_dive.when, &dive_site_table);
createdNewDive = true;
}
@@ -856,7 +856,7 @@ void MainTab::acceptChanges()
if (oldDs && !is_dive_site_used(oldDs, false)) {
if (verbose)
qDebug() << "delete now unused dive site" << (oldDs->name ? oldDs->name : "without name");
- delete_dive_site(oldDs);
+ delete_dive_site(oldDs, &dive_site_table);
MapWidget::instance()->reload();
}
// the code above can change the correct uuid for the displayed dive site - and the
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 196554654..8239bfc7a 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -773,7 +773,7 @@ static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, doub
if (ds) {
ds->location = location;
} else {
- d->dive_site = create_dive_site_with_gps(locationtext, &location, d->when);
+ d->dive_site = create_dive_site_with_gps(locationtext, &location, d->when, &dive_site_table);
}
}
@@ -889,9 +889,9 @@ bool QMLManager::checkLocation(DiveObjectHelper *myDive, struct dive *d, QString
qDebug() << "checkLocation" << location << "gps" << gps << "dive had" << myDive->location() << "gps" << myDive->gas();
if (myDive->location() != location) {
diveChanged = true;
- ds = get_dive_site_by_name(qPrintable(location));
+ ds = get_dive_site_by_name(qPrintable(location), &dive_site_table);
if (!ds && !location.isEmpty())
- ds = create_dive_site(qPrintable(location), d->when);
+ ds = create_dive_site(qPrintable(location), d->when, &dive_site_table);
d->dive_site = ds;
}
// now make sure that the GPS coordinates match - if the user changed the name but not
@@ -1597,11 +1597,11 @@ QString QMLManager::getVersion() const
return versionRe.cap(1);
}
-QString QMLManager::getGpsFromSiteName(const QString& siteName)
+QString QMLManager::getGpsFromSiteName(const QString &siteName)
{
struct dive_site *ds;
- ds = get_dive_site_by_name(qPrintable(siteName));
+ ds = get_dive_site_by_name(qPrintable(siteName), &dive_site_table);
if (!ds)
return QString();
return printGPSCoords(&ds->location);
diff --git a/qt-models/divelocationmodel.cpp b/qt-models/divelocationmodel.cpp
index a942961a5..552c7c276 100644
--- a/qt-models/divelocationmodel.cpp
+++ b/qt-models/divelocationmodel.cpp
@@ -70,7 +70,7 @@ QVariant LocationInformationModel::data(const QModelIndex &index, int role) cons
if (!index.isValid())
return QVariant();
- struct dive_site *ds = get_dive_site(index.row());
+ struct dive_site *ds = get_dive_site(index.row(), &dive_site_table);
return getDiveSiteData(ds, index.column(), role);
}
@@ -95,9 +95,9 @@ bool LocationInformationModel::removeRows(int row, int, const QModelIndex&)
return false;
beginRemoveRows(QModelIndex(), row, row);
- struct dive_site *ds = get_dive_site(row);
+ struct dive_site *ds = get_dive_site(row, &dive_site_table);
if (ds)
- delete_dive_site(ds);
+ delete_dive_site(ds, &dive_site_table);
endRemoveRows();
return true;
}
diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c
index 8ef01de48..b33afb43c 100644
--- a/smtk-import/smartrak.c
+++ b/smtk-import/smartrak.c
@@ -373,12 +373,12 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, str
str = smtk_concat_str(str, ", ", "%s", col[1]->bind_ptr); // Locality
str = smtk_concat_str(str, ", ", "%s", site);
- ds = get_dive_site_by_name(str);
+ ds = get_dive_site_by_name(str, &dive_site_table);
if (!ds) {
if (!has_location(&loc))
- ds = create_dive_site(str, when);
+ ds = create_dive_site(str, when, &dive_site_table);
else
- ds = create_dive_site_with_gps(str, &loc, when);
+ ds = create_dive_site_with_gps(str, &loc, when, &dive_site_table);
}
*location = ds;
smtk_free(bound_values, table->num_cols);
diff --git a/tests/testparse.cpp b/tests/testparse.cpp
index c728b8ef1..2a90f5a0f 100644
--- a/tests/testparse.cpp
+++ b/tests/testparse.cpp
@@ -113,7 +113,7 @@ int TestParse::parseCSV(int units, std::string file)
int TestParse::parseDivingLog()
{
// Parsing of DivingLog import from SQLite database
- struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef);
+ struct dive_site *ds = alloc_or_get_dive_site(0xdeadbeef, &dive_site_table);
ds->name = copy_string("Suomi - - Hälvälä");
int ret = sqlite3_open(SUBSURFACE_TEST_DATA "/dives/TestDivingLog4.1.1.sql", &_sqlite3_handle);