From 0ab40dc1ab4e689921da54080b135e1d22b1c586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 14 Mar 2017 21:45:23 +0100 Subject: Refactoring louloulibs and cmake Use OBJECT libraries Remove the louloulibs directory Write FOUND variables in the cache --- src/utils/timed_events.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/utils/timed_events.cpp (limited to 'src/utils/timed_events.cpp') diff --git a/src/utils/timed_events.cpp b/src/utils/timed_events.cpp new file mode 100644 index 0000000..5077199 --- /dev/null +++ b/src/utils/timed_events.cpp @@ -0,0 +1,47 @@ +#include + +TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, + std::function callback, const std::string& name): + time_point(std::move(time_point)), + callback(callback), + repeat(false), + repeat_delay(0), + name(name) +{ +} + +TimedEvent::TimedEvent(std::chrono::milliseconds&& duration, + std::function callback, const std::string& name): + time_point(std::chrono::steady_clock::now() + duration), + callback(callback), + repeat(true), + repeat_delay(std::move(duration)), + name(name) +{ +} + +bool TimedEvent::is_after(const TimedEvent& other) const +{ + return this->is_after(other.time_point); +} + +bool TimedEvent::is_after(const std::chrono::steady_clock::time_point& time_point) const +{ + return this->time_point > time_point; +} + +std::chrono::milliseconds TimedEvent::get_timeout() const +{ + auto diff = std::chrono::duration_cast(this->time_point - std::chrono::steady_clock::now()); + return std::max(diff, 0ms); +} + +void TimedEvent::execute() const +{ + this->callback(); +} + +const std::string& TimedEvent::get_name() const +{ + return this->name; +} -- cgit v1.2.3 From 5402a256d1f0ebbeafa32d250d000cf38fe748fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 7 Apr 2017 18:45:24 +0200 Subject: Apply all the clang-tidy modernize-* fixes --- src/utils/timed_events.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/utils/timed_events.cpp') diff --git a/src/utils/timed_events.cpp b/src/utils/timed_events.cpp index 5077199..e35a659 100644 --- a/src/utils/timed_events.cpp +++ b/src/utils/timed_events.cpp @@ -1,22 +1,23 @@ +#include #include TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, - std::function callback, const std::string& name): + std::function callback, std::string name): time_point(std::move(time_point)), - callback(callback), + callback(std::move(callback)), repeat(false), repeat_delay(0), - name(name) + name(std::move(name)) { } TimedEvent::TimedEvent(std::chrono::milliseconds&& duration, - std::function callback, const std::string& name): + std::function callback, std::string name): time_point(std::chrono::steady_clock::now() + duration), - callback(callback), + callback(std::move(callback)), repeat(true), repeat_delay(std::move(duration)), - name(name) + name(std::move(name)) { } -- cgit v1.2.3 From ccb4ee098f0416ab47a46650705dba6495e8bec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Fri, 7 Apr 2017 18:53:12 +0200 Subject: Apply all the clang-tidy misc-* fixes --- src/utils/timed_events.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/utils/timed_events.cpp') diff --git a/src/utils/timed_events.cpp b/src/utils/timed_events.cpp index e35a659..26ded82 100644 --- a/src/utils/timed_events.cpp +++ b/src/utils/timed_events.cpp @@ -3,7 +3,7 @@ TimedEvent::TimedEvent(std::chrono::steady_clock::time_point&& time_point, std::function callback, std::string name): - time_point(std::move(time_point)), + time_point(time_point), callback(std::move(callback)), repeat(false), repeat_delay(0), @@ -16,7 +16,7 @@ TimedEvent::TimedEvent(std::chrono::milliseconds&& duration, time_point(std::chrono::steady_clock::now() + duration), callback(std::move(callback)), repeat(true), - repeat_delay(std::move(duration)), + repeat_delay(duration), name(std::move(name)) { } -- cgit v1.2.3