mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: use std::vector<> to store divecomputer samples
This is a hairy one, because the sample code is rather tricky. There was a pattern of looping through pairs of adjacent samples, for interpolation purposes. Add an range adapter to generalize such loops. Removes the finish_sample() function: The code would call prepare_sample() to start parsing of samples and then finish_sample() to actuall add it. I.e. a kind of commit(). Since, with one exception, all users of prepare_sample() called finish_sample() in all code paths, we might just add the sample in the first place. The exception was sample_end() in parse.cpp. This brings a small change: samples are now added, even if they could only be parsed partially. I doubt that this makes any difference, since it will only happen for broken divelogs anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
bc761344d4
commit
f120fecccb
28 changed files with 588 additions and 715 deletions
|
@ -679,8 +679,9 @@ static int sanitize_sensor_id(const struct dive *d, int nr)
|
|||
static struct sample *new_sample(struct git_parser_state *state)
|
||||
{
|
||||
struct sample *sample = prepare_sample(state->active_dc);
|
||||
if (sample != state->active_dc->sample) {
|
||||
memcpy(sample, sample - 1, sizeof(struct sample));
|
||||
size_t num_samples = state->active_dc->samples.size();
|
||||
if (num_samples >= 2) {
|
||||
*sample = state->active_dc->samples[num_samples - 2];
|
||||
sample->pressure[0].mbar = 0;
|
||||
sample->pressure[1].mbar = 0;
|
||||
} else {
|
||||
|
@ -721,7 +722,6 @@ static void sample_parser(char *line, struct git_parser_state *state)
|
|||
line = parse_sample_unit(sample, val, line);
|
||||
}
|
||||
}
|
||||
finish_sample(state->active_dc);
|
||||
}
|
||||
|
||||
static void parse_dc_airtemp(char *line, struct git_parser_state *state)
|
||||
|
@ -1649,7 +1649,7 @@ static struct divecomputer *create_new_dc(struct dive *dive)
|
|||
while (dc->next)
|
||||
dc = dc->next;
|
||||
/* Did we already fill that in? */
|
||||
if (dc->samples || !dc->model.empty() || dc->when) {
|
||||
if (!dc->samples.empty() || !dc->model.empty() || dc->when) {
|
||||
struct divecomputer *newdc = new divecomputer;
|
||||
dc->next = newdc;
|
||||
dc = newdc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue