2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2011-09-05 19:12:58 +00:00
|
|
|
#ifndef DIVELIST_H
|
|
|
|
#define DIVELIST_H
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
#include "triptable.h"
|
|
|
|
#include "divesitetable.h"
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "units.h"
|
2024-06-04 11:52:48 +00:00
|
|
|
#include <memory>
|
2024-09-01 12:12:05 +00:00
|
|
|
#include <optional>
|
2019-03-04 22:20:29 +00:00
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
struct dive;
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct divelog;
|
2024-05-31 05:08:54 +00:00
|
|
|
struct device;
|
2019-08-05 18:43:06 +00:00
|
|
|
struct deco_state;
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
int comp_dives(const struct dive &a, const struct dive &b);
|
|
|
|
int comp_dives_ptr(const struct dive *a, const struct dive *b);
|
|
|
|
|
2024-06-24 18:47:02 +00:00
|
|
|
struct merge_result {
|
|
|
|
std::unique_ptr<struct dive> dive;
|
2024-09-01 12:12:05 +00:00
|
|
|
std::optional<location_t> set_location; // change location of dive site
|
2024-06-24 18:47:02 +00:00
|
|
|
};
|
|
|
|
|
2024-06-07 08:25:09 +00:00
|
|
|
struct dive_table : public sorted_owning_table<dive, &comp_dives> {
|
|
|
|
dive *get_by_uniq_id(int id) const;
|
|
|
|
void record_dive(std::unique_ptr<dive> d); // call fixup_dive() before adding dive to table.
|
2024-06-18 19:19:14 +00:00
|
|
|
struct dive *register_dive(std::unique_ptr<dive> d);
|
2024-06-07 08:25:09 +00:00
|
|
|
std::unique_ptr<dive> unregister_dive(int idx);
|
2024-06-23 12:20:59 +00:00
|
|
|
std::unique_ptr<dive> default_dive(); // generate a sensible looking defaultdive 1h from now.
|
2024-06-18 18:57:10 +00:00
|
|
|
|
2024-06-23 12:20:59 +00:00
|
|
|
// Some of these functions act on dives, but need data from adjacent dives,
|
|
|
|
// notably to calculate CNS, surface interval, etc. Therefore, they are called
|
|
|
|
// on the dive_table and not on the dive.
|
|
|
|
void fixup_dive(struct dive &dive) const;
|
|
|
|
void force_fixup_dive(struct dive &d) const;
|
2024-06-18 20:23:57 +00:00
|
|
|
int init_decompression(struct deco_state *ds, const struct dive *dive, bool in_planner) const;
|
2024-06-23 12:20:59 +00:00
|
|
|
void update_cylinder_related_info(struct dive &dive) const;
|
2024-06-18 19:07:58 +00:00
|
|
|
int get_dive_nr_at_idx(int idx) const;
|
2024-06-18 19:01:16 +00:00
|
|
|
timestamp_t get_surface_interval(timestamp_t when) const;
|
2024-06-18 18:57:10 +00:00
|
|
|
struct dive *find_next_visible_dive(timestamp_t when);
|
2024-06-24 17:17:43 +00:00
|
|
|
std::array<std::unique_ptr<dive>, 2> split_divecomputer(const struct dive &src, int num) const;
|
|
|
|
std::array<std::unique_ptr<dive>, 2> split_dive(const struct dive &dive) const;
|
|
|
|
std::array<std::unique_ptr<dive>, 2> split_dive_at_time(const struct dive &dive, duration_t time) const;
|
2024-09-01 12:12:05 +00:00
|
|
|
merge_result merge_dives(const std::vector<dive *> &dives) const;
|
2024-06-24 18:47:02 +00:00
|
|
|
std::unique_ptr<dive> try_to_merge(const struct dive &a, const struct dive &b, bool prefer_downloaded) const;
|
2024-06-25 12:40:51 +00:00
|
|
|
bool has_dive(unsigned int deviceid, unsigned int diveid) const;
|
2024-06-25 12:45:33 +00:00
|
|
|
std::unique_ptr<dive> clone_delete_divecomputer(const struct dive &d, int dc_number);
|
2024-06-18 20:23:57 +00:00
|
|
|
private:
|
2024-06-23 12:20:59 +00:00
|
|
|
int calculate_cns(struct dive &dive) const; // Note: writes into dive->cns
|
2024-06-24 17:17:43 +00:00
|
|
|
std::array<std::unique_ptr<dive>, 2> split_dive_at(const struct dive &dive, int a, int b) const;
|
2024-09-01 12:12:05 +00:00
|
|
|
std::unique_ptr<dive> merge_two_dives(const struct dive &a_in, const struct dive &b_in, int offset, bool prefer_downloaded) const;
|
2020-05-01 11:43:52 +00:00
|
|
|
};
|
|
|
|
|
2015-07-24 20:18:30 +00:00
|
|
|
void clear_dive_file_data();
|
2015-06-20 13:45:12 +00:00
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVELIST_H
|