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-05-31 05:08:54 +00:00
|
|
|
#include <vector>
|
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);
|
|
|
|
|
|
|
|
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-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
|
2020-05-01 11:43:52 +00:00
|
|
|
};
|
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
/* this is used for both git and xml format */
|
|
|
|
#define DATAFORMAT_VERSION 3
|
|
|
|
|
2018-10-13 20:32:53 +00:00
|
|
|
extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
|
2019-05-31 14:09:14 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
int get_min_datafile_version();
|
|
|
|
void report_datafile_version(int version);
|
2015-07-24 20:18:30 +00:00
|
|
|
void clear_dive_file_data();
|
2021-10-30 19:39:36 +00:00
|
|
|
extern bool has_dive(unsigned int deviceid, unsigned int diveid);
|
2015-06-20 13:45:12 +00:00
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // DIVELIST_H
|