From 5960fb73409e5eb9797ac74bef97f8fa82810e1c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 4 May 2024 22:26:30 +0200 Subject: [PATCH] core: remove get_event_mutable() We can now return mutable/imutable depending on const-ness of the parameter, owing to parameter overloading. Signed-off-by: Berthold Stoeger --- commands/command_event.cpp | 2 +- core/dive.cpp | 2 +- core/event.h | 3 +-- core/profile.cpp | 4 ++-- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/commands/command_event.cpp b/commands/command_event.cpp index 110ad9639..9d11fdbc3 100644 --- a/commands/command_event.cpp +++ b/commands/command_event.cpp @@ -166,7 +166,7 @@ AddGasSwitch::AddGasSwitch(struct dive *d, int dcNr, int seconds, int tank) : Ev // support that anyway. struct divecomputer *dc = get_dive_dc(d, dcNr); struct event *gasChangeEvent = dc->events; - while ((gasChangeEvent = get_next_event_mutable(gasChangeEvent, "gaschange")) != NULL) { + while ((gasChangeEvent = get_next_event(gasChangeEvent, "gaschange")) != NULL) { if (gasChangeEvent->time.seconds == seconds) { eventsToRemove.push_back(gasChangeEvent); int idx = gasChangeEvent->gas.index; diff --git a/core/dive.cpp b/core/dive.cpp index c6c2019ca..70541c0bd 100644 --- a/core/dive.cpp +++ b/core/dive.cpp @@ -652,7 +652,7 @@ void update_setpoint_events(const struct dive *dive, struct divecomputer *dc) // an "SP change" event at t=0 is currently our marker for OC vs CCR // this will need to change to a saner setup, but for now we can just // check if such an event is there and adjust it, or add that event - ev = get_next_event_mutable(dc->events, "SP change"); + ev = get_next_event(dc->events, "SP change"); if (ev && ev->time.seconds == 0) { ev->value = new_setpoint; } else { diff --git a/core/event.h b/core/event.h index fe3d0fc1b..767237a88 100644 --- a/core/event.h +++ b/core/event.h @@ -56,8 +56,7 @@ extern struct event *clone_event_rename(const struct event *ev, const std::strin extern bool same_event(const struct event *a, const struct event *b); extern enum event_severity get_event_severity(const struct event *ev); -/* Since C doesn't have parameter-based overloading, two versions of get_next_event. */ extern const struct event *get_next_event(const struct event *event, const std::string &name); -extern struct event *get_next_event_mutable(struct event *event, const std::string &name); +extern struct event *get_next_event(struct event *event, const std::string &name); #endif diff --git a/core/profile.cpp b/core/profile.cpp index f4e75fcd1..92ffb048e 100644 --- a/core/profile.cpp +++ b/core/profile.cpp @@ -221,7 +221,7 @@ int get_cylinder_index(const struct dive *dive, const struct event *ev) return best < 0 ? 0 : best; } -struct event *get_next_event_mutable(struct event *event, const std::string &name) +struct event *get_next_event(struct event *event, const std::string &name) { if (name.empty()) return NULL; @@ -235,7 +235,7 @@ struct event *get_next_event_mutable(struct event *event, const std::string &nam const struct event *get_next_event(const struct event *event, const std::string &name) { - return get_next_event_mutable((struct event *)event, name); + return get_next_event((struct event *)event, name); } static int count_events(const struct divecomputer *dc)