From 576d3a3bc64457e3593ef77cef10a816339fec96 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 25 Jun 2024 14:40:51 +0200 Subject: [PATCH] core: move has_dive() function into struct divelist Seems natural in a C++ code base. Signed-off-by: Berthold Stoeger --- core/device.cpp | 2 +- core/divelist.cpp | 4 ++-- core/divelist.h | 2 +- core/libdivecomputer.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index c49e2dd5f..1bc2183ee 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -147,7 +147,7 @@ std::pair get_fingerprint_data(const fingerprint_tab if (it != table.end() && it->model == model && it->serial == serial) { // std::lower_bound gets us the first element that isn't smaller than what we are looking // for - so if one is found, we still need to check for equality - if (has_dive(it->fdeviceid, it->fdiveid)) + if (divelog.dives.has_dive(it->fdeviceid, it->fdiveid)) return { it->fsize, it->raw_data.get() }; } return { 0, nullptr }; diff --git a/core/divelist.cpp b/core/divelist.cpp index 0cad7f3bd..a48064cb0 100644 --- a/core/divelist.cpp +++ b/core/divelist.cpp @@ -881,9 +881,9 @@ struct dive *dive_table::find_next_visible_dive(timestamp_t when) return nullptr; } -bool has_dive(unsigned int deviceid, unsigned int diveid) +bool dive_table::has_dive(unsigned int deviceid, unsigned int diveid) const { - return std::any_of(divelog.dives.begin(), divelog.dives.end(), [deviceid,diveid] (auto &d) { + return std::any_of(begin(), end(), [deviceid,diveid] (auto &d) { return std::any_of(d->dcs.begin(), d->dcs.end(), [deviceid,diveid] (auto &dc) { return dc.deviceid == deviceid && dc.diveid == diveid; }); diff --git a/core/divelist.h b/core/divelist.h index 4f4994f62..235f7c9b0 100644 --- a/core/divelist.h +++ b/core/divelist.h @@ -43,12 +43,12 @@ struct dive_table : public sorted_owning_table { std::array, 2> split_dive_at_time(const struct dive &dive, duration_t time) const; merge_result merge_dives(const struct dive &a_in, const struct dive &b_in, int offset, bool prefer_downloaded) const; std::unique_ptr try_to_merge(const struct dive &a, const struct dive &b, bool prefer_downloaded) const; + bool has_dive(unsigned int deviceid, unsigned int diveid) const; private: int calculate_cns(struct dive &dive) const; // Note: writes into dive->cns std::array, 2> split_dive_at(const struct dive &dive, int a, int b) const; }; void clear_dive_file_data(); -extern bool has_dive(unsigned int deviceid, unsigned int diveid); #endif // DIVELIST_H diff --git a/core/libdivecomputer.cpp b/core/libdivecomputer.cpp index 77004d76a..408923b3f 100644 --- a/core/libdivecomputer.cpp +++ b/core/libdivecomputer.cpp @@ -983,7 +983,7 @@ static void verify_fingerprint(dc_device_t *device, device_data_t *devdata, cons if (verbose) dev_info(" ... fingerprinted dive %08x:%08x", deviceid, diveid); /* Only use it if we *have* that dive! */ - if (!has_dive(deviceid, diveid)) { + if (!divelog.dives.has_dive(deviceid, diveid)) { if (verbose) dev_info(" ... dive not found"); return;