diff --git a/core/dive.cpp b/core/dive.cpp index fbe080fe5..a6fdfe6cd 100644 --- a/core/dive.cpp +++ b/core/dive.cpp @@ -969,7 +969,7 @@ static void fixup_dc_depths(struct dive *dive, struct divecomputer *dc) } update_depth(&dc->maxdepth, maxdepth); - if (!has_planned(dive, false) || !is_dc_planner(dc)) + if (!is_logged(dive) || !is_dc_planner(dc)) if (maxdepth > dive->maxdepth.mm) dive->maxdepth.mm = maxdepth; } @@ -2550,19 +2550,29 @@ static void join_dive_computers(struct dive *d, struct divecomputer *res, remove_redundant_dc(res, prefer_downloaded); } -// Does this dive have a dive computer for which is_dc_planner has value planned -extern "C" bool has_planned(const struct dive *dive, bool planned) +static bool has_dc_type(const struct dive *dive, bool dc_is_planner) { const struct divecomputer *dc = &dive->dc; while (dc) { - if (is_dc_planner(&dive->dc) == planned) + if (is_dc_planner(dc) == dc_is_planner) return true; dc = dc->next; } return false; } +// Does this dive have a dive computer for which is_dc_planner has value planned +extern "C" bool is_planned(const struct dive *dive) +{ + return has_dc_type(dive, true); +} + +extern "C" bool is_logged(const struct dive *dive) +{ + return has_dc_type(dive, false); +} + /* * Merging two dives can be subtle, because there's two different ways * of merging: diff --git a/core/dive.h b/core/dive.h index b4ed2af1d..adc0fdb11 100644 --- a/core/dive.h +++ b/core/dive.h @@ -141,8 +141,7 @@ void split_divecomputer(const struct dive *src, int num, struct dive **out1, str for (_dc = &_dive->dc; _dc; _dc = _dc->next) #define for_each_relevant_dc(_dive, _dc) \ - bool _all_planned = !has_planned(_dive, false); \ - for (_dc = &_dive->dc; _dc; _dc = _dc->next) if (_all_planned || !is_dc_planner(_dc)) + for (_dc = &_dive->dc; _dc; _dc = _dc->next) if (!is_logged(_dive) || !is_dc_planner(_dc)) extern struct dive *get_dive_by_uniq_id(int id); extern int get_idx_by_uniq_id(int id); @@ -207,7 +206,8 @@ extern void invalidate_dive_cache(struct dive *dc); extern int total_weight(const struct dive *); -extern bool has_planned(const struct dive *dive, bool planned); +extern bool is_planned(const struct dive *dive); +extern bool is_logged(const struct dive *dive); /* Get gasmixes at increasing timestamps. * In "evp", pass a pointer to a "struct event *" which is NULL-initialized on first invocation. diff --git a/core/filterconstraint.cpp b/core/filterconstraint.cpp index 097adf4cb..487d1a1b1 100644 --- a/core/filterconstraint.cpp +++ b/core/filterconstraint.cpp @@ -1074,9 +1074,9 @@ bool filter_constraint_match_dive(const filter_constraint &c, const struct dive case FILTER_CONSTRAINT_SAC: return check_numerical_range_non_zero(c, d->sac); case FILTER_CONSTRAINT_LOGGED: - return has_planned(d, false) != c.negate; + return is_logged(d) != c.negate; case FILTER_CONSTRAINT_PLANNED: - return has_planned(d, true) != c.negate; + return is_planned(d) != c.negate; case FILTER_CONSTRAINT_DIVE_MODE: return check_multiple_choice(c, (int)d->dc.divemode); // should we be smarter and check all DCs? case FILTER_CONSTRAINT_TAGS: