core: move divesite_has_gps_information() to struct dive_site

Seems logical in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-30 17:38:36 +02:00 committed by bstoeger
parent c812dd140b
commit 0aa4efb3d9
14 changed files with 20 additions and 21 deletions

View file

@ -2531,14 +2531,9 @@ const struct divecomputer *get_dive_dc(const struct dive *dive, int nr)
return get_dive_dc((struct dive *)dive, nr);
}
bool dive_site_has_gps_location(const struct dive_site *ds)
{
return ds && has_location(&ds->location);
}
bool dive::dive_has_gps_location() const
{
return dive_site && dive_site_has_gps_location(dive_site);
return dive_site && dive_site->has_gps_location();
}
/* Extract GPS location of a dive computer stored in the GPS1

View file

@ -167,8 +167,6 @@ extern const struct divecomputer *get_dive_dc(const struct dive *dive, int nr);
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
extern bool dive_site_has_gps_location(const struct dive_site *ds);
extern bool time_during_dive_with_offset(const struct dive *dive, timestamp_t when, timestamp_t offset);
extern int save_dives(const char *filename);

View file

@ -1175,7 +1175,7 @@ merge_result dive_table::merge_dives(const struct dive &a_in, const struct dive
/* we take the first dive site, unless it's empty */
res.site = a->dive_site && !a->dive_site->is_empty() ? a->dive_site : b->dive_site;
if (!dive_site_has_gps_location(res.site) && dive_site_has_gps_location(b->dive_site)) {
if (res.site && !res.site->has_gps_location() && b->dive_site && b->dive_site->has_gps_location()) {
/* we picked the first dive site and that didn't have GPS data, but the new dive has
* GPS data (that could be a download from a GPS enabled dive computer).
* Keep the dive site, but add the GPS data */

View file

@ -134,6 +134,11 @@ bool dive_site::is_selected() const
[](dive *dive) { return dive->selected; });
}
bool dive_site::has_gps_location() const
{
return has_location(&location);
}
/* allocate a new site and add it to the table */
dive_site *dive_site_table::create(const std::string &name)
{

View file

@ -26,6 +26,7 @@ struct dive_site
size_t nr_of_dives() const;
bool is_selected() const;
bool is_empty() const;
bool has_gps_location() const;
void merge(struct dive_site &b); // Note: b is consumed
void add_dive(struct dive *d);
};

View file

@ -181,7 +181,7 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
ds = state->log->sites.create(std::string(), location);
ds->add_dive(state->active_dive.get());
} else {
if (dive_site_has_gps_location(ds) && ds->location != location) {
if (ds->has_gps_location() && ds->location != location) {
std::string coords = printGPSCoordsC(&location);
// we have a dive site that already has GPS coordinates
// note 1: there will be much less copying once the core

View file

@ -36,7 +36,7 @@ static void writeMarkers(struct membuffer *b, bool selected_only)
if (selected_only && !dive->selected)
continue;
struct dive_site *ds = get_dive_site_for_dive(dive.get());
if (!dive_site_has_gps_location(ds))
if (!ds || !ds->has_gps_location())
continue;
put_degrees(b, ds->location.lat, "temp = new google.maps.Marker({position: new google.maps.LatLng(", "");
put_degrees(b, ds->location.lon, ",", ")});\n");