mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:53:23 +00:00
Cleanup: const-ify parameters to trivial accessor functions
Accessor-functions without noticeable logic, such as depth_to_bar() can trivially be made "const-clean". Moreover, let get_dive_location() return a "const char *". The non-const version must have been an oversight, as the caller must not free() or overwrite the string. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
360f07e453
commit
44f34d8cd7
2 changed files with 35 additions and 35 deletions
36
core/dive.c
36
core/dive.c
|
@ -3858,7 +3858,7 @@ static bool new_picture_for_dive(struct dive *d, const char *filename)
|
|||
// only add pictures that have timestamps between 30 minutes before the dive and
|
||||
// 30 minutes after the dive ends
|
||||
#define D30MIN (30 * 60)
|
||||
bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp)
|
||||
bool dive_check_picture_time(const struct dive *d, int shift_time, timestamp_t timestamp)
|
||||
{
|
||||
offset_t offset;
|
||||
if (timestamp) {
|
||||
|
@ -4025,7 +4025,7 @@ void delete_current_divecomputer(void)
|
|||
|
||||
/* helper function to make it easier to work with our structures
|
||||
* we don't interpolate here, just use the value from the last sample up to that time */
|
||||
int get_depth_at_time(struct divecomputer *dc, unsigned int time)
|
||||
int get_depth_at_time(const struct divecomputer *dc, unsigned int time)
|
||||
{
|
||||
int depth = 0;
|
||||
if (dc && dc->sample)
|
||||
|
@ -4038,7 +4038,7 @@ int get_depth_at_time(struct divecomputer *dc, unsigned int time)
|
|||
}
|
||||
|
||||
//Calculate O2 in best mix
|
||||
fraction_t best_o2(depth_t depth, struct dive *dive)
|
||||
fraction_t best_o2(depth_t depth, const struct dive *dive)
|
||||
{
|
||||
fraction_t fo2;
|
||||
|
||||
|
@ -4050,7 +4050,7 @@ fraction_t best_o2(depth_t depth, struct dive *dive)
|
|||
}
|
||||
|
||||
//Calculate He in best mix. O2 is considered narcopic
|
||||
fraction_t best_he(depth_t depth, struct dive *dive)
|
||||
fraction_t best_he(depth_t depth, const struct dive *dive)
|
||||
{
|
||||
fraction_t fhe;
|
||||
int pnarcotic, ambient;
|
||||
|
@ -4107,17 +4107,17 @@ int calculate_depth_to_mbar(int depth, pressure_t surface_pressure, int salinity
|
|||
return mbar;
|
||||
}
|
||||
|
||||
int depth_to_mbar(int depth, struct dive *dive)
|
||||
int depth_to_mbar(int depth, const struct dive *dive)
|
||||
{
|
||||
return calculate_depth_to_mbar(depth, dive->surface_pressure, dive->salinity);
|
||||
}
|
||||
|
||||
double depth_to_bar(int depth, struct dive *dive)
|
||||
double depth_to_bar(int depth, const struct dive *dive)
|
||||
{
|
||||
return depth_to_mbar(depth, dive) / 1000.0;
|
||||
}
|
||||
|
||||
double depth_to_atm(int depth, struct dive *dive)
|
||||
double depth_to_atm(int depth, const struct dive *dive)
|
||||
{
|
||||
return mbar_to_atm(depth_to_mbar(depth, dive));
|
||||
}
|
||||
|
@ -4126,7 +4126,7 @@ double depth_to_atm(int depth, struct dive *dive)
|
|||
* (that's the one that some dive computers like the Uemis Zurich
|
||||
* provide - for the other models that do this libdivecomputer has to
|
||||
* take care of this, but the Uemis we support natively */
|
||||
int rel_mbar_to_depth(int mbar, struct dive *dive)
|
||||
int rel_mbar_to_depth(int mbar, const struct dive *dive)
|
||||
{
|
||||
int cm;
|
||||
double specific_weight = 1.03 * 0.981;
|
||||
|
@ -4137,7 +4137,7 @@ int rel_mbar_to_depth(int mbar, struct dive *dive)
|
|||
return cm * 10;
|
||||
}
|
||||
|
||||
int mbar_to_depth(int mbar, struct dive *dive)
|
||||
int mbar_to_depth(int mbar, const struct dive *dive)
|
||||
{
|
||||
pressure_t surface_pressure;
|
||||
if (dive->surface_pressure.mbar)
|
||||
|
@ -4148,7 +4148,7 @@ int mbar_to_depth(int mbar, struct dive *dive)
|
|||
}
|
||||
|
||||
/* MOD rounded to multiples of roundto mm */
|
||||
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, struct dive *dive, int roundto)
|
||||
depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto)
|
||||
{
|
||||
depth_t rounded_depth;
|
||||
|
||||
|
@ -4158,7 +4158,7 @@ depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, struct dive *dive, int
|
|||
}
|
||||
|
||||
/* Maximum narcotic depth rounded to multiples of roundto mm */
|
||||
depth_t gas_mnd(struct gasmix mix, depth_t end, struct dive *dive, int roundto)
|
||||
depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto)
|
||||
{
|
||||
depth_t rounded_depth;
|
||||
pressure_t ppo2n2;
|
||||
|
@ -4183,14 +4183,14 @@ struct dive *get_dive_from_table(int nr, struct dive_table *dt)
|
|||
return dt->dives[nr];
|
||||
}
|
||||
|
||||
struct dive_site *get_dive_site_for_dive(struct dive *dive)
|
||||
struct dive_site *get_dive_site_for_dive(const struct dive *dive)
|
||||
{
|
||||
if (dive)
|
||||
return get_dive_site_by_uuid(dive->dive_site_uuid);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *get_dive_country(struct dive *dive)
|
||||
const char *get_dive_country(const struct dive *dive)
|
||||
{
|
||||
struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
|
||||
if (ds) {
|
||||
|
@ -4201,7 +4201,7 @@ const char *get_dive_country(struct dive *dive)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *get_dive_location(struct dive *dive)
|
||||
const char *get_dive_location(const struct dive *dive)
|
||||
{
|
||||
struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);
|
||||
if (ds && ds->name)
|
||||
|
@ -4209,10 +4209,10 @@ char *get_dive_location(struct dive *dive)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
unsigned int number_of_computers(struct dive *dive)
|
||||
unsigned int number_of_computers(const struct dive *dive)
|
||||
{
|
||||
unsigned int total_number = 0;
|
||||
struct divecomputer *dc = &dive->dc;
|
||||
const struct divecomputer *dc = &dive->dc;
|
||||
|
||||
if (!dive)
|
||||
return 1;
|
||||
|
@ -4275,12 +4275,12 @@ int get_idx_by_uniq_id(int id)
|
|||
return i;
|
||||
}
|
||||
|
||||
bool dive_site_has_gps_location(struct dive_site *ds)
|
||||
bool dive_site_has_gps_location(const struct dive_site *ds)
|
||||
{
|
||||
return ds && (ds->latitude.udeg || ds->longitude.udeg);
|
||||
}
|
||||
|
||||
int dive_has_gps_location(struct dive *dive)
|
||||
int dive_has_gps_location(const struct dive *dive)
|
||||
{
|
||||
if (!dive)
|
||||
return false;
|
||||
|
|
34
core/dive.h
34
core/dive.h
|
@ -373,7 +373,7 @@ struct picture {
|
|||
for (struct picture *picture = (_divestruct).picture_list; picture; picture = picture->next)
|
||||
|
||||
extern struct picture *alloc_picture();
|
||||
extern bool dive_check_picture_time(struct dive *d, int shift_time, timestamp_t timestamp);
|
||||
extern bool dive_check_picture_time(const struct dive *d, int shift_time, timestamp_t timestamp);
|
||||
extern void dive_create_picture(struct dive *d, const char *filename, int shift_time, bool match_all);
|
||||
extern void dive_add_picture(struct dive *d, struct picture *newpic);
|
||||
extern bool dive_remove_picture(struct dive *d, const char *filename);
|
||||
|
@ -384,20 +384,20 @@ extern void picture_free(struct picture *picture);
|
|||
|
||||
extern bool has_gaschange_event(struct dive *dive, struct divecomputer *dc, int idx);
|
||||
extern int explicit_first_cylinder(struct dive *dive, struct divecomputer *dc);
|
||||
extern int get_depth_at_time(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, struct dive *dive);
|
||||
extern fraction_t best_he(depth_t depth, struct dive *dive);
|
||||
extern fraction_t best_o2(depth_t depth, const struct dive *dive);
|
||||
extern fraction_t best_he(depth_t depth, const struct dive *dive);
|
||||
|
||||
extern int get_surface_pressure_in_mbar(const struct dive *dive, bool non_null);
|
||||
extern int calculate_depth_to_mbar(int depth, pressure_t surface_pressure, int salinity);
|
||||
extern int depth_to_mbar(int depth, struct dive *dive);
|
||||
extern double depth_to_bar(int depth, struct dive *dive);
|
||||
extern double depth_to_atm(int depth, struct dive *dive);
|
||||
extern int rel_mbar_to_depth(int mbar, struct dive *dive);
|
||||
extern int mbar_to_depth(int mbar, struct dive *dive);
|
||||
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, struct dive *dive, int roundto);
|
||||
extern depth_t gas_mnd(struct gasmix mix, depth_t end, struct dive *dive, int roundto);
|
||||
extern int depth_to_mbar(int depth, const struct dive *dive);
|
||||
extern double depth_to_bar(int depth, const struct dive *dive);
|
||||
extern double depth_to_atm(int depth, const struct dive *dive);
|
||||
extern int rel_mbar_to_depth(int mbar, const struct dive *dive);
|
||||
extern int mbar_to_depth(int mbar, const struct dive *dive);
|
||||
extern depth_t gas_mod(struct gasmix mix, pressure_t po2_limit, const struct dive *dive, int roundto);
|
||||
extern depth_t gas_mnd(struct gasmix mix, depth_t end, const struct dive *dive, int roundto);
|
||||
|
||||
#define SURFACE_THRESHOLD 750 /* somewhat arbitrary: only below 75cm is it really diving */
|
||||
|
||||
|
@ -442,10 +442,10 @@ extern unsigned int dc_number;
|
|||
|
||||
extern struct dive *get_dive(int nr);
|
||||
extern struct dive *get_dive_from_table(int nr, struct dive_table *dt);
|
||||
extern struct dive_site *get_dive_site_for_dive(struct dive *dive);
|
||||
extern const char *get_dive_country(struct dive *dive);
|
||||
extern char *get_dive_location(struct dive *dive);
|
||||
extern unsigned int number_of_computers(struct dive *dive);
|
||||
extern struct dive_site *get_dive_site_for_dive(const struct dive *dive);
|
||||
extern const char *get_dive_country(const struct dive *dive);
|
||||
extern const char *get_dive_location(const struct dive *dive);
|
||||
extern unsigned int number_of_computers(const struct dive *dive);
|
||||
extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
|
||||
extern timestamp_t dive_endtime(const struct dive *dive);
|
||||
|
||||
|
@ -475,8 +475,8 @@ extern "C" {
|
|||
|
||||
extern struct dive *get_dive_by_uniq_id(int id);
|
||||
extern int get_idx_by_uniq_id(int id);
|
||||
extern bool dive_site_has_gps_location(struct dive_site *ds);
|
||||
extern int dive_has_gps_location(struct dive *dive);
|
||||
extern bool dive_site_has_gps_location(const struct dive_site *ds);
|
||||
extern int dive_has_gps_location(const struct dive *dive);
|
||||
|
||||
extern int report_error(const char *fmt, ...);
|
||||
extern void set_error_cb(void(*cb)(char *)); // Callback takes ownership of passed string
|
||||
|
|
Loading…
Add table
Reference in a new issue