mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn string data in struct divecomputer into std::string
Simplifies memory management. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
cc39f709ce
commit
b9a2eff3c9
28 changed files with 114 additions and 147 deletions
|
@ -181,14 +181,11 @@ static void copy_extra_data(struct extra_data *sed, struct extra_data *ded)
|
|||
ded->value = copy_string(sed->value);
|
||||
}
|
||||
|
||||
/* this is very different from the copy_divecomputer later in this file;
|
||||
/* this is very different from the copy_dive_computer later in this file;
|
||||
* this function actually makes full copies of the content */
|
||||
static void copy_dc(const struct divecomputer *sdc, struct divecomputer *ddc)
|
||||
{
|
||||
*ddc = *sdc;
|
||||
ddc->model = copy_string(sdc->model);
|
||||
ddc->serial = copy_string(sdc->serial);
|
||||
ddc->fw_version = copy_string(sdc->fw_version);
|
||||
copy_samples(sdc, ddc);
|
||||
copy_events(sdc, ddc);
|
||||
STRUCTURED_LIST_COPY(struct extra_data, sdc->extra_data, ddc->extra_data, copy_extra_data);
|
||||
|
@ -616,9 +613,9 @@ void update_setpoint_events(const struct dive *dive, struct divecomputer *dc)
|
|||
new_setpoint = prefs.defaultsetpoint;
|
||||
|
||||
if (dc->divemode == OC &&
|
||||
(same_string(dc->model, "Shearwater Predator") ||
|
||||
same_string(dc->model, "Shearwater Petrel") ||
|
||||
same_string(dc->model, "Shearwater Nerd"))) {
|
||||
(dc->model == "Shearwater Predator" ||
|
||||
dc->model == "Shearwater Petrel" ||
|
||||
dc->model == "Shearwater Nerd")) {
|
||||
// make sure there's no setpoint in the samples
|
||||
// this is an irreversible change - so switching a dive to OC
|
||||
// by mistake when it's actually CCR is _bad_
|
||||
|
@ -2399,11 +2396,11 @@ static int same_dc(struct divecomputer *a, struct divecomputer *b)
|
|||
static int might_be_same_device(const struct divecomputer *a, const struct divecomputer *b)
|
||||
{
|
||||
/* No dive computer model? That matches anything */
|
||||
if (!a->model || !b->model)
|
||||
if (a->model.empty() || b->model.empty())
|
||||
return 1;
|
||||
|
||||
/* Otherwise at least the model names have to match */
|
||||
if (strcasecmp(a->model, b->model))
|
||||
if (strcasecmp(a->model.c_str(), b->model.c_str()))
|
||||
return 0;
|
||||
|
||||
/* No device ID? Match */
|
||||
|
@ -2452,9 +2449,6 @@ static const struct divecomputer *find_matching_computer(const struct divecomput
|
|||
static void copy_dive_computer(struct divecomputer *res, const struct divecomputer *a)
|
||||
{
|
||||
*res = *a;
|
||||
res->model = copy_string(a->model);
|
||||
res->serial = copy_string(a->serial);
|
||||
res->fw_version = copy_string(a->fw_version);
|
||||
STRUCTURED_LIST_COPY(struct extra_data, a->extra_data, res->extra_data, copy_extra_data);
|
||||
res->samples = res->alloc_samples = 0;
|
||||
res->sample = NULL;
|
||||
|
@ -2520,11 +2514,11 @@ static void join_dive_computers(struct dive *d, struct divecomputer *res,
|
|||
{
|
||||
struct divecomputer *tmp;
|
||||
|
||||
if (a->model && !b->model) {
|
||||
if (!a->model.empty() && b->model.empty()) {
|
||||
copy_dc_renumber(d, a, res, cylinders_map_a);
|
||||
return;
|
||||
}
|
||||
if (b->model && !a->model) {
|
||||
if (!b->model.empty() && a->model.empty()) {
|
||||
copy_dc_renumber(d, b, res, cylinders_map_b);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue