Timed events can have a name, and can be canceled based on their name

This commit is contained in:
Florent Le Coz
2014-05-30 15:42:01 +02:00
parent a63faf6fa9
commit 5cca518c2d
4 changed files with 62 additions and 7 deletions
+13 -5
View File
@@ -1,20 +1,22 @@
#include <utils/timed_events.hpp>
TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point,
std::function<void()> callback):
std::function<void()> callback, const std::string& name):
time_point(std::move(time_point)),
callback(callback),
repeat(false),
repeat_delay(0)
repeat_delay(0),
name(name)
{
}
TimedEvent::TimedEvent(std::chrono::milliseconds&& duration,
std::function<void()> callback):
std::function<void()> callback, const std::string& name):
time_point(std::chrono::steady_clock::now() + duration),
callback(callback),
repeat(true),
repeat_delay(std::move(duration))
repeat_delay(std::move(duration)),
name(name)
{
}
@@ -22,7 +24,8 @@ TimedEvent::TimedEvent(TimedEvent&& other):
time_point(std::move(other.time_point)),
callback(std::move(other.callback)),
repeat(other.repeat),
repeat_delay(std::move(other.repeat_delay))
repeat_delay(std::move(other.repeat_delay)),
name(std::move(other.name))
{
}
@@ -52,3 +55,8 @@ void TimedEvent::execute()
{
this->callback();
}
const std::string& TimedEvent::get_name() const
{
return this->name;
}