From 5cca518c2d946144f4fee1b15dcfd3884850dcb1 Mon Sep 17 00:00:00 2001 From: Florent Le Coz Date: Fri, 30 May 2014 15:42:01 +0200 Subject: Timed events can have a name, and can be canceled based on their name --- src/utils/timed_events.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'src/utils/timed_events.cpp') diff --git a/src/utils/timed_events.cpp b/src/utils/timed_events.cpp index 10ef4c1..5010a3f 100644 --- a/src/utils/timed_events.cpp +++ b/src/utils/timed_events.cpp @@ -1,20 +1,22 @@ #include TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, - std::function callback): + std::function 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 callback): + std::function 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; +} -- cgit v1.2.3