summaryrefslogtreecommitdiff
path: root/common/accel-invoke.hpp
blob: f2a95dc5fb16869f684e95638748ff9f0ef65428 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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)
        };
    }

}