core: move has_dive() function into struct divelist

Seems natural in a C++ code base.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-06-25 14:40:51 +02:00 committed by bstoeger
parent 60c7b503cf
commit 576d3a3bc6
4 changed files with 5 additions and 5 deletions

View file

@ -147,7 +147,7 @@ std::pair<int, const unsigned char *> 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 };

View file

@ -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;
});

View file

@ -43,12 +43,12 @@ struct dive_table : public sorted_owning_table<dive, &comp_dives> {
std::array<std::unique_ptr<dive>, 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<dive> 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<std::unique_ptr<dive>, 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

View file

@ -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;