mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: replace divesite_table_t by a vector of std::unique_ptr<>s
This is a long commit, because it introduces a new abstraction: a general std::vector<> of std::unique_ptrs<>. Moreover, it replaces a number of pointers by C++ references, when the callee does not suppoert null objects. This simplifies memory management and makes ownership more explicit. It is a proof-of-concept and a test-bed for the other core data structrures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
411188728d
commit
e39dea3d68
41 changed files with 451 additions and 426 deletions
|
@ -559,7 +559,7 @@ static void dive_site(const char *buffer, struct dive *d, struct parser_state *s
|
|||
{
|
||||
uint32_t uuid;
|
||||
hex_value(buffer, &uuid);
|
||||
add_dive_to_dive_site(d, get_dive_site_by_uuid(uuid, state->log->sites));
|
||||
add_dive_to_dive_site(d, get_dive_site_by_uuid(uuid, *state->log->sites));
|
||||
}
|
||||
|
||||
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 = get_dive_site_by_name(buffer, state->log->sites);
|
||||
ds = get_dive_site_by_name(buffer, *state->log->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site(buffer, state->log->sites);
|
||||
ds = create_dive_site(buffer, *state->log->sites);
|
||||
add_dive_to_dive_site(d, ds);
|
||||
|
||||
// TODO: capture the country / city info in the taxonomy instead
|
||||
|
@ -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) {
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, *state->log->sites));
|
||||
} 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) {
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, state->log->sites));
|
||||
add_dive_to_dive_site(dive, create_dive_site_with_gps(std::string(), &location, *state->log->sites));
|
||||
} 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,
|
||||
|
@ -1197,14 +1197,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 = get_dive_site_by_gps_proximity(&location, 20, state->log->sites);
|
||||
ds = get_dive_site_by_gps_proximity(&location, 20, *state->log->sites);
|
||||
|
||||
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 = create_dive_site_with_gps(std::string(), &location, state->log->sites);
|
||||
ds = create_dive_site_with_gps(std::string(), &location, *state->log->sites);
|
||||
}
|
||||
add_dive_to_dive_site(dive, ds);
|
||||
} 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));
|
||||
add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported"s, &state.cur_location, state.log->sites));
|
||||
add_dive_to_dive_site(state.cur_dive, create_dive_site_with_gps("DLF imported"s, &state.cur_location, *state.log->sites));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue