subsurface/core/divecomputer.h
Berthold Stoeger 27dbdd35c6 core: turn event-list of divecomputer into std::vector<>
This is a rather long commit, because it refactors lots of the event
code from pointer to value semantics: pointers to entries in an
std::vector<> are not stable, so better use indexes.

To step through the event-list at diven time stamps, add *_loop classes,
which encapsulate state that had to be manually handled before by
the caller. I'm not happy about the interface, but it tries to
mirror the one we had before.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2024-08-13 19:28:30 +02:00

78 lines
3.3 KiB
C++

// SPDX-License-Identifier: GPL-2.0
#ifndef DIVECOMPUTER_H
#define DIVECOMPUTER_H
#include "divemode.h"
#include "units.h"
#include <string>
#include <vector>
struct extra_data;
struct event;
struct sample;
/* Is this header the correct place? */
#define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */
/*
* NOTE! The deviceid and diveid are model-specific *hashes* of
* whatever device identification that model may have. Different
* dive computers will have different identifying data, it could
* be a firmware number or a serial ID (in either string or in
* numeric format), and we do not care.
*
* The only thing we care about is that subsurface will hash
* that information the same way. So then you can check the ID
* of a dive computer by comparing the hashes for equality.
*
* A deviceid or diveid of zero is assumed to be "no ID".
*/
struct divecomputer {
timestamp_t when = 0;
duration_t duration, surfacetime, last_manual_time;
depth_t maxdepth, meandepth;
temperature_t airtemp, watertemp;
pressure_t surface_pressure;
enum divemode_t divemode = OC; // dive computer type: OC(default) or CCR
uint8_t no_o2sensors = 0; // rebreathers: number of O2 sensors used
int salinity = 0; // kg per 10000 l
std::string model, serial, fw_version;
uint32_t deviceid = 0, diveid = 0;
// Note: ve store samples, events and extra_data in std::vector<>s.
// This means that pointers to these items are *not* stable.
std::vector<struct sample> samples;
std::vector<struct event> events;
std::vector<struct extra_data> extra_data;
struct divecomputer *next = nullptr;
divecomputer();
~divecomputer();
divecomputer(divecomputer &&);
divecomputer &operator=(const divecomputer &);
};
extern void fake_dc(struct divecomputer *dc);
extern void free_dc_contents(struct divecomputer *dc);
extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time);
extern void free_dive_dcs(struct divecomputer *dc);
extern struct sample *prepare_sample(struct divecomputer *dc);
extern struct sample *add_sample(const struct sample *sample, int time, struct divecomputer *dc);
extern void fixup_dc_duration(struct divecomputer *dc);
extern unsigned int dc_airtemp(const struct divecomputer *dc);
extern unsigned int dc_watertemp(const struct divecomputer *dc);
extern int add_event_to_dc(struct divecomputer *dc, struct event ev); // event structure is consumed, returns index of inserted event
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const std::string &name);
extern struct event remove_event_from_dc(struct divecomputer *dc, int idx);
struct event *get_event(struct divecomputer *dc, int idx);
extern void add_extra_data(struct divecomputer *dc, const std::string &key, const std::string &value);
extern uint32_t calculate_string_hash(const char *str);
extern bool is_dc_planner(const struct divecomputer *dc);
extern void make_planner_dc(struct divecomputer *dc);
extern const char *manual_dc_name;
extern bool is_dc_manually_added_dive(const struct divecomputer *dc);
extern void make_manually_added_dive_dc(struct divecomputer *dc);
/* Check if two dive computer entries are the exact same dive (-1=no/0=maybe/1=yes) */
extern int match_one_dc(const struct divecomputer *a, const struct divecomputer *b);
#endif