core: move clone_delete_divecomputer() to struct dive_table

Since this calls force_fixup_dive() it needs access to other dives
in the dive_table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-25 14:45:33 +02:00 committed by bstoeger
parent 576d3a3bc6
commit 79bf79ad7f
5 changed files with 25 additions and 26 deletions

View file

@ -1219,3 +1219,25 @@ struct std::unique_ptr<dive> dive_table::try_to_merge(const struct dive &a, cons
res->dive_site = site; /* Caller has to call site->add_dive()! */
return std::move(res);
}
/* Clone a dive and delete given dive computer */
std::unique_ptr<dive> dive_table::clone_delete_divecomputer(const struct dive &d, int dc_number)
{
/* copy the dive */
auto res = std::make_unique<dive>(d);
/* make a new unique id, since we still can't handle two equal ids */
res->id = dive_getUniqID();
if (res->dcs.size() <= 1)
return res;
if (dc_number < 0 || static_cast<size_t>(dc_number) >= res->dcs.size())
return res;
res->dcs.erase(res->dcs.begin() + dc_number);
force_fixup_dive(*res);
return res;
}