Cleanup: const-ify functions taking pointers to events

This is another entry in the series to make more things
"const-clean" with the ultimate goal of merge_dive() take
const pointers.

This concerns functions taking pointers to events and
the fallout from making these const.

The somewhat debatable part of this commit might be
that get_next_event() is split in a two distinct
(const and non-const) versions with different names,
since C doesn't allow overloading. The linker should
recognize that these functions are identical and remove
one of them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-08-17 00:58:30 +02:00 committed by Dirk Hohndel
parent 44f34d8cd7
commit 605e1e19ed
15 changed files with 76 additions and 69 deletions

View file

@ -581,7 +581,7 @@ void restore_deco_state(struct deco_state *data, struct deco_state *target, bool
} }
int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, bool smooth) int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth)
{ {
int depth; int depth;
double pressure_delta; double pressure_delta;

View file

@ -8,7 +8,7 @@ extern "C" {
extern double buehlmann_N2_t_halflife[]; extern double buehlmann_N2_t_halflife[];
extern int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, bool smooth); extern int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth);
double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive); double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive);

View file

@ -130,7 +130,7 @@ int legacy_format_o2pressures(struct dive *dive, struct divecomputer *dc)
return o2sensor < 0 ? 256 : o2sensor; return o2sensor < 0 ? 256 : o2sensor;
} }
int event_is_gaschange(struct event *ev) int event_is_gaschange(const struct event *ev)
{ {
return ev->type == SAMPLE_EVENT_GASCHANGE || return ev->type == SAMPLE_EVENT_GASCHANGE ||
ev->type == SAMPLE_EVENT_GASCHANGE2; ev->type == SAMPLE_EVENT_GASCHANGE2;
@ -184,7 +184,7 @@ struct event *add_event(struct divecomputer *dc, unsigned int time, int type, in
return ev; return ev;
} }
static int same_event(struct event *a, struct event *b) static int same_event(const struct event *a, const struct event *b)
{ {
if (a->time.seconds != b->time.seconds) if (a->time.seconds != b->time.seconds)
return 0; return 0;
@ -255,9 +255,9 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
* saving the dive mode for each event. When the events occur AFTER 'time' seconds, the last stored divemode * saving the dive mode for each event. When the events occur AFTER 'time' seconds, the last stored divemode
* is returned. This function is self-tracking, relying on setting the event pointer 'evp' so that, in each iteration * is returned. This function is self-tracking, relying on setting the event pointer 'evp' so that, in each iteration
* that calls this function, the search does not have to begin at the first event of the dive */ * that calls this function, the search does not have to begin at the first event of the dive */
enum divemode_t get_current_divemode(struct divecomputer *dc, int time, struct event **evp, enum divemode_t *divemode) enum divemode_t get_current_divemode(const struct divecomputer *dc, int time, const struct event **evp, enum divemode_t *divemode)
{ {
struct event *ev = *evp; const struct event *ev = *evp;
if (*divemode == UNDEF_COMP_TYPE) { if (*divemode == UNDEF_COMP_TYPE) {
*divemode = dc->divemode; *divemode = dc->divemode;
ev = dc ? get_next_event(dc->events, "modechange") : NULL; ev = dc ? get_next_event(dc->events, "modechange") : NULL;
@ -270,7 +270,7 @@ enum divemode_t get_current_divemode(struct divecomputer *dc, int time, struct e
return *divemode; return *divemode;
} }
struct gasmix get_gasmix_from_event(struct dive *dive, struct event *ev) struct gasmix get_gasmix_from_event(const struct dive *dive, const struct event *ev)
{ {
struct gasmix dummy = { 0 }; struct gasmix dummy = { 0 };
if (ev && event_is_gaschange(ev)) { if (ev && event_is_gaschange(ev)) {
@ -901,7 +901,7 @@ static unsigned int get_cylinder_used(struct dive *dive)
static unsigned int get_cylinder_known(struct dive *dive, struct divecomputer *dc) static unsigned int get_cylinder_known(struct dive *dive, struct divecomputer *dc)
{ {
unsigned int mask = 0; unsigned int mask = 0;
struct event *ev; const struct event *ev;
/* We know about using the O2 cylinder in a CCR dive */ /* We know about using the O2 cylinder in a CCR dive */
if (dc->divemode == CCR) { if (dc->divemode == CCR) {
@ -973,7 +973,7 @@ void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *me
} }
if (!dc->samples) if (!dc->samples)
fake_dc(dc); fake_dc(dc);
struct event *ev = get_next_event(dc->events, "gaschange"); const struct event *ev = get_next_event(dc->events, "gaschange");
for (i = 0; i < dc->samples; i++) { for (i = 0; i < dc->samples; i++) {
struct sample *sample = dc->sample + i; struct sample *sample = dc->sample + i;
uint32_t time = sample->time.seconds; uint32_t time = sample->time.seconds;
@ -1039,10 +1039,10 @@ static int same_rounded_pressure(pressure_t a, pressure_t b)
* tell us what the first gas is with a gas change event in the first sample. * tell us what the first gas is with a gas change event in the first sample.
* Sneakily we'll use a return value of 0 (or FALSE) when there is no explicit * Sneakily we'll use a return value of 0 (or FALSE) when there is no explicit
* first cylinder - in which case cylinder 0 is indeed the first cylinder */ * first cylinder - in which case cylinder 0 is indeed the first cylinder */
int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc) int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc)
{ {
if (dc) { if (dc) {
struct event *ev = get_next_event(dc->events, "gaschange"); const struct event *ev = get_next_event(dc->events, "gaschange");
if (ev && ((dc->sample && ev->time.seconds == dc->sample[0].time.seconds) || ev->time.seconds <= 1)) if (ev && ((dc->sample && ev->time.seconds == dc->sample[0].time.seconds) || ev->time.seconds <= 1))
return get_cylinder_index(dive, ev); return get_cylinder_index(dive, ev);
else if (dc->divemode == CCR) else if (dc->divemode == CCR)
@ -1054,7 +1054,7 @@ int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc)
/* this gets called when the dive mode has changed (so OC vs. CC) /* this gets called when the dive mode has changed (so OC vs. CC)
* there are two places we might have setpoints... events or in the samples * there are two places we might have setpoints... events or in the samples
*/ */
void update_setpoint_events(struct dive *dive, struct divecomputer *dc) void update_setpoint_events(const struct dive *dive, struct divecomputer *dc)
{ {
struct event *ev; struct event *ev;
int new_setpoint = 0; int new_setpoint = 0;
@ -1071,9 +1071,9 @@ void update_setpoint_events(struct dive *dive, struct divecomputer *dc)
// by mistake when it's actually CCR is _bad_ // by mistake when it's actually CCR is _bad_
// So we make sure, this comes from a Predator or Petrel and we only remove // So we make sure, this comes from a Predator or Petrel and we only remove
// pO2 values we would have computed anyway. // pO2 values we would have computed anyway.
struct event *ev = get_next_event(dc->events, "gaschange"); const struct event *ev = get_next_event(dc->events, "gaschange");
struct gasmix gasmix = get_gasmix_from_event(dive, ev); struct gasmix gasmix = get_gasmix_from_event(dive, ev);
struct event *next = get_next_event(ev, "gaschange"); const struct event *next = get_next_event(ev, "gaschange");
for (int i = 0; i < dc->samples; i++) { for (int i = 0; i < dc->samples; i++) {
struct gas_pressures pressures; struct gas_pressures pressures;
@ -1091,7 +1091,7 @@ void update_setpoint_events(struct dive *dive, struct divecomputer *dc)
// an "SP change" event at t=0 is currently our marker for OC vs CCR // an "SP change" event at t=0 is currently our marker for OC vs CCR
// this will need to change to a saner setup, but for now we can just // this will need to change to a saner setup, but for now we can just
// check if such an event is there and adjust it, or add that event // check if such an event is there and adjust it, or add that event
ev = get_next_event(dc->events, "SP change"); ev = get_next_event_mutable(dc->events, "SP change");
if (ev && ev->time.seconds == 0) { if (ev && ev->time.seconds == 0) {
ev->value = new_setpoint; ev->value = new_setpoint;
} else { } else {
@ -1241,7 +1241,7 @@ bool isobaric_counterdiffusion(struct gasmix oldgasmix, struct gasmix newgasmix,
} }
/* some events should never be thrown away */ /* some events should never be thrown away */
static bool is_potentially_redundant(struct event *event) static bool is_potentially_redundant(const struct event *event)
{ {
if (!strcmp(event->name, "gaschange")) if (!strcmp(event->name, "gaschange"))
return false; return false;
@ -1608,7 +1608,7 @@ static void fixup_dive_pressures(struct dive *dive, struct divecomputer *dc)
simplify_dc_pressures(dc); simplify_dc_pressures(dc);
} }
int find_best_gasmix_match(struct gasmix mix, cylinder_t array[], unsigned int used) int find_best_gasmix_match(struct gasmix mix, const cylinder_t array[], unsigned int used)
{ {
int i; int i;
int best = -1, score = INT_MAX; int best = -1, score = INT_MAX;
@ -1968,7 +1968,7 @@ static char *merge_text(const char *a, const char *b, const char *sep)
if (a->field != b->field) \ if (a->field != b->field) \
return a->field < b->field ? -1 : 1 return a->field < b->field ? -1 : 1
static int sort_event(struct event *a, struct event *b) static int sort_event(const struct event *a, const struct event *b)
{ {
SORT(a, b, time.seconds); SORT(a, b, time.seconds);
SORT(a, b, type); SORT(a, b, type);
@ -1977,7 +1977,7 @@ static int sort_event(struct event *a, struct event *b)
return strcmp(a->name, b->name); return strcmp(a->name, b->name);
} }
static int same_gas(struct event *a, struct event *b) static int same_gas(const struct event *a, const struct event *b)
{ {
if (a->type == b->type && a->flags == b->flags && a->value == b->value && !strcmp(a->name, b->name) && if (a->type == b->type && a->flags == b->flags && a->value == b->value && !strcmp(a->name, b->name) &&
same_gasmix(a->gas.mix, b->gas.mix)) { same_gasmix(a->gas.mix, b->gas.mix)) {
@ -2068,7 +2068,7 @@ static void merge_weightsystem_info(weightsystem_t *res, weightsystem_t *a, weig
* A negative number returned indicates that a match could not be found. * A negative number returned indicates that a match could not be found.
* Call parameters: dive = the dive being processed * Call parameters: dive = the dive being processed
* cylinder_use_type = an enum, one of {oxygen, diluent, bailout} */ * cylinder_use_type = an enum, one of {oxygen, diluent, bailout} */
extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type) extern int get_cylinder_idx_by_use(const struct dive *dive, enum cylinderuse cylinder_use_type)
{ {
int cylinder_index; int cylinder_index;
for (cylinder_index = 0; cylinder_index < MAX_CYLINDERS; cylinder_index++) { for (cylinder_index = 0; cylinder_index < MAX_CYLINDERS; cylinder_index++) {
@ -2137,7 +2137,7 @@ extern void fill_pressures(struct gas_pressures *pressures, const double amb_pre
/* Force an initial gaschange event to the (old) gas #0 */ /* Force an initial gaschange event to the (old) gas #0 */
static void add_initial_gaschange(struct dive *dive, struct divecomputer *dc) static void add_initial_gaschange(struct dive *dive, struct divecomputer *dc)
{ {
struct event *ev = get_next_event(dc->events, "gaschange"); const struct event *ev = get_next_event(dc->events, "gaschange");
if (ev && ev->time.seconds < 30) if (ev && ev->time.seconds < 30)
return; return;
@ -2874,7 +2874,7 @@ static int same_sample(struct sample *a, struct sample *b)
static int same_dc(struct divecomputer *a, struct divecomputer *b) static int same_dc(struct divecomputer *a, struct divecomputer *b)
{ {
int i; int i;
struct event *eva, *evb; const struct event *eva, *evb;
i = match_one_dc(a, b); i = match_one_dc(a, b);
if (i) if (i)
@ -4287,9 +4287,9 @@ int dive_has_gps_location(const struct dive *dive)
return dive_site_has_gps_location(get_dive_site_by_uuid(dive->dive_site_uuid)); return dive_site_has_gps_location(get_dive_site_by_uuid(dive->dive_site_uuid));
} }
struct gasmix get_gasmix(struct dive *dive, struct divecomputer *dc, int time, struct event **evp, struct gasmix gasmix) struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc, int time, const struct event **evp, struct gasmix gasmix)
{ {
struct event *ev = *evp; const struct event *ev = *evp;
struct gasmix res; struct gasmix res;
if (!ev) { if (!ev) {
@ -4310,9 +4310,9 @@ struct gasmix get_gasmix(struct dive *dive, struct divecomputer *dc, int time, s
} }
/* get the gas at a certain time during the dive */ /* get the gas at a certain time during the dive */
struct gasmix get_gasmix_at_time(struct dive *d, struct divecomputer *dc, duration_t time) struct gasmix get_gasmix_at_time(const struct dive *d, const struct divecomputer *dc, duration_t time)
{ {
struct event *ev = NULL; const struct event *ev = NULL;
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
return get_gasmix(d, dc, time.seconds, &ev, gasmix); return get_gasmix(d, dc, time.seconds, &ev, gasmix);
} }

View file

@ -100,7 +100,7 @@ struct event {
char name[]; char name[];
}; };
extern int event_is_gaschange(struct event *ev); extern int event_is_gaschange(const struct event *ev);
extern int get_pressure_units(int mb, const char **units); extern int get_pressure_units(int mb, const char **units);
extern double get_depth_units(int mm, int *frac, const char **units); extern double get_depth_units(int mm, int *frac, const char **units);
@ -137,7 +137,7 @@ extern void fill_pressures(struct gas_pressures *pressures, const double amb_pre
extern void sanitize_gasmix(struct gasmix *mix); extern void sanitize_gasmix(struct gasmix *mix);
extern int gasmix_distance(struct gasmix a, struct gasmix b); extern int gasmix_distance(struct gasmix a, struct gasmix b);
extern int find_best_gasmix_match(struct gasmix mix, cylinder_t array[], unsigned int used); extern int find_best_gasmix_match(struct gasmix mix, const cylinder_t array[], unsigned int used);
extern bool gasmix_is_air(struct gasmix gasmix); extern bool gasmix_is_air(struct gasmix gasmix);
@ -334,7 +334,7 @@ struct dive {
extern void invalidate_dive_cache(struct dive *dive); extern void invalidate_dive_cache(struct dive *dive);
extern bool dive_cache_is_valid(const struct dive *dive); extern bool dive_cache_is_valid(const struct dive *dive);
extern int get_cylinder_idx_by_use(struct dive *dive, enum cylinderuse cylinder_use_type); extern int get_cylinder_idx_by_use(const struct dive *dive, enum cylinderuse cylinder_use_type);
extern void cylinder_renumber(struct dive *dive, int mapping[]); extern void cylinder_renumber(struct dive *dive, int mapping[]);
extern int same_gasmix_cylinder(cylinder_t *cyl, int cylid, struct dive *dive, bool check_unused); extern int same_gasmix_cylinder(cylinder_t *cyl, int cylid, struct dive *dive, bool check_unused);
@ -352,9 +352,9 @@ struct dive_components {
unsigned int weights : 1; unsigned int weights : 1;
}; };
extern enum divemode_t get_current_divemode(struct divecomputer *dc, int time, struct event **evp, enum divemode_t *divemode); extern enum divemode_t get_current_divemode(const struct divecomputer *dc, int time, const struct event **evp, enum divemode_t *divemode);
extern struct event *get_next_divemodechange(struct event **evd, bool update_pointer); extern struct event *get_next_divemodechange(const struct event **evd, bool update_pointer);
extern enum divemode_t get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc); extern enum divemode_t get_divemode_at_time(const struct divecomputer *dc, int dtime, const struct event **ev_dmc);
/* picture list and methods related to dive picture handling */ /* picture list and methods related to dive picture handling */
struct picture { struct picture {
@ -382,8 +382,8 @@ extern bool picture_check_valid(const char *filename, int shift_time);
extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic); extern void dive_set_geodata_from_picture(struct dive *d, struct picture *pic);
extern void picture_free(struct picture *picture); extern void picture_free(struct picture *picture);
extern bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx); extern bool has_gaschange_event(const struct dive *dive, const struct divecomputer *dc, int idx);
extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc); extern int explicit_first_cylinder(const struct dive *dive, const struct divecomputer *dc);
extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time); extern int get_depth_at_time(const struct divecomputer *dc, unsigned int time);
extern fraction_t best_o2(depth_t depth, const struct dive *dive); extern fraction_t best_o2(depth_t depth, const struct dive *dive);
@ -581,11 +581,11 @@ extern void fill_default_cylinder(cylinder_t *cyl);
extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx); extern void add_gas_switch_event(struct dive *dive, struct divecomputer *dc, int time, int idx);
extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name); extern struct event *add_event(struct divecomputer *dc, unsigned int time, int type, int flags, int value, const char *name);
extern void remove_event(struct event *event); extern void remove_event(struct event *event);
extern void update_event_name(struct dive *d, struct event* event, const char *name); extern void update_event_name(struct dive *d, struct event *event, const char *name);
extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value); extern void add_extra_data(struct divecomputer *dc, const char *key, const char *value);
extern void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration); extern void per_cylinder_mean_depth(struct dive *dive, struct divecomputer *dc, int *mean, int *duration);
extern int get_cylinder_index(struct dive *dive, struct event *ev); extern int get_cylinder_index(const struct dive *dive, const struct event *ev);
extern struct gasmix get_gasmix_from_event(struct dive *, struct event *ev); extern struct gasmix get_gasmix_from_event(const struct dive *, const struct event *ev);
extern int nr_cylinders(struct dive *dive); extern int nr_cylinders(struct dive *dive);
extern int nr_weightsystems(struct dive *dive); extern int nr_weightsystems(struct dive *dive);
@ -716,16 +716,18 @@ extern void vpmb_start_gradient(struct deco_state *ds);
extern void clear_vpmb_state(struct deco_state *ds); extern void clear_vpmb_state(struct deco_state *ds);
extern void printdecotable(struct decostop *table); extern void printdecotable(struct decostop *table);
extern struct event *get_next_event(struct event *event, const char *name); /* Since C doesn't have parameter-based overloading, two versions of get_next_event. */
extern const struct event *get_next_event(const struct event *event, const char *name);
extern struct event *get_next_event_mutable(struct event *event, const char *name);
/* Get gasmixes at increasing timestamps. /* Get gasmixes at increasing timestamps.
* In "evp", pass a pointer to a "struct event *" which is NULL-initialized on first invocation. * In "evp", pass a pointer to a "struct event *" which is NULL-initialized on first invocation.
* On subsequent calls, pass the same "evp" and the "gasmix" from previous calls. * On subsequent calls, pass the same "evp" and the "gasmix" from previous calls.
*/ */
extern struct gasmix get_gasmix(struct dive *dive, struct divecomputer *dc, int time, struct event **evp, struct gasmix gasmix); extern struct gasmix get_gasmix(const struct dive *dive, const struct divecomputer *dc, int time, const struct event **evp, struct gasmix gasmix);
/* Get gasmix at a given time */ /* Get gasmix at a given time */
extern struct gasmix get_gasmix_at_time(struct dive *dive, struct divecomputer *dc, duration_t time); extern struct gasmix get_gasmix_at_time(const struct dive *dive, const struct divecomputer *dc, duration_t time);
/* these structs holds the information that /* these structs holds the information that
* describes the cylinders / weight systems. * describes the cylinders / weight systems.
@ -762,7 +764,7 @@ extern void set_informational_units(const char *units);
extern void set_git_prefs(const char *prefs); extern void set_git_prefs(const char *prefs);
extern char *get_dive_date_c_string(timestamp_t when); extern char *get_dive_date_c_string(timestamp_t when);
extern void update_setpoint_events(struct dive *dive, struct divecomputer *dc); extern void update_setpoint_events(const struct dive *dive, struct divecomputer *dc);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -405,7 +405,7 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
struct divecomputer *dc = &dive->dc; struct divecomputer *dc = &dive->dc;
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
int i; int i;
struct event *ev = NULL, *evd = NULL; const struct event *ev = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE; enum divemode_t current_divemode = UNDEF_COMP_TYPE;
if (!dc) if (!dc)

View file

@ -350,7 +350,7 @@ void populate_pressure_information(struct dive *dive, struct divecomputer *dc, s
cylinder_t *cylinder = dive->cylinder + sensor; cylinder_t *cylinder = dive->cylinder + sensor;
pr_track_t *track = NULL; pr_track_t *track = NULL;
pr_track_t *current = NULL; pr_track_t *current = NULL;
struct event *ev, *b_ev; const struct event *ev, *b_ev;
int missing_pr = 0, dense = 1; int missing_pr = 0, dense = 1;
enum divemode_t dmode = dc->divemode; enum divemode_t dmode = dc->divemode;
const double gasfactor[5] = {1.0, 0.0, prefs.pscr_ratio/1000.0, 1.0, 1.0 }; const double gasfactor[5] = {1.0, 0.0, prefs.pscr_ratio/1000.0, 1.0, 1.0 };

View file

@ -136,7 +136,7 @@ int tissue_at_end(struct deco_state *ds, struct dive *dive, struct deco_state **
return 0; return 0;
psample = sample = dc->sample; psample = sample = dc->sample;
struct event *evdm = NULL; const struct event *evdm = NULL;
enum divemode_t divemode = UNDEF_COMP_TYPE; enum divemode_t divemode = UNDEF_COMP_TYPE;
for (i = 0; i < dc->samples; i++, sample++) { for (i = 0; i < dc->samples; i++, sample++) {
@ -716,7 +716,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
current_cylinder = get_cylinderid_at_time(dive, &dive->dc, sample->time); current_cylinder = get_cylinderid_at_time(dive, &dive->dc, sample->time);
// FIXME: This needs a function to find the divemode at the end of the dive like in // FIXME: This needs a function to find the divemode at the end of the dive like in
struct event *ev = NULL; const struct event *ev = NULL;
divemode = UNDEF_COMP_TYPE; divemode = UNDEF_COMP_TYPE;
divemode = get_current_divemode(&dive->dc, bottom_time, &ev, &divemode); divemode = get_current_divemode(&dive->dc, bottom_time, &ev, &divemode);
gas = dive->cylinder[current_cylinder].gasmix; gas = dive->cylinder[current_cylinder].gasmix;

View file

@ -551,7 +551,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
bool o2warning_exist = false; bool o2warning_exist = false;
enum divemode_t current_divemode; enum divemode_t current_divemode;
double amb; double amb;
struct event *evd = NULL; const struct event *evd = NULL;
current_divemode = UNDEF_COMP_TYPE; current_divemode = UNDEF_COMP_TYPE;
if (dive->dc.divemode != CCR) { if (dive->dc.divemode != CCR) {

View file

@ -316,7 +316,7 @@ struct plot_info *analyze_plot_info(struct plot_info *pi)
* Some dive computers give cylinder indexes, some * Some dive computers give cylinder indexes, some
* give just the gas mix. * give just the gas mix.
*/ */
int get_cylinder_index(struct dive *dive, struct event *ev) int get_cylinder_index(const struct dive *dive, const struct event *ev)
{ {
int best; int best;
struct gasmix mix; struct gasmix mix;
@ -337,7 +337,7 @@ int get_cylinder_index(struct dive *dive, struct event *ev)
return best < 0 ? 0 : best; return best < 0 ? 0 : best;
} }
struct event *get_next_event(struct event *event, const char *name) struct event *get_next_event_mutable(struct event *event, const char *name)
{ {
if (!name || !*name) if (!name || !*name)
return NULL; return NULL;
@ -349,6 +349,11 @@ struct event *get_next_event(struct event *event, const char *name)
return event; return event;
} }
const struct event *get_next_event(const struct event *event, const char *name)
{
return get_next_event_mutable((struct event *)event, name);
}
static int count_events(struct divecomputer *dc) static int count_events(struct divecomputer *dc)
{ {
int result = 0; int result = 0;
@ -372,13 +377,13 @@ static int set_setpoint(struct plot_info *pi, int i, int setpoint, int end)
return i; return i;
} }
static void check_setpoint_events(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) static void check_setpoint_events(const struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{ {
UNUSED(dive); UNUSED(dive);
int i = 0; int i = 0;
pressure_t setpoint; pressure_t setpoint;
setpoint.mbar = 0; setpoint.mbar = 0;
struct event *ev = get_next_event(dc->events, "SP change"); const struct event *ev = get_next_event(dc->events, "SP change");
if (!ev) if (!ev)
return; return;
@ -776,7 +781,7 @@ static unsigned int matching_gases(struct dive *dive, struct gasmix gasmix)
static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plot_info *pi)
{ {
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
struct event *ev = NULL; const struct event *ev = NULL;
unsigned int gases = 0; unsigned int gases = 0;
for (int i = 0; i < pi->nr; i++) { for (int i = 0; i < pi->nr; i++) {
@ -791,7 +796,7 @@ static void calculate_sac(struct dive *dive, struct divecomputer *dc, struct plo
} }
} }
static void populate_secondary_sensor_data(struct divecomputer *dc, struct plot_info *pi) static void populate_secondary_sensor_data(const struct divecomputer *dc, struct plot_info *pi)
{ {
UNUSED(dc); UNUSED(dc);
UNUSED(pi); UNUSED(pi);
@ -818,14 +823,14 @@ static void add_plot_pressure(struct plot_info *pi, int time, int cyl, pressure_
SENSOR_PRESSURE(entry, cyl) = p.mbar; SENSOR_PRESSURE(entry, cyl) = p.mbar;
} }
static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc, struct plot_info *pi) static void setup_gas_sensor_pressure(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi)
{ {
int prev, i; int prev, i;
struct event *ev; const struct event *ev;
int seen[MAX_CYLINDERS] = { 0, }; int seen[MAX_CYLINDERS] = { 0, };
unsigned int first[MAX_CYLINDERS] = { 0, }; unsigned int first[MAX_CYLINDERS] = { 0, };
unsigned int last[MAX_CYLINDERS] = { 0, }; unsigned int last[MAX_CYLINDERS] = { 0, };
struct divecomputer *secondary; const struct divecomputer *secondary;
prev = explicit_first_cylinder(dive, dc); prev = explicit_first_cylinder(dive, dc);
seen[prev] = 1; seen[prev] = 1;
@ -854,7 +859,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
// Fill in "seen[]" array - mark cylinders we're not interested // Fill in "seen[]" array - mark cylinders we're not interested
// in as negative. // in as negative.
for (i = 0; i < MAX_CYLINDERS; i++) { for (i = 0; i < MAX_CYLINDERS; i++) {
cylinder_t *cyl = dive->cylinder + i; const cylinder_t *cyl = dive->cylinder + i;
int start = cyl->start.mbar; int start = cyl->start.mbar;
int end = cyl->end.mbar; int end = cyl->end.mbar;
@ -885,7 +890,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
for (i = 0; i < MAX_CYLINDERS; i++) { for (i = 0; i < MAX_CYLINDERS; i++) {
if (seen[i] >= 0) { if (seen[i] >= 0) {
cylinder_t *cyl = dive->cylinder + i; const cylinder_t *cyl = dive->cylinder + i;
add_plot_pressure(pi, first[i], i, cyl->start); add_plot_pressure(pi, first[i], i, cyl->start);
add_plot_pressure(pi, last[i], i, cyl->end); add_plot_pressure(pi, last[i], i, cyl->end);
@ -907,7 +912,7 @@ static void setup_gas_sensor_pressure(struct dive *dive, struct divecomputer *dc
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
/* calculate DECO STOP / TTS / NDL */ /* calculate DECO STOP / TTS / NDL */
static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode) static void calculate_ndl_tts(struct deco_state *ds, const struct dive *dive, struct plot_data *entry, struct gasmix gasmix, double surface_pressure,enum divemode_t divemode)
{ {
/* FIXME: This should be configurable */ /* FIXME: This should be configurable */
/* ascent speed up to first deco stop */ /* ascent speed up to first deco stop */
@ -990,7 +995,7 @@ static void calculate_ndl_tts(struct deco_state *ds, struct dive *dive, struct p
/* Let's try to do some deco calculations. /* Let's try to do some deco calculations.
*/ */
void calculate_deco_information(struct deco_state *ds, struct deco_state *planner_ds, struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode) void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_ds, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode)
{ {
int i, count_iteration = 0; int i, count_iteration = 0;
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0; double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0;
@ -1017,7 +1022,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
if (decoMode() == VPMB) if (decoMode() == VPMB)
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive); ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
struct event *ev = NULL, *evd = NULL; const struct event *ev = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE; enum divemode_t current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) { for (i = 1; i < pi->nr; i++) {
@ -1206,7 +1211,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
int i; int i;
double amb_pressure; double amb_pressure;
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
struct event *evg = NULL, *evd = NULL; const struct event *evg = NULL, *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE; enum divemode_t current_divemode = UNDEF_COMP_TYPE;
for (i = 1; i < pi->nr; i++) { for (i = 1; i < pi->nr; i++) {

View file

@ -77,7 +77,7 @@ void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int
struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi); struct plot_data *populate_plot_entries(struct dive *dive, struct divecomputer *dc, struct plot_info *pi);
struct plot_info *analyze_plot_info(struct plot_info *pi); struct plot_info *analyze_plot_info(struct plot_info *pi);
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds); void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds);
void calculate_deco_information(struct deco_state *ds, struct deco_state *planner_de, struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode); void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_de, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode);
struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *); struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
/* /*

View file

@ -236,10 +236,10 @@ void process_selected_dives(void)
#define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used #define SOME_GAS 5000 // 5bar drop in cylinder pressure makes cylinder used
bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx) bool has_gaschange_event(const struct dive *dive, const struct divecomputer *dc, int idx)
{ {
bool first_gas_explicit = false; bool first_gas_explicit = false;
struct event *event = get_next_event(dc->events, "gaschange"); const struct event *event = get_next_event(dc->events, "gaschange");
while (event) { while (event) {
if (dc->sample && (event->time.seconds == 0 || if (dc->sample && (event->time.seconds == 0 ||
(dc->samples && dc->sample[0].time.seconds == event->time.seconds))) (dc->samples && dc->sample[0].time.seconds == event->time.seconds)))

View file

@ -411,7 +411,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem
if (i < poly.count()) { if (i < poly.count()) {
double value = dataModel->index(i, vDataColumn).data().toDouble(); double value = dataModel->index(i, vDataColumn).data().toDouble();
struct gasmix gasmix = { 0 }; struct gasmix gasmix = { 0 };
struct event *ev = NULL; const struct event *ev = NULL;
int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt(); int sec = dataModel->index(i, DivePlotDataModel::TIME).data().toInt();
gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix); gasmix = get_gasmix(&displayed_dive, displayed_dc, sec, &ev, gasmix);
int inert = 1000 - get_o2(gasmix); int inert = 1000 - get_o2(gasmix);

View file

@ -1452,7 +1452,7 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
action->setData(event->globalPos()); action->setData(event->globalPos());
QAction *splitAction = m.addAction(tr("Split dive into two"), this, SLOT(splitDive())); QAction *splitAction = m.addAction(tr("Split dive into two"), this, SLOT(splitDive()));
splitAction->setData(event->globalPos()); splitAction->setData(event->globalPos());
struct event *ev = NULL; const struct event *ev = NULL;
enum divemode_t divemode = UNDEF_COMP_TYPE; enum divemode_t divemode = UNDEF_COMP_TYPE;
QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos())); QPointF scenePos = mapToScene(mapFromGlobal(event->globalPos()));
QString gas = action->text(); QString gas = action->text();
@ -1695,7 +1695,7 @@ void ProfileWidget2::changeGas()
// if there is a gas change at this time stamp, remove it before adding the new one // if there is a gas change at this time stamp, remove it before adding the new one
struct event *gasChangeEvent = current_dc->events; struct event *gasChangeEvent = current_dc->events;
while ((gasChangeEvent = get_next_event(gasChangeEvent, "gaschange")) != NULL) { while ((gasChangeEvent = get_next_event_mutable(gasChangeEvent, "gaschange")) != NULL) {
if (gasChangeEvent->time.seconds == seconds) { if (gasChangeEvent->time.seconds == seconds) {
remove_event(gasChangeEvent); remove_event(gasChangeEvent);
gasChangeEvent = current_dc->events; gasChangeEvent = current_dc->events;

View file

@ -108,7 +108,7 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
int startTime = 0; int startTime = 0;
// work through all the gas changes and add the rectangle for each gas while it was used // work through all the gas changes and add the rectangle for each gas while it was used
struct event *ev = get_next_event(dc->events, "gaschange"); const struct event *ev = get_next_event(dc->events, "gaschange");
while (ev && (int)ev->time.seconds < last_entry->sec) { while (ev && (int)ev->time.seconds < last_entry->sec) {
width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime); width = hAxis->posAtValue(ev->time.seconds) - hAxis->posAtValue(startTime);
left = hAxis->posAtValue(startTime); left = hAxis->posAtValue(startTime);

View file

@ -81,7 +81,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
o2pressure_t last_sp; o2pressure_t last_sp;
bool oldRec = recalc; bool oldRec = recalc;
struct divecomputer *dc = &(d->dc); struct divecomputer *dc = &(d->dc);
struct event *evd = NULL; const struct event *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE; enum divemode_t current_divemode = UNDEF_COMP_TYPE;
recalc = false; recalc = false;
CylindersModel::instance()->updateDive(); CylindersModel::instance()->updateDive();