From d361f57c8064ce13a0478653050b169dc94e2e99 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 18 Jan 2018 19:35:08 +0100 Subject: compat/util: retire Adjust usages. --- compat/check-visible.hpp | 2 +- compat/clamp.hpp | 54 ---------------------------- compat/correlation-calibrator.cpp | 2 +- compat/library-path.hpp | 4 +++ compat/macros.hpp | 4 --- compat/math-imports.hpp | 8 ++--- compat/math.hpp | 74 +++++++++++++++++++++++++++++++++++++++ compat/meta.hpp | 5 +++ compat/round.hpp | 15 -------- compat/timer.hpp | 8 ++--- compat/util.hpp | 10 ------ 11 files changed, 90 insertions(+), 96 deletions(-) delete mode 100644 compat/clamp.hpp create mode 100644 compat/library-path.hpp create mode 100644 compat/math.hpp delete mode 100644 compat/round.hpp delete mode 100644 compat/util.hpp (limited to 'compat') diff --git a/compat/check-visible.hpp b/compat/check-visible.hpp index f5420a39..a0211982 100644 --- a/compat/check-visible.hpp +++ b/compat/check-visible.hpp @@ -1,7 +1,7 @@ #pragma once #include "export.hpp" -#include "util.hpp" +#include "macros.hpp" #include diff --git a/compat/clamp.hpp b/compat/clamp.hpp deleted file mode 100644 index 8141e25f..00000000 --- a/compat/clamp.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once - -#include -#include - -#include "macros.hpp" - -namespace util_detail { - -template -inline auto clamp_float(n val, n min_, n max_) -{ - return std::fmin(std::fmax(val, min_), max_); -} - -template -struct clamp final -{ - static inline auto clamp_(const n& val, const n& min_, const n& max_) - { - if (unlikely(val > max_)) - return max_; - if (unlikely(val < min_)) - return min_; - return val; - } -}; - -template -struct clamp -{ - static inline auto clamp_(float val, float min_, float max_) - { - return clamp_float(val, min_, max_); - } -}; - -template -struct clamp -{ - static inline auto clamp_(double val, double min_, double max_) - { - return clamp_float(val, min_, max_); - } -}; - -} // ns util_detail - -template -inline auto clamp(const t& val, const u& min, const w& max) -{ - using tp = decltype(val + min + max); - return ::util_detail::clamp, tp>::clamp_(val, min, max); -} diff --git a/compat/correlation-calibrator.cpp b/compat/correlation-calibrator.cpp index 1d3339d3..aef804d2 100644 --- a/compat/correlation-calibrator.cpp +++ b/compat/correlation-calibrator.cpp @@ -1,6 +1,6 @@ #include "correlation-calibrator.hpp" #include "variance.hpp" -#include "util.hpp" +#include "compat/math.hpp" #include #include diff --git a/compat/library-path.hpp b/compat/library-path.hpp new file mode 100644 index 00000000..e14cf5e0 --- /dev/null +++ b/compat/library-path.hpp @@ -0,0 +1,4 @@ +#pragma once + +// from build directory +#include "__opentrack-library-path.h" diff --git a/compat/macros.hpp b/compat/macros.hpp index d51bace7..766730db 100644 --- a/compat/macros.hpp +++ b/compat/macros.hpp @@ -71,7 +71,3 @@ # define unlikely(x) (x) #endif -#define progn(...) (([&]() { __VA_ARGS__ })()) -#define prog1(x, ...) (([&]() { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })()) - -#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false) diff --git a/compat/math-imports.hpp b/compat/math-imports.hpp index 4d8d5a5f..67b7e6ed 100644 --- a/compat/math-imports.hpp +++ b/compat/math-imports.hpp @@ -1,11 +1,5 @@ #pragma once -template -static inline constexpr auto signum(T x) -{ - return x < T(0) ? -1 : 1; -} - #include using std::copysign; @@ -51,3 +45,5 @@ using std::uint8_t; using std::min; using std::max; + +#include "math.hpp" diff --git a/compat/math.hpp b/compat/math.hpp new file mode 100644 index 00000000..5d80dace --- /dev/null +++ b/compat/math.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include "macros.hpp" + +#include +#include + +namespace util_detail { + +template +inline auto clamp_float(n val, n min_, n max_) +{ + return std::fmin(std::fmax(val, min_), max_); +} + +template +struct clamp final +{ + static inline auto clamp_(const n& val, const n& min_, const n& max_) + { + if (unlikely(val > max_)) + return max_; + if (unlikely(val < min_)) + return min_; + return val; + } +}; + +template +struct clamp +{ + static inline auto clamp_(float val, float min_, float max_) + { + return clamp_float(val, min_, max_); + } +}; + +template +struct clamp +{ + static inline auto clamp_(double val, double min_, double max_) + { + return clamp_float(val, min_, max_); + } +}; + +} // ns util_detail + +template +inline auto clamp(const t& val, const u& min, const w& max) +{ + using tp = decltype(val + min + max); + return ::util_detail::clamp, tp>::clamp_(val, min, max); +} + +template +inline int iround(const t& val) +{ + return int(std::round(val)); +} + +template +inline unsigned uround(const t& val) +{ + return std::round(std::fmax(t(0), val)); +} + +#include "macros.hpp" + +template +static force_inline constexpr auto signum(T x) +{ + return x < T(0) ? -1 : 1; +} diff --git a/compat/meta.hpp b/compat/meta.hpp index ce81b3d0..80eca89a 100644 --- a/compat/meta.hpp +++ b/compat/meta.hpp @@ -12,6 +12,11 @@ template using cv_qualified = std::conditional_t>, std::decay_t, const t&>; +#define progn(...) (([&]() { __VA_ARGS__ })()) +#define prog1(x, ...) (([&]() { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })()) + +#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false) + #if 0 #include diff --git a/compat/round.hpp b/compat/round.hpp deleted file mode 100644 index 90a0ccb3..00000000 --- a/compat/round.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -template -inline int iround(const t& val) -{ - return int(std::round(val)); -} - -template -inline unsigned uround(const t& val) -{ - return std::round(std::fmax(t(0), val)); -} diff --git a/compat/timer.hpp b/compat/timer.hpp index ac255a9d..a92d3f68 100644 --- a/compat/timer.hpp +++ b/compat/timer.hpp @@ -9,6 +9,9 @@ #pragma once #include "export.hpp" +#include "time.hpp" + +#include #if defined (_WIN32) # include @@ -17,11 +20,6 @@ # include #endif -#include - -#include "time.hpp" -#include "util.hpp" - class OTR_COMPAT_EXPORT Timer final { struct timespec state; diff --git a/compat/util.hpp b/compat/util.hpp deleted file mode 100644 index dda947e5..00000000 --- a/compat/util.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "opentrack-library-path.h" -#include "run-in-thread.hpp" -#include "meta.hpp" -#include "macros.hpp" -#include "round.hpp" -#include "clamp.hpp" - -#include -- cgit v1.2.3