summaryrefslogtreecommitdiff
path: root/common/accel-invoke.hpp
diff options
context:
space:
mode:
authora1xd <[email protected]>2021-09-22 20:49:04 -0400
committerGitHub <[email protected]>2021-09-22 20:49:04 -0400
commit8a4b6f57758338d5537d4671184099a4728a8cdd (patch)
treedf36529a344d5d21ff11f5ba021ec80afb4b68a4 /common/accel-invoke.hpp
parentMerge pull request #87 from matthewstrasiotto/streamer_mode (diff)
parentimprove converter + docs (diff)
downloadrawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.tar.xz
rawaccel-8a4b6f57758338d5537d4671184099a4728a8cdd.zip
Merge pull request #105 from a1xd/1.5.x
v1.5
Diffstat (limited to 'common/accel-invoke.hpp')
-rw-r--r--common/accel-invoke.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/common/accel-invoke.hpp b/common/accel-invoke.hpp
new file mode 100644
index 0000000..f2a95dc
--- /dev/null
+++ b/common/accel-invoke.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include "accel-union.hpp"
+
+namespace rawaccel {
+
+ class accel_invoker {
+ using callback_t = double (*)(const accel_union&, double, double);
+
+ callback_t cb = &invoke_impl<accel_noaccel>;
+
+ template <typename T>
+ static double invoke_impl(const accel_union& u, double x, double w)
+ {
+ return apply_weighted(reinterpret_cast<const T&>(u), x, w);
+ }
+
+ public:
+
+ accel_invoker(const accel_args& args)
+ {
+ cb = visit_accel([](auto&& arg) {
+ using T = remove_ref_t<decltype(arg)>;
+
+ if constexpr (is_same_v<T, motivity>) {
+ static_assert(sizeof motivity == sizeof binlog_lut);
+ return &invoke_impl<binlog_lut>;
+ }
+ else {
+ return &invoke_impl<T>;
+ }
+
+ }, make_mode(args), accel_union{});
+ }
+
+ accel_invoker() = default;
+
+ double invoke(const accel_union& u, double x, double weight = 1) const
+ {
+ return (*cb)(u, x, weight);
+ }
+ };
+
+ inline vec2<accel_invoker> invokers(const settings& args)
+ {
+ return {
+ accel_invoker(args.argsv.x),
+ accel_invoker(args.argsv.y)
+ };
+ }
+
+}