cleanup: pass location_t as value to divesite functions

These were passed as pointers, which makes no sense.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-12 22:30:15 +02:00 committed by bstoeger
parent 858a0aecba
commit 90d5bab4e9
8 changed files with 16 additions and 16 deletions

View file

@ -171,7 +171,7 @@ AddPictures::AddPictures(const std::vector<PictureListForAddition> &pictures) :
if (!ds) {
// This dive doesn't yet have a dive site -> add a new dive site.
QString name = Command::Base::tr("unnamed dive site");
sitesToAdd.push_back(std::make_unique<dive_site>(qPrintable(name), &it->location));
sitesToAdd.push_back(std::make_unique<dive_site>(qPrintable(name), it->location));
sitesToSet.push_back({ p.d, sitesToAdd.back().get() });
} else if (!dive_site_has_gps_location(ds)) {
// This dive has a dive site, but without coordinates. Let's add them.

View file

@ -41,9 +41,9 @@ dive_site *dive_site_table::get_by_gps(const location_t *loc) const
/* 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 */
dive_site *dive_site_table::get_by_gps_and_name(const std::string &name, const location_t *loc) const
dive_site *dive_site_table::get_by_gps_and_name(const std::string &name, const location_t loc) const
{
return get_by_predicate(*this, [&name, loc](const auto &ds) { return ds->location == *loc &&
return get_by_predicate(*this, [&name, loc](const auto &ds) { return ds->location == loc &&
ds->name == name; });
}
@ -93,7 +93,7 @@ dive_site::dive_site(const std::string &name) : name(name)
{
}
dive_site::dive_site(const std::string &name, const location_t *loc) : name(name), location(*loc)
dive_site::dive_site(const std::string &name, const location_t loc) : name(name), location(loc)
{
}
@ -134,7 +134,7 @@ dive_site *dive_site_table::create(const std::string &name)
}
/* same as before, but with GPS data */
dive_site *dive_site_table::create(const std::string &name, const location_t *loc)
dive_site *dive_site_table::create(const std::string &name, const location_t loc)
{
return register_site(std::make_unique<dive_site>(name, loc)).ptr;
}

View file

@ -22,7 +22,7 @@ struct dive_site
dive_site();
dive_site(const std::string &name);
dive_site(const std::string &name, const location_t *loc);
dive_site(const std::string &name, const location_t loc);
dive_site(uint32_t uuid);
~dive_site();
@ -46,11 +46,11 @@ public:
dive_site *get_by_uuid(uint32_t uuid) const;
dive_site *alloc_or_get(uint32_t uuid);
dive_site *create(const std::string &name);
dive_site *create(const std::string &name, const location_t *);
dive_site *create(const std::string &name, const location_t);
dive_site *find_or_create(const std::string &name);
dive_site *get_by_name(const std::string &name) const;
dive_site *get_by_gps(const location_t *) const;
dive_site *get_by_gps_and_name(const std::string &name, const location_t *) const;
dive_site *get_by_gps_and_name(const std::string &name, const location_t) const;
dive_site *get_by_gps_proximity(location_t, int distance) const;
dive_site *get_same(const struct dive_site &) const;
void purge_empty();

View file

@ -636,7 +636,7 @@ static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_fie
if (location.lat.udeg && location.lon.udeg) {
unregister_dive_from_dive_site(dive);
devdata->log->sites->create(std::string(str->value), &location)->add_dive(dive);
devdata->log->sites->create(std::string(str->value), location)->add_dive(dive);
}
}
}

View file

@ -177,7 +177,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
if (!ds) {
ds = state->log->sites->get_by_gps(&location);
if (!ds)
ds = state->log->sites->create(std::string(), &location);
ds = state->log->sites->create(std::string(), location);
ds->add_dive(state->active_dive);
} else {
if (dive_site_has_gps_location(ds) && ds->location != location) {

View file

@ -1149,7 +1149,7 @@ static void gps_lat(const char *buffer, struct dive *dive, struct parser_state *
location.lat = parse_degrees(buffer, &end);
if (!ds) {
state->log->sites->create(std::string(), &location)->add_dive(dive);
state->log->sites->create(std::string(), location)->add_dive(dive);
} else {
if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg)
report_info("Oops, changing the latitude of existing dive site id %8x name %s; not good", ds->uuid,
@ -1166,7 +1166,7 @@ static void gps_long(const char *buffer, struct dive *dive, struct parser_state
location.lon = parse_degrees(buffer, &end);
if (!ds) {
state->log->sites->create(std::string(), &location)->add_dive(dive);
state->log->sites->create(std::string(), location)->add_dive(dive);
} else {
if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg)
report_info("Oops, changing the longitude of existing dive site id %8x name %s; not good", ds->uuid,
@ -1204,7 +1204,7 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
// remember the original coordinates so we can create the correct dive site later
state->cur_location = location;
} else {
ds = state->log->sites->create(std::string(), &location);
ds = state->log->sites->create(std::string(), location);
}
ds->add_dive(dive);
} else {
@ -2225,7 +2225,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
/* 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.log->sites->create("DLF imported"s, &state.cur_location)->add_dive(state.cur_dive);
state.log->sites->create("DLF imported"s, state.cur_location)->add_dive(state.cur_dive);
break;
default:
break;

View file

@ -481,7 +481,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_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 = state->log->sites->get_by_gps_and_name(trimmed, &ds->location);
struct dive_site *exact_match = state->log->sites->get_by_gps_and_name(trimmed, ds->location);
if (exact_match) {
unregister_dive_from_dive_site(dive);
exact_match->add_dive(dive);

View file

@ -428,7 +428,7 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, struct dive_site **lo
if (!has_location(&loc))
ds = log->sites->create(str);
else
ds = log->sites->create(str, &loc);
ds = log->sites->create(str, loc);
}
*location = ds;