summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-06-10 12:50:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-06-10 12:50:25 +0200
commitd415d383db1e1cf8038ffb34459864e3b6e19f39 (patch)
tree888cfaaab4733269b4342ea0337460f774c87023 /compat
parent1a4ad209341b7ef2364f7b6bc8195a4ac93838d0 (diff)
minor cleanup only
Diffstat (limited to 'compat')
-rw-r--r--compat/time.hpp8
-rw-r--r--compat/timer.hpp16
-rw-r--r--compat/util.hpp2
3 files changed, 21 insertions, 5 deletions
diff --git a/compat/time.hpp b/compat/time.hpp
index b560da70..c07f29cb 100644
--- a/compat/time.hpp
+++ b/compat/time.hpp
@@ -1,10 +1,12 @@
#pragma once
+#include "compat/functional.hpp"
+
#include <chrono>
namespace time_units {
-template<typename repr, typename ratio>
+template<typename repr, typename ratio = std::ratio<1>>
using duration = std::chrono::duration<repr, ratio>;
template<typename t, typename u>
@@ -13,8 +15,8 @@ static inline constexpr auto time_cast(const u& in)
return std::chrono::duration_cast<t>(in);
}
-using secs = duration<double, std::ratio<1, 1>>;
-using secs_ = duration<long long, std::ratio<1, 1>>;
+using secs = duration<double>;
+using secs_ = duration<long>;
using ms = duration<double, std::milli>;
using ms_ = duration<long long, std::milli>;
using us = duration<double, std::micro>;
diff --git a/compat/timer.hpp b/compat/timer.hpp
index 6af7430d..ac255a9d 100644
--- a/compat/timer.hpp
+++ b/compat/timer.hpp
@@ -20,6 +20,7 @@
#include <ctime>
#include "time.hpp"
+#include "util.hpp"
class OTR_COMPAT_EXPORT Timer final
{
@@ -43,7 +44,20 @@ public:
t elapsed() const
{
using namespace time_units;
- return static_cast<const t&>(ns(elapsed_nsecs()));
+ return time_cast<t>(ns(elapsed_nsecs()));
+ }
+
+ template<typename t>
+ bool is_elapsed(const t& time_value)
+ {
+ using namespace time_units;
+
+ if (unlikely(elapsed<ns>() >= time_value))
+ {
+ start();
+ return true;
+ }
+ return false;
}
long long elapsed_nsecs() const;
diff --git a/compat/util.hpp b/compat/util.hpp
index 823b83d1..3a53e203 100644
--- a/compat/util.hpp
+++ b/compat/util.hpp
@@ -12,7 +12,7 @@
#include <QSharedPointer>
#include <QDebug>
-#define progn(...) ([&]() { __VA_ARGS__ }())
+#define progn(...) (([&]() { __VA_ARGS__ })())
#define prog1(x, ...) (([&]() { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })())
#define once_only(...) progn(static bool once = false; if (!once) { once = true; __VA_ARGS__; })