argument.hpp 799 Bytes
Newer Older
Paul's avatar
Paul committed
1
2
3
4
5
6
7
8
9
10
#ifndef GUARD_RTGLIB_ARGUMENT_HPP
#define GUARD_RTGLIB_ARGUMENT_HPP

#include <rtg/shape.hpp>
#include <functional>

namespace rtg {

struct argument
{
Paul's avatar
Paul committed
11
12
13
14
15
16
17
    argument()
    {}

    argument(shape s, std::function<char*()> d)
    : data(d), shape_(s)
    {}

Paul's avatar
Paul committed
18
    std::function<char*()> data;
Paul's avatar
Paul committed
19
20
21
22
23
24
25
26
27
28
29
30
31

    const shape& get_shape() const
    {
        return this->shape_;
    }

    template<class Visitor>
    void visit_at(Visitor v, std::size_t n=0) const
    {
        shape_.visit_type([&](auto as) {
            v(*(as.from(this->data())+shape_.index(n)));
        });
    }
Paul's avatar
Paul committed
32
33
34
35

    template<class Visitor>
    void visit(Visitor v) const
    {
Paul's avatar
Paul committed
36
37
        shape_.visit_type([&](auto as) {
            v(make_view(this->shape_, as.from(this->data())));
Paul's avatar
Paul committed
38
39
        });
    }
Paul's avatar
Paul committed
40
41
private:
    shape shape_;
Paul's avatar
Paul committed
42
43
44
45
46
};

}

#endif