NGen
Loading...
Searching...
No Matches
visitors.hpp
1#ifndef NGEN_IO_MDFRAME_VISITORS_HPP
2#define NGEN_IO_MDFRAME_VISITORS_HPP
3
4#include "mdarray/mdarray.hpp"
5#include <boost/variant.hpp>
6#include <boost/core/span.hpp>
7#include <traits.hpp>
8
9namespace ngen {
10namespace detail {
11namespace visitors {
12
17 : public boost::static_visitor<std::size_t>
18{
19 template<typename T>
20 auto operator()(const mdarray<T>& md_array) const noexcept
21 {
22 return md_array.size();
23 }
24};
25
30 : public boost::static_visitor<std::size_t>
31{
32 template<typename T>
33 auto operator()(const mdarray<T>& arr) const noexcept
34 {
35 return arr.rank();
36 }
37};
38
43 : public boost::static_visitor<boost::span<const std::size_t>>
44{
45 template<typename T>
46 auto operator()(const mdarray<T>& arr) const noexcept
47 {
48 return arr.shape();
49 }
50};
51
56 : public boost::static_visitor<void>
57{
58 template<typename T>
59 void operator()(T& arr, boost::span<const std::size_t> index, typename T::value_type value)
60 {
61 arr.insert(index, value);
62 }
63};
64
68template<typename... SupportedTypes>
70 : public boost::static_visitor<
71 typename traits::type_list<SupportedTypes...>::variant_scalar
72 >
73{
74 template<typename T>
75 typename T::value_type operator()(const T& arr, const boost::span<const std::size_t> index) const
76 {
77 return arr.at(index);
78 }
79};
80
81// Apply std::to_string as a visitor
82struct to_string_visitor : public boost::static_visitor<std::string>
83{
84 template<typename T>
85 std::string operator()(const T& v) const
86 {
87 return std::to_string(v);
88 }
89};
90
91
92} // namespace visitors
93} // namespace detail
94} // namespace ngen
95
96#endif // NGEN_IO_MDFRAME_VISITORS_HPP
Definition mdarray.hpp:13
Definition DomainLayer.hpp:9
mdarray visitor for indexed access
Definition visitors.hpp:73
T::value_type operator()(const T &arr, const boost::span< const std::size_t > index) const
Definition visitors.hpp:75
mdarray visitor for inserting a value
Definition visitors.hpp:57
void operator()(T &arr, boost::span< const std::size_t > index, typename T::value_type value)
Definition visitors.hpp:59
mdarray visitor for retrieving the rank of the mdarray
Definition visitors.hpp:31
auto operator()(const mdarray< T > &arr) const noexcept
Definition visitors.hpp:33
mdarray visitor for retrieving the shape of the mdarray
Definition visitors.hpp:44
auto operator()(const mdarray< T > &arr) const noexcept
Definition visitors.hpp:46
mdarray visitor for retrieving the size of the mdarray
Definition visitors.hpp:18
auto operator()(const mdarray< T > &md_array) const noexcept
Definition visitors.hpp:20
std::string operator()(const T &v) const
Definition visitors.hpp:85