divelog: turn owning-pointers into unique_ptr<>s

Since everything is C++ now, we can use unique_ptr<>s. This makes
the code significantly shorter, because we can now use the default
move constructor and assignment operators.

This has a semantic change when std::move()-ing the divelog:
now not the contents of the tables are moved, but the pointers.
That is, the moved-from object now has no more tables and
must not be used anymore. This made it necessary to replace
std::move()s by std::swap()s. In that regard, the old code was
in principle broken: it used moved-from objects, which may work
but usually doesn't.

This commit adds a myriad of .get() function calls where the code
expects a C-style pointer. The plan is to remove virtually all of
them, when we move free-standing functions into the class it acts
on. Or, replace C-style pointers by references where we don't support
NULL.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-13 19:34:43 +02:00 committed by bstoeger
parent 6e352d5281
commit d242198c99
22 changed files with 113 additions and 138 deletions

View file

@ -178,7 +178,7 @@ void dc_settings_start(struct parser_state *state)
void dc_settings_end(struct parser_state *state)
{
create_device_node(state->log->devices,
create_device_node(state->log->devices.get(),
state->cur_settings.dc.model.c_str(),
state->cur_settings.dc.serial_nr.c_str(),
state->cur_settings.dc.nickname.c_str());
@ -217,7 +217,7 @@ void filter_preset_start(struct parser_state *state)
void filter_preset_end(struct parser_state *state)
{
add_filter_preset_to_table(state->cur_filter.get(), state->log->filter_presets);
add_filter_preset_to_table(state->cur_filter.get(), state->log->filter_presets.get());
state->cur_filter.reset();
}
@ -277,7 +277,7 @@ void dive_end(struct parser_state *state)
if (!is_dive(state)) {
free_dive(state->cur_dive);
} else {
record_dive_to_table(state->cur_dive, state->log->dives);
record_dive_to_table(state->cur_dive, state->log->dives.get());
if (state->cur_trip)
add_dive_to_trip(state->cur_dive, state->cur_trip);
}
@ -300,7 +300,7 @@ void trip_end(struct parser_state *state)
{
if (!state->cur_trip)
return;
insert_trip(state->cur_trip, state->log->trips);
insert_trip(state->cur_trip, state->log->trips.get());
state->cur_trip = NULL;
}