core: add constructor/destructor pairs to dive and divecomputer

This allows us to use non-C member variables. Convert a number
of pointers to unique_ptr<>s.

Code in uemis-downloader.cpp had to be refactored, because
it mixed owning and non-owning pointers. Mad.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-05-16 20:11:21 +02:00 committed by bstoeger
parent bfb54aa581
commit cc39f709ce
35 changed files with 289 additions and 308 deletions

View file

@ -411,7 +411,7 @@ AddDive::AddDive(dive *d, bool autogroup, bool newNumber)
currentDive = nullptr;
// Get an owning pointer to a moved dive.
OwningDivePtr divePtr(move_dive(d));
std::unique_ptr<dive> divePtr = move_dive(d);
divePtr->selected = false; // If we clone a planned dive, it might have been selected.
// We have to clear the flag, as selections will be managed
// on dive-addition.
@ -494,7 +494,7 @@ ImportDives::ImportDives(struct divelog *log, int flags, const QString &source)
// Add dives to the divesToAdd.dives structure
divesToAdd.dives.reserve(dives_to_add.nr);
for (int i = 0; i < dives_to_add.nr; ++i) {
OwningDivePtr divePtr(dives_to_add.dives[i]);
std::unique_ptr<dive> divePtr(dives_to_add.dives[i]);
divePtr->selected = false; // See above in AddDive::AddDive()
dive_trip *trip = divePtr->divetrip;
divePtr->divetrip = nullptr; // See above in AddDive::AddDive()
@ -971,7 +971,7 @@ MergeDives::MergeDives(const QVector <dive *> &dives)
dive_trip *preferred_trip;
dive_site *preferred_site;
OwningDivePtr d(merge_dives(dives[0], dives[1], dives[1]->when - dives[0]->when, false, &preferred_trip, &preferred_site));
std::unique_ptr<dive> d(merge_dives(dives[0], dives[1], dives[1]->when - dives[0]->when, false, &preferred_trip, &preferred_site));
// Currently, the core code selects the dive -> this is not what we want, as
// we manually manage the selection post-command.

View file

@ -15,9 +15,9 @@ namespace Command {
// This helper structure describes a dive that we want to add.
struct DiveToAdd {
OwningDivePtr dive; // Dive to add
dive_trip *trip; // Trip the dive belongs to, may be null
dive_site *site; // Site the dive is associated with, may be null
std::unique_ptr<struct dive> dive; // Dive to add
dive_trip *trip; // Trip the dive belongs to, may be null
dive_site *site; // Site the dive is associated with, may be null
};
// Multiple trips, dives and dive sites that have to be added for a command

View file

@ -797,7 +797,6 @@ ReplanDive::ReplanDive(dive *source) : d(current_dive),
when(0),
maxdepth({0}),
meandepth({0}),
dc({ 0 }),
notes(nullptr),
surface_pressure({0}),
duration({0}),
@ -885,8 +884,7 @@ EditProfile::EditProfile(const dive *source, int dcNr, EditProfileType type, int
maxdepth({0}),
meandepth({0}),
dcmaxdepth({0}),
duration({0}),
dc({ 0 })
duration({0})
{
const struct divecomputer *sdc = get_dive_dc_const(source, dcNr);
if (!sdc)

View file

@ -465,7 +465,7 @@ public:
EditDive(dive *oldDive, dive *newDive, dive_site *createDs, dive_site *editDs, location_t dsLocation); // Takes ownership of newDive
private:
dive *oldDive; // Dive that is going to be overwritten
OwningDivePtr newDive; // New data
std::unique_ptr<dive> newDive; // New data
dive_site *newDiveSite;
int changedFields;