mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: include divesite table directly in divelog
Having this as a pointer is an artifact from the C/C++ split. The divesitetable header is small enough so that we can include it directly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
7792f54a73
commit
5af9d28291
29 changed files with 90 additions and 91 deletions
|
|
@ -211,9 +211,9 @@ static char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct
|
|||
*/
|
||||
{
|
||||
std::string buffer2 = std::string((char *)locality) + " " + (char *)dive_point;
|
||||
struct dive_site *ds = log->sites->get_by_name(buffer2);
|
||||
struct dive_site *ds = log->sites.get_by_name(buffer2);
|
||||
if (!ds)
|
||||
ds = log->sites->create(buffer2);
|
||||
ds = log->sites.create(buffer2);
|
||||
ds->add_dive(dt_dive);
|
||||
}
|
||||
free(locality);
|
||||
|
|
|
|||
|
|
@ -931,7 +931,7 @@ void add_imported_dives(struct divelog &import_log, int flags)
|
|||
|
||||
/* Add new dive sites */
|
||||
for (auto &ds: dive_sites_to_add)
|
||||
divelog.sites->register_site(std::move(ds));
|
||||
divelog.sites.register_site(std::move(ds));
|
||||
|
||||
/* Add new devices */
|
||||
for (auto &dev: devices_to_add)
|
||||
|
|
@ -1047,13 +1047,13 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
|
|||
autogroup_dives(import_log.dives, *import_log.trips);
|
||||
|
||||
/* If dive sites already exist, use the existing versions. */
|
||||
for (auto &new_ds: *import_log.sites) {
|
||||
for (auto &new_ds: import_log.sites) {
|
||||
/* Check if it dive site is actually used by new dives. */
|
||||
if (std::none_of(import_log.dives.begin(), import_log.dives.end(), [ds=new_ds.get()]
|
||||
(auto &d) { return d->dive_site == ds; }))
|
||||
continue;
|
||||
|
||||
struct dive_site *old_ds = divelog.sites->get_same(*new_ds);
|
||||
struct dive_site *old_ds = divelog.sites.get_same(*new_ds);
|
||||
if (!old_ds) {
|
||||
/* Dive site doesn't exist. Add it to list of dive sites to be added. */
|
||||
new_ds->dives.clear(); /* Caller is responsible for adding dives to site */
|
||||
|
|
@ -1066,7 +1066,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
|
|||
}
|
||||
}
|
||||
}
|
||||
import_log.sites->clear();
|
||||
import_log.sites.clear();
|
||||
|
||||
/* Merge overlapping trips. Since both trip tables are sorted, we
|
||||
* could be smarter here, but realistically not a whole lot of trips
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ struct divelog divelog;
|
|||
|
||||
divelog::divelog() :
|
||||
trips(std::make_unique<trip_table>()),
|
||||
sites(std::make_unique<dive_site_table>()),
|
||||
filter_presets(std::make_unique<filter_preset_table>()),
|
||||
autogroup(false)
|
||||
{
|
||||
|
|
@ -67,7 +66,7 @@ void divelog::delete_multiple_dives(const std::vector<dive *> &dives_to_delete)
|
|||
void divelog::clear()
|
||||
{
|
||||
dives.clear();
|
||||
sites->clear();
|
||||
sites.clear();
|
||||
trips->clear();
|
||||
devices.clear();
|
||||
filter_presets->clear();
|
||||
|
|
|
|||
|
|
@ -4,19 +4,19 @@
|
|||
#define DIVELOG_H
|
||||
|
||||
#include "divelist.h"
|
||||
#include "divesitetable.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
struct trip_table;
|
||||
class dive_site_table;
|
||||
struct device;
|
||||
struct filter_preset_table;
|
||||
|
||||
struct divelog {
|
||||
dive_table dives;
|
||||
std::unique_ptr<trip_table> trips;
|
||||
std::unique_ptr<dive_site_table> sites;
|
||||
dive_site_table sites;
|
||||
std::vector<device> devices;
|
||||
std::unique_ptr<filter_preset_table> filter_presets;
|
||||
bool autogroup;
|
||||
|
|
|
|||
|
|
@ -181,7 +181,7 @@ static int cobalt_dive(void *param, int, char **data, char **)
|
|||
|
||||
if (location && location_site) {
|
||||
std::string tmp = std::string(location) + " / " + location_site;
|
||||
state->log->sites->find_or_create(tmp)->add_dive(state->cur_dive.get());
|
||||
state->log->sites.find_or_create(tmp)->add_dive(state->cur_dive.get());
|
||||
}
|
||||
free(location);
|
||||
free(location_site);
|
||||
|
|
|
|||
|
|
@ -276,7 +276,7 @@ static int divinglog_dive(void *param, int, char **data, char **)
|
|||
state->cur_dive->when = (time_t)(atol(data[1]));
|
||||
|
||||
if (data[2])
|
||||
state->log->sites->find_or_create(std::string(data[2]))->add_dive(state->cur_dive.get());
|
||||
state->log->sites.find_or_create(std::string(data[2]))->add_dive(state->cur_dive.get());
|
||||
|
||||
if (data[3])
|
||||
utf8_string_std(data[3], &state->cur_dive->buddy);
|
||||
|
|
|
|||
|
|
@ -617,7 +617,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -437,7 +437,7 @@ int try_to_open_liquivision(const char *, std::string &mem, struct divelog *log)
|
|||
}
|
||||
ptr += 4;
|
||||
|
||||
parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, *log->sites);
|
||||
parse_dives(log_version, buf + ptr, buf_size - ptr, log->dives, log->sites);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,9 +175,9 @@ static void parse_dive_gps(char *line, struct git_parser_state *state)
|
|||
|
||||
parse_location(line, &location);
|
||||
if (!ds) {
|
||||
ds = state->log->sites->get_by_gps(&location);
|
||||
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.get());
|
||||
} else {
|
||||
if (dive_site_has_gps_location(ds) && ds->location != location) {
|
||||
|
|
@ -221,9 +221,9 @@ static void parse_dive_location(char *, struct git_parser_state *state)
|
|||
std::string name = get_first_converted_string(state);
|
||||
struct dive_site *ds = get_dive_site_for_dive(state->active_dive.get());
|
||||
if (!ds) {
|
||||
ds = state->log->sites->get_by_name(name);
|
||||
ds = state->log->sites.get_by_name(name);
|
||||
if (!ds)
|
||||
ds = state->log->sites->create(name);
|
||||
ds = state->log->sites.create(name);
|
||||
ds->add_dive(state->active_dive.get());
|
||||
} else {
|
||||
// we already had a dive site linked to the dive
|
||||
|
|
@ -252,7 +252,7 @@ static void parse_dive_notes(char *, struct git_parser_state *state)
|
|||
{ state->active_dive->notes = get_first_converted_string(state); }
|
||||
|
||||
static void parse_dive_divesiteid(char *line, struct git_parser_state *state)
|
||||
{ state->log->sites->get_by_uuid(get_hex(line))->add_dive(state->active_dive.get()); }
|
||||
{ state->log->sites.get_by_uuid(get_hex(line))->add_dive(state->active_dive.get()); }
|
||||
|
||||
/*
|
||||
* We can have multiple tags.
|
||||
|
|
@ -1698,7 +1698,7 @@ static int parse_site_entry(struct git_parser_state *state, const git_tree_entry
|
|||
if (*suffix == '\0')
|
||||
return report_error("Dive site without uuid");
|
||||
uint32_t uuid = strtoul(suffix, NULL, 16);
|
||||
state->active_site = state->log->sites->alloc_or_get(uuid);
|
||||
state->active_site = state->log->sites.alloc_or_get(uuid);
|
||||
git_blob *blob = git_tree_entry_blob(state->repo, entry);
|
||||
if (!blob)
|
||||
return report_error("Unable to read dive site file");
|
||||
|
|
|
|||
|
|
@ -560,7 +560,7 @@ static void dive_site(const char *buffer, struct dive *d, struct parser_state *s
|
|||
{
|
||||
uint32_t uuid;
|
||||
hex_value(buffer, &uuid);
|
||||
state->log->sites->get_by_uuid(uuid)->add_dive(d);
|
||||
state->log->sites.get_by_uuid(uuid)->add_dive(d);
|
||||
}
|
||||
|
||||
static void get_notrip(const char *buffer, bool *notrip)
|
||||
|
|
@ -977,9 +977,9 @@ static void divinglog_place(const char *place, struct dive *d, struct parser_sta
|
|||
!state->city.empty() ? state->city.c_str() : "",
|
||||
!state->country.empty() ? ", " : "",
|
||||
!state->country.empty() ? state->country.c_str() : "");
|
||||
ds = state->log->sites->get_by_name(buffer);
|
||||
ds = state->log->sites.get_by_name(buffer);
|
||||
if (!ds)
|
||||
ds = state->log->sites->create(buffer);
|
||||
ds = state->log->sites.create(buffer);
|
||||
ds->add_dive(d);
|
||||
|
||||
// TODO: capture the country / city info in the taxonomy instead
|
||||
|
|
@ -1147,7 +1147,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,
|
||||
|
|
@ -1164,7 +1164,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,
|
||||
|
|
@ -1195,14 +1195,14 @@ static void gps_in_dive(const char *buffer, struct dive *dive, struct parser_sta
|
|||
parse_location(buffer, &location);
|
||||
if (!ds) {
|
||||
// check if we have a dive site within 20 meters of that gps fix
|
||||
ds = state->log->sites->get_by_gps_proximity(location, 20);
|
||||
ds = state->log->sites.get_by_gps_proximity(location, 20);
|
||||
|
||||
if (ds) {
|
||||
// found a site nearby; in case it turns out this one had a different name let's
|
||||
// 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 {
|
||||
|
|
@ -2226,7 +2226,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.get());
|
||||
state.log->sites.create("DLF imported"s, state.cur_location)->add_dive(state.cur_dive.get());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -184,7 +184,7 @@ void dive_site_end(struct parser_state *state)
|
|||
if (!state->cur_dive_site)
|
||||
return;
|
||||
|
||||
struct dive_site *ds = state->log->sites->alloc_or_get(state->cur_dive_site->uuid);
|
||||
struct dive_site *ds = state->log->sites.alloc_or_get(state->cur_dive_site->uuid);
|
||||
ds->merge(*state->cur_dive_site);
|
||||
|
||||
if (verbose > 3)
|
||||
|
|
@ -428,7 +428,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
|
|||
struct dive_site *ds = dive->dive_site;
|
||||
if (!ds) {
|
||||
// if the dive doesn't have a dive site, check if there's already a dive site by this name
|
||||
ds = state->log->sites->get_by_name(trimmed);
|
||||
ds = state->log->sites.get_by_name(trimmed);
|
||||
}
|
||||
if (ds) {
|
||||
// we have a dive site, let's hope there isn't a different name
|
||||
|
|
@ -439,12 +439,12 @@ 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);
|
||||
} else {
|
||||
struct dive_site *newds = state->log->sites->create(trimmed.c_str());
|
||||
struct dive_site *newds = state->log->sites.create(trimmed.c_str());
|
||||
unregister_dive_from_dive_site(dive);
|
||||
newds->add_dive(dive);
|
||||
if (has_location(&state->cur_location)) {
|
||||
|
|
@ -462,7 +462,7 @@ void add_dive_site(const char *ds_name, struct dive *dive, struct parser_state *
|
|||
ds->add_dive(dive);
|
||||
}
|
||||
} else {
|
||||
state->log->sites->create(trimmed)->add_dive(dive);
|
||||
state->log->sites.create(trimmed)->add_dive(dive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -886,8 +886,8 @@ static void save_divesites(git_repository *repo, struct dir *tree)
|
|||
put_format(&dirname, "01-Divesites");
|
||||
subdir = new_directory(repo, tree, &dirname);
|
||||
|
||||
divelog.sites->purge_empty();
|
||||
for (const auto &ds: *divelog.sites) {
|
||||
divelog.sites.purge_empty();
|
||||
for (const auto &ds: divelog.sites) {
|
||||
membuffer b;
|
||||
membuffer site_file_name;
|
||||
put_format(&site_file_name, "Site-%08x", ds->uuid);
|
||||
|
|
|
|||
|
|
@ -653,7 +653,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
|
|||
|
||||
/* save the dive sites */
|
||||
put_format(b, "<divesites>\n");
|
||||
for (const auto &ds: *divelog.sites) {
|
||||
for (const auto &ds: divelog.sites) {
|
||||
/* Don't export empty dive sites */
|
||||
if (ds->is_empty())
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -918,7 +918,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, std::s
|
|||
} else if (non_owned_dive && tag == "divespot_id") {
|
||||
int divespot_id;
|
||||
if (from_chars(val, divespot_id).ec != std::errc::invalid_argument) {
|
||||
struct dive_site *ds = devdata->log->sites->create("from Uemis"s);
|
||||
struct dive_site *ds = devdata->log->sites.create("from Uemis"s);
|
||||
unregister_dive_from_dive_site(non_owned_dive);
|
||||
ds->add_dive(non_owned_dive);
|
||||
uemis_obj.mark_divelocation(non_owned_dive->dcs[0].diveid, divespot_id, ds);
|
||||
|
|
@ -1094,19 +1094,19 @@ static void get_uemis_divespot(device_data_t *devdata, const std::string &mountp
|
|||
* 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.
|
||||
*/
|
||||
struct dive_site *ods = devdata->log->sites->get_by_name(nds->name);
|
||||
struct dive_site *ods = devdata->log->sites.get_by_name(nds->name);
|
||||
if (ods && nds->uuid != ods->uuid) {
|
||||
/* if the uuid's are the same, the new site is a duplicate and can be deleted */
|
||||
unregister_dive_from_dive_site(dive);
|
||||
ods->add_dive(dive);
|
||||
devdata->log->sites->pull(nds);
|
||||
devdata->log->sites.pull(nds);
|
||||
}
|
||||
divespot_mapping[divespot_id] = dive->dive_site;
|
||||
} else {
|
||||
/* if we can't load the dive site details, delete the site we
|
||||
* created in process_raw_buffer
|
||||
*/
|
||||
devdata->log->sites->pull(dive->dive_site);
|
||||
devdata->log->sites.pull(dive->dive_site);
|
||||
dive->dive_site = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue