mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Dive site: return pointer to dive_site in create_dive_site_*()
This changes more of the dive-site interface to return pointers instead of UUIDs. Currently, most call sites directly extract UUIDs afterwards. Ultimately, the UUIDs will be generally replaced by pointers, which will then simplify these callers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ae6239bfec
commit
d3a7c5448f
16 changed files with 35 additions and 36 deletions
|
@ -204,7 +204,7 @@ unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive)
|
|||
ds = get_dive_site_by_name(buffer);
|
||||
dt_dive->dive_site_uuid = ds ? ds->uuid : 0;
|
||||
if (dt_dive->dive_site_uuid == 0)
|
||||
dt_dive->dive_site_uuid = create_dive_site(buffer, dt_dive->when);
|
||||
dt_dive->dive_site_uuid = create_dive_site(buffer, dt_dive->when)->uuid;
|
||||
free(locality);
|
||||
locality = NULL;
|
||||
free(dive_point);
|
||||
|
|
|
@ -4080,7 +4080,7 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture)
|
|||
if (ds) {
|
||||
ds->location = picture->location;
|
||||
} else {
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &picture->location, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &picture->location, dive->when)->uuid;
|
||||
invalidate_dive_cache(dive);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,16 +203,16 @@ uint32_t create_divesite_uuid(const char *name, timestamp_t divetime)
|
|||
}
|
||||
|
||||
/* allocate a new site and add it to the table */
|
||||
uint32_t create_dive_site(const char *name, timestamp_t divetime)
|
||||
struct dive_site *create_dive_site(const char *name, timestamp_t divetime)
|
||||
{
|
||||
uint32_t uuid = create_divesite_uuid(name, divetime);
|
||||
struct dive_site *ds = alloc_or_get_dive_site(uuid);
|
||||
ds->name = copy_string(name);
|
||||
return uuid;
|
||||
return ds;
|
||||
}
|
||||
|
||||
/* same as before, but with current time if no current_dive is present */
|
||||
uint32_t create_dive_site_from_current_dive(const char *name)
|
||||
struct dive_site *create_dive_site_from_current_dive(const char *name)
|
||||
{
|
||||
if (current_dive != NULL) {
|
||||
return create_dive_site(name, current_dive->when);
|
||||
|
@ -225,14 +225,14 @@ uint32_t create_dive_site_from_current_dive(const char *name)
|
|||
}
|
||||
|
||||
/* same as before, but with GPS data */
|
||||
uint32_t 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)
|
||||
{
|
||||
uint32_t uuid = create_divesite_uuid(name, divetime);
|
||||
struct dive_site *ds = alloc_or_get_dive_site(uuid);
|
||||
ds->name = copy_string(name);
|
||||
ds->location = *loc;
|
||||
|
||||
return ds->uuid;
|
||||
return ds;
|
||||
}
|
||||
|
||||
/* a uuid is always present - but if all the other fields are empty, the dive site is pointless */
|
||||
|
@ -330,7 +330,7 @@ void merge_dive_sites(uint32_t ref, uint32_t* uuids, int count)
|
|||
mark_divelist_changed(true);
|
||||
}
|
||||
|
||||
uint32_t 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)
|
||||
{
|
||||
int i;
|
||||
struct dive_site *ds;
|
||||
|
@ -339,7 +339,7 @@ uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t diveti
|
|||
break;
|
||||
}
|
||||
if (ds)
|
||||
return ds->uuid;
|
||||
return ds;
|
||||
return create_dive_site(name, divetime);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,9 +58,9 @@ int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only);
|
|||
bool is_dive_site_used(uint32_t uuid, bool select_only);
|
||||
void free_dive_site(struct dive_site *ds);
|
||||
void delete_dive_site(uint32_t id);
|
||||
uint32_t create_dive_site(const char *name, timestamp_t divetime);
|
||||
uint32_t create_dive_site_from_current_dive(const char *name);
|
||||
uint32_t create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime);
|
||||
struct dive_site *create_dive_site(const char *name, timestamp_t divetime);
|
||||
struct dive_site *create_dive_site_from_current_dive(const char *name);
|
||||
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 *);
|
||||
|
@ -71,7 +71,7 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy);
|
|||
void merge_dive_site(struct dive_site *a, struct dive_site *b);
|
||||
void clear_dive_site(struct dive_site *ds);
|
||||
unsigned int get_distance(const location_t *loc1, const location_t *loc2);
|
||||
uint32_t 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);
|
||||
void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -211,8 +211,8 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d)
|
|||
{
|
||||
struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid);
|
||||
if (!ds) {
|
||||
d->dive_site_uuid = create_dive_site(qPrintable(gps.name), gps.when);
|
||||
ds = get_dive_site_by_uuid(d->dive_site_uuid);
|
||||
ds = create_dive_site(qPrintable(gps.name), gps.when);
|
||||
d->dive_site_uuid = ds->uuid;
|
||||
}
|
||||
ds->location = gps.location;
|
||||
}
|
||||
|
|
|
@ -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_uuid = find_or_create_dive_site_with_name(tmp, state->cur_dive->when);
|
||||
state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(tmp, state->cur_dive->when)->uuid;
|
||||
free(tmp);
|
||||
}
|
||||
free(location);
|
||||
|
|
|
@ -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_uuid = find_or_create_dive_site_with_name(data[2], state->cur_dive->when);
|
||||
state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(data[2], state->cur_dive->when)->uuid;
|
||||
|
||||
if (data[3])
|
||||
utf8_string(data[3], &state->cur_dive->buddy);
|
||||
|
|
|
@ -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_uuid = create_dive_site_with_gps(str->value, &location, time(NULL));
|
||||
dive->dive_site_uuid = create_dive_site_with_gps(str->value, &location, time(NULL))->uuid;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -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_uuid = find_or_create_dive_site_with_name(location, dive->when);
|
||||
dive->dive_site_uuid = find_or_create_dive_site_with_name(location, dive->when)->uuid;
|
||||
free(location);
|
||||
}
|
||||
//unsigned int end_time = array_uint32_le(buf + ptr);
|
||||
|
|
|
@ -159,7 +159,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
|
|||
if (!ds) {
|
||||
ds = get_dive_site_by_gps(&location);
|
||||
if (!ds)
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid;
|
||||
else
|
||||
dive->dive_site_uuid = ds->uuid;
|
||||
} else {
|
||||
|
@ -183,7 +183,7 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
|
|||
if (!ds) {
|
||||
ds = get_dive_site_by_name(name);
|
||||
if (!ds)
|
||||
dive->dive_site_uuid = create_dive_site(name, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site(name, dive->when)->uuid;
|
||||
else
|
||||
dive->dive_site_uuid = ds->uuid;
|
||||
} else {
|
||||
|
|
|
@ -981,7 +981,7 @@ static void divinglog_place(char *place, uint32_t *uuid, struct parser_state *st
|
|||
if (ds)
|
||||
*uuid = ds->uuid;
|
||||
else
|
||||
*uuid = create_dive_site(buffer, state->cur_dive->when);
|
||||
*uuid = create_dive_site(buffer, state->cur_dive->when)->uuid;
|
||||
|
||||
// TODO: capture the country / city info in the taxonomy instead
|
||||
free(state->city);
|
||||
|
@ -1133,7 +1133,7 @@ static void gps_lat(char *buffer, struct dive *dive)
|
|||
|
||||
location.lat = parse_degrees(buffer, &end);
|
||||
if (!ds) {
|
||||
dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid;
|
||||
} 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)");
|
||||
|
@ -1149,7 +1149,7 @@ static void gps_long(char *buffer, struct dive *dive)
|
|||
|
||||
location.lon = parse_degrees(buffer, &end);
|
||||
if (!ds) {
|
||||
dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid;
|
||||
} 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)");
|
||||
|
@ -1189,7 +1189,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st
|
|||
state->cur_location = location;
|
||||
dive->dive_site_uuid = ds->uuid;
|
||||
} else {
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid;
|
||||
}
|
||||
} else {
|
||||
ds = get_dive_site_by_uuid(uuid);
|
||||
|
@ -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_uuid = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when);
|
||||
state.cur_dive->dive_site_uuid = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when)->uuid;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -435,8 +435,8 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
|
|||
if (exact_match) {
|
||||
dive->dive_site_uuid = exact_match->uuid;
|
||||
} else {
|
||||
dive->dive_site_uuid = create_dive_site(buffer, dive->when);
|
||||
struct dive_site *newds = get_dive_site_by_uuid(dive->dive_site_uuid);
|
||||
struct dive_site *newds = create_dive_site(buffer, dive->when);
|
||||
dive->dive_site_uuid = newds->uuid;
|
||||
if (has_location(&state->cur_location)) {
|
||||
// we started this uuid with GPS data, so lets use those
|
||||
newds->location = state->cur_location;
|
||||
|
@ -450,7 +450,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state)
|
|||
dive->dive_site_uuid = ds->uuid;
|
||||
}
|
||||
} else {
|
||||
dive->dive_site_uuid = create_dive_site(buffer, dive->when);
|
||||
dive->dive_site_uuid = create_dive_site(buffer, dive->when)->uuid;
|
||||
}
|
||||
}
|
||||
free(to_free);
|
||||
|
|
|
@ -992,7 +992,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) {
|
||||
dive->dive_site_uuid = create_dive_site("from Uemis", dive->when);
|
||||
dive->dive_site_uuid = create_dive_site("from Uemis", dive->when)->uuid;
|
||||
uemis_mark_divelocation(dive->dc.diveid, divespot_id, dive->dive_site_uuid);
|
||||
}
|
||||
#if UEMIS_DEBUG & 2
|
||||
|
|
|
@ -688,7 +688,7 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, dive *d)
|
|||
|
||||
if (pickedUuid == RECENTLY_ADDED_DIVESITE) {
|
||||
QString name = ui.location->text().isEmpty() ? tr("New dive site") : ui.location->text();
|
||||
pickedUuid = create_dive_site(qPrintable(name), displayed_dive.when);
|
||||
pickedUuid = create_dive_site(qPrintable(name), displayed_dive.when)->uuid;
|
||||
createdNewDive = true;
|
||||
LocationFilterModel::instance()->addName(name);
|
||||
}
|
||||
|
|
|
@ -760,7 +760,7 @@ static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, doub
|
|||
if (ds) {
|
||||
ds->location = location;
|
||||
} else {
|
||||
d->dive_site_uuid = create_dive_site_with_gps(locationtext, &location, d->when);
|
||||
d->dive_site_uuid = create_dive_site_with_gps(locationtext, &location, d->when)->uuid;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -879,8 +879,7 @@ bool QMLManager::checkLocation(DiveObjectHelper *myDive, struct dive *d, QString
|
|||
if (!ds)
|
||||
ds = get_dive_site_by_name(qPrintable(location));
|
||||
if (!ds && !location.isEmpty()) {
|
||||
uint32_t uuid = create_dive_site(qPrintable(location), d->when);
|
||||
ds = get_dive_site_by_uuid(uuid);
|
||||
ds = create_dive_site(qPrintable(location), d->when);
|
||||
}
|
||||
d->dive_site_uuid = ds ? ds->uuid : 0;
|
||||
}
|
||||
|
|
|
@ -376,9 +376,9 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, uin
|
|||
ds = get_dive_site_by_name(str);
|
||||
if (!ds) {
|
||||
if (!has_location(&loc))
|
||||
*location = create_dive_site(str, when);
|
||||
*location = create_dive_site(str, when)->uuid;
|
||||
else
|
||||
*location = create_dive_site_with_gps(str, &loc, when);
|
||||
*location = create_dive_site_with_gps(str, &loc, when)->uuid;
|
||||
ds = get_dive_site_by_uuid(*location);
|
||||
} else {
|
||||
*location = ds->uuid;
|
||||
|
|
Loading…
Reference in a new issue