mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: move get_or_create_cylinder() to struct dive
Other cylinder-creation functions were already there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
777e7f32a5
commit
9bb2255ba8
12 changed files with 83 additions and 83 deletions
|
|
@ -359,6 +359,17 @@ int dive::get_cylinder_index(const struct event &ev) const
|
|||
return best < 0 ? 0 : best;
|
||||
}
|
||||
|
||||
cylinder_t *dive::get_or_create_cylinder(int idx)
|
||||
{
|
||||
if (idx < 0) {
|
||||
report_info("Warning: accessing invalid cylinder %d", idx);
|
||||
return NULL;
|
||||
}
|
||||
while (static_cast<size_t>(idx) >= cylinders.size())
|
||||
add_empty_cylinder(&cylinders);
|
||||
return &cylinders[idx];
|
||||
}
|
||||
|
||||
/* Are there any used cylinders which we do not know usage about? */
|
||||
static bool has_unknown_used_cylinders(const struct dive &dive, const struct divecomputer *dc,
|
||||
const bool used_cylinders[], int num)
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ struct dive {
|
|||
struct gasmix get_gasmix_from_event(const struct event &ev) const;
|
||||
struct gasmix get_gasmix_at_time(const struct divecomputer &dc, duration_t time) const;
|
||||
cylinder_t *get_cylinder(int idx);
|
||||
cylinder_t *get_or_create_cylinder(int idx);
|
||||
const cylinder_t *get_cylinder(int idx) const;
|
||||
weight_t total_weight() const;
|
||||
int get_salinity() const;
|
||||
|
|
|
|||
|
|
@ -369,17 +369,6 @@ cylinder_t *add_empty_cylinder(struct cylinder_table *t)
|
|||
return &t->back();
|
||||
}
|
||||
|
||||
cylinder_t *get_or_create_cylinder(struct dive *d, int idx)
|
||||
{
|
||||
if (idx < 0) {
|
||||
report_info("Warning: accessing invalid cylinder %d", idx);
|
||||
return NULL;
|
||||
}
|
||||
while (static_cast<size_t>(idx) >= d->cylinders.size())
|
||||
add_empty_cylinder(&d->cylinders);
|
||||
return &d->cylinders[idx];
|
||||
}
|
||||
|
||||
/* if a default cylinder is set, use that */
|
||||
void fill_default_cylinder(const struct dive *dive, cylinder_t *cyl)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ using weightsystem_table = std::vector<weightsystem_t>;
|
|||
extern enum cylinderuse cylinderuse_from_text(const char *text);
|
||||
extern void copy_cylinder_types(const struct dive *s, struct dive *d);
|
||||
extern cylinder_t *add_empty_cylinder(struct cylinder_table *t);
|
||||
extern cylinder_t *get_or_create_cylinder(struct dive *d, int idx);
|
||||
extern void remove_cylinder(struct dive *dive, int idx);
|
||||
extern void remove_weightsystem(struct dive *dive, int idx);
|
||||
extern void set_weightsystem(struct dive *dive, int idx, weightsystem_t ws);
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ static int seac_dive(void *param, int, char **data, char **)
|
|||
state->cur_dive->number = atoi(data[0]);
|
||||
|
||||
// Create first cylinder
|
||||
cylinder_t *curcyl = get_or_create_cylinder(state->cur_dive.get(), 0);
|
||||
cylinder_t *curcyl = state->cur_dive->get_or_create_cylinder(0);
|
||||
|
||||
// Get time and date
|
||||
sscanf(data[2], "%d/%d/%2d", &day, &month, &year);
|
||||
|
|
@ -238,7 +238,7 @@ static int seac_dive(void *param, int, char **data, char **)
|
|||
seac_gaschange(state, sqlstmt);
|
||||
lastgas = curgas;
|
||||
cylnum ^= 1; // Only need to toggle between two cylinders
|
||||
curcyl = get_or_create_cylinder(state->cur_dive.get(), cylnum);
|
||||
curcyl = state->cur_dive->get_or_create_cylinder(cylnum);
|
||||
curcyl->gasmix.o2.permille = 10 * sqlite3_column_int(sqlstmt, 4);
|
||||
}
|
||||
state->cur_sample->stopdepth.mm = 10 * sqlite3_column_int(sqlstmt, 5);
|
||||
|
|
|
|||
|
|
@ -993,23 +993,23 @@ static int divinglog_dive_match(struct dive *dive, const char *name, char *buf,
|
|||
/* For cylinder related fields, we might have to create a cylinder first. */
|
||||
cylinder_t cyl;
|
||||
if (MATCH("tanktype", utf8_string_std, &cyl.type.description)) {
|
||||
get_or_create_cylinder(dive, 0)->type.description = std::move(cyl.type.description);
|
||||
dive->get_or_create_cylinder(0)->type.description = std::move(cyl.type.description);
|
||||
return 1;
|
||||
}
|
||||
if (MATCH("tanksize", cylindersize, &cyl.type.size)) {
|
||||
get_or_create_cylinder(dive, 0)->type.size = cyl.type.size;
|
||||
dive->get_or_create_cylinder(0)->type.size = cyl.type.size;
|
||||
return 1;
|
||||
}
|
||||
if (MATCH_STATE("presw", pressure, &cyl.type.workingpressure)) {
|
||||
get_or_create_cylinder(dive, 0)->type.workingpressure = cyl.type.workingpressure;
|
||||
dive->get_or_create_cylinder(0)->type.workingpressure = cyl.type.workingpressure;
|
||||
return 1;
|
||||
}
|
||||
if (MATCH_STATE("press", pressure, &cyl.start)) {
|
||||
get_or_create_cylinder(dive, 0)->start = cyl.start;
|
||||
dive->get_or_create_cylinder(0)->start = cyl.start;
|
||||
return 1;
|
||||
}
|
||||
if (MATCH_STATE("prese", pressure, &cyl.end)) {
|
||||
get_or_create_cylinder(dive, 0)->end = cyl.end;
|
||||
dive->get_or_create_cylinder(0)->end = cyl.end;
|
||||
return 1;
|
||||
}
|
||||
return MATCH_STATE("divedate", divedate, &dive->when) ||
|
||||
|
|
@ -1283,11 +1283,11 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf, str
|
|||
return;
|
||||
}
|
||||
if (MATCH_STATE("cylinderstartpressure", pressure, &p)) {
|
||||
get_or_create_cylinder(dive, 0)->start = p;
|
||||
dive->get_or_create_cylinder(0)->start = p;
|
||||
return;
|
||||
}
|
||||
if (MATCH_STATE("cylinderendpressure", pressure, &p)) {
|
||||
get_or_create_cylinder(dive, 0)->end = p;
|
||||
dive->get_or_create_cylinder(0)->end = p;
|
||||
return;
|
||||
}
|
||||
if (MATCH_STATE("gps", gps_in_dive, dive))
|
||||
|
|
@ -1858,7 +1858,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct divelog *log)
|
|||
state.cur_dc->surface_pressure.mbar = ((ptr[25] << 8) + ptr[24]) / 10;
|
||||
|
||||
// Declare initial mix as first cylinder
|
||||
cyl = get_or_create_cylinder(state.cur_dive.get(), 0);
|
||||
cyl = state.cur_dive->get_or_create_cylinder(0);
|
||||
cyl->gasmix.o2.permille = ptr[26] * 10;
|
||||
cyl->gasmix.he.permille = ptr[27] * 10;
|
||||
|
||||
|
|
|
|||
|
|
@ -226,7 +226,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
|
|||
/* Create first sample at time = 0, not based on dp because
|
||||
* there is no real dp for time = 0, set first cylinder to 0
|
||||
* O2 setpoint for this sample will be filled later from next dp */
|
||||
cyl = get_or_create_cylinder(dive, 0);
|
||||
cyl = dive->get_or_create_cylinder(0);
|
||||
struct sample *sample = prepare_sample(dc);
|
||||
sample->sac.mliter = prefs.bottomsac;
|
||||
if (track_gas && cyl->type.workingpressure.mbar)
|
||||
|
|
|
|||
|
|
@ -324,7 +324,7 @@ void uemis::parse_divelog_binary(std::string_view base64, struct dive *dive)
|
|||
* we store the incorrect working pressure to get the SAC calculations "close"
|
||||
* but the user will have to correct this manually
|
||||
*/
|
||||
cylinder_t *cyl = get_or_create_cylinder(dive, i);
|
||||
cylinder_t *cyl = dive->get_or_create_cylinder(i);
|
||||
cyl->type.size.mliter = lrintf(volume);
|
||||
cyl->type.workingpressure.mbar = 202600;
|
||||
cyl->gasmix.o2.permille = *(uint8_t *)(data.data() + 120 + 25 * (gasoffset + i)) * 10;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue