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
|
@ -276,7 +276,6 @@ void export_depths(const char *filename, bool selected_only)
|
|||
{
|
||||
FILE *f;
|
||||
struct dive *dive;
|
||||
depth_t depth;
|
||||
int i;
|
||||
const char *unit = NULL;
|
||||
|
||||
|
@ -287,12 +286,11 @@ void export_depths(const char *filename, bool selected_only)
|
|||
continue;
|
||||
|
||||
FOR_EACH_PICTURE (dive) {
|
||||
int n = dive->dc.samples;
|
||||
struct sample *s = dive->dc.sample;
|
||||
depth.mm = 0;
|
||||
while (--n >= 0 && (int32_t)s->time.seconds <= picture->offset.seconds) {
|
||||
depth.mm = s->depth.mm;
|
||||
s++;
|
||||
depth_t depth;
|
||||
for (auto &s: dive->dc.samples) {
|
||||
if ((int32_t)s.time.seconds > picture->offset.seconds)
|
||||
break;
|
||||
depth = s.depth;
|
||||
}
|
||||
put_format(&buf, "%s\t%.1f", picture->filename, get_depth_units(depth.mm, NULL, &unit));
|
||||
put_format(&buf, "%s\n", unit);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue