summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/timed_events.hpp5
-rw-r--r--src/utils/timed_events_manager.cpp14
2 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/timed_events.hpp b/src/utils/timed_events.hpp
index 393b38d..fa0fc50 100644
--- a/src/utils/timed_events.hpp
+++ b/src/utils/timed_events.hpp
@@ -125,6 +125,11 @@ public:
* Return the number of managed events.
*/
std::size_t size() const;
+ /**
+ * Return a pointer to the first event with the given name. If none
+ * is found, returns nullptr.
+ */
+ const TimedEvent* find_event(const std::string& name) const;
private:
std::vector<TimedEvent> events;
diff --git a/src/utils/timed_events_manager.cpp b/src/utils/timed_events_manager.cpp
index 67d61fe..75e6338 100644
--- a/src/utils/timed_events_manager.cpp
+++ b/src/utils/timed_events_manager.cpp
@@ -1,5 +1,7 @@
#include <utils/timed_events.hpp>
+#include <algorithm>
+
TimedEventsManager& TimedEventsManager::instance()
{
static TimedEventsManager inst;
@@ -67,7 +69,19 @@ std::size_t TimedEventsManager::cancel(const std::string& name)
return res;
}
+
+
std::size_t TimedEventsManager::size() const
{
return this->events.size();
}
+
+const TimedEvent* TimedEventsManager::find_event(const std::string& name) const
+{
+ const auto it = std::find_if(this->events.begin(), this->events.end(), [&name](const TimedEvent& o) {
+ return o.get_name() == name;
+ });
+ if (it == this->events.end())
+ return nullptr;
+ return &*it;
+}