AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
Access.hpp
1#pragma once
2
3#include <dune/common/typeutilities.hh>
4#include <dune/functions/backends/istlvectorbackend.hh>
5
6namespace AMDiS {
7namespace Traits {
8
10struct Access
11{
12private:
13 // if C implements the vector facade interface
14 template <class C, class MI>
15 auto operator()(C const& c, MI const& mi, Dune::PriorityTag<3>) const
16 -> decltype(c.get(mi))
17 {
18 return c.get(mi);
19 }
20
21 // if C supports multi-index access
22 template <class C, class MI>
23 auto operator()(C const& c, MI const& mi, Dune::PriorityTag<2>) const
24 -> decltype(c[mi])
25 {
26 return c[mi];
27 }
28
29 // if C implements the vector facade interface
30 template <class C, class MI>
31 auto operator()(C const& c, MI const& mi, Dune::PriorityTag<1>) const
32 -> decltype(c.at(mi))
33 {
34 return c.at(mi);
35 }
36
37 // fallback implementation for simple vectors
38 template <class C, class MI>
39 auto operator()(C const& c, MI const& mi, Dune::PriorityTag<0>) const
40 -> decltype(Dune::Functions::istlVectorBackend(c)[mi])
41 {
42 return Dune::Functions::istlVectorBackend(c)[mi];
43 }
44
45public:
46 template <class C, class MI>
47 auto operator()(C const& c, MI const& mi) const
48 {
49 return (*this)(c,mi,Dune::PriorityTag<5>{});
50 }
51};
52
53}} // end namespace AMDiS::Traits
Unified accessor class.
Definition: Access.hpp:11