mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn event-list of divecomputer into std::vector<>
This is a rather long commit, because it refactors lots of the event code from pointer to value semantics: pointers to entries in an std::vector<> are not stable, so better use indexes. To step through the event-list at diven time stamps, add *_loop classes, which encapsulate state that had to be manually handled before by the caller. I'm not happy about the interface, but it tries to mirror the one we had before. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
8ddc960fa0
commit
27dbdd35c6
36 changed files with 644 additions and 821 deletions
|
@ -728,16 +728,12 @@ static void smtk_parse_other(struct dive *dive, const std::vector<std::string> &
|
|||
* Returns a pointer to a bookmark event in an event list if it exists for
|
||||
* a given time. Return NULL otherwise.
|
||||
*/
|
||||
static struct event *find_bookmark(struct event *orig, int t)
|
||||
static struct event *find_bookmark(struct divecomputer &dc, int t)
|
||||
{
|
||||
struct event *ev = orig;
|
||||
|
||||
while (ev) {
|
||||
if ((ev->time.seconds == t) && (ev->type == SAMPLE_EVENT_BOOKMARK))
|
||||
return ev;
|
||||
ev = ev->next;
|
||||
}
|
||||
return NULL;
|
||||
auto it = std::find_if(dc.events.begin(), dc.events.end(),
|
||||
[t](auto &ev)
|
||||
{ return ev.time.seconds == t && ev.type == SAMPLE_EVENT_BOOKMARK; });
|
||||
return it != dc.events.end() ? &*it : nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -763,7 +759,7 @@ static void smtk_parse_bookmarks(MdbHandle *mdb, struct dive *d, char *dive_idx)
|
|||
if (same_string(table.get_data(0), dive_idx)) {
|
||||
time = lrint(strtod(table.get_data(4), NULL) * 60);
|
||||
const char *tmp = table.get_data(2);
|
||||
ev = find_bookmark(d->dc.events, time);
|
||||
ev = find_bookmark(d->dc, time);
|
||||
if (ev)
|
||||
ev->name = tmp;
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue