From cd92baae3f0de8b841b5bbfdb02e4fa95acd52c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 7 Mar 2017 18:27:27 +0100 Subject: Little refactor in timed_events Also makes the coverage code deterministic --- louloulibs/utils/timed_events.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'louloulibs/utils/timed_events.cpp') diff --git a/louloulibs/utils/timed_events.cpp b/louloulibs/utils/timed_events.cpp index 68d009c..5077199 100644 --- a/louloulibs/utils/timed_events.cpp +++ b/louloulibs/utils/timed_events.cpp @@ -32,10 +32,8 @@ bool TimedEvent::is_after(const std::chrono::steady_clock::time_point& time_poin std::chrono::milliseconds TimedEvent::get_timeout() const { - auto now = std::chrono::steady_clock::now(); - if (now > this->time_point) - return std::chrono::milliseconds(0); - return std::chrono::duration_cast(this->time_point - now); + auto diff = std::chrono::duration_cast(this->time_point - std::chrono::steady_clock::now()); + return std::max(diff, 0ms); } void TimedEvent::execute() const -- cgit v1.2.3 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 --- louloulibs/utils/timed_events.cpp | 47 --------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 louloulibs/utils/timed_events.cpp (limited to 'louloulibs/utils/timed_events.cpp') diff --git a/louloulibs/utils/timed_events.cpp b/louloulibs/utils/timed_events.cpp deleted file mode 100644 index 5077199..0000000 --- a/louloulibs/utils/timed_events.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#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