DASH  0.3.0
ViewTraits.h
1 #ifndef DASH__VIEW__VIEW_TRAITS_H__INCLUDED
2 #define DASH__VIEW__VIEW_TRAITS_H__INCLUDED
3 
4 #include <type_traits>
5 
6 #include <dash/Meta.h>
7 #include <dash/Range.h>
8 
9 
10 namespace dash {
11 
12 #ifdef DOXYGEN
13 
21 template <class Viewable>
22 constexpr typename Viewable::domain_type &
23 domain(const Viewable & v);
24 
30 template <class ViewT>
32 {
33  typedef typename ViewT::domain_type domain_type;
34  typedef typename ViewT::image_type image_type;
35  typedef typename ViewT::origin_type origin_type;
36  typedef typename ViewT::local_type local_type;
37  typedef typename ViewT::global_type global_type;
38 
39  typedef std::integral_constant<dim_t, value> rank;
40 
41  typedef std::integral_constant<bool, value> is_origin;
42  typedef std::integral_constant<bool, value> is_view;
43  typedef std::integral_constant<bool, value> is_projection;
44  typedef std::integral_constant<bool, value> is_local;
45 };
46 
47 #else // DOXYGEN
48 
49 template <class ViewableType>
50 struct view_traits;
51 
52 template <class ViewType>
53 class IndexSetIdentity;
54 
55 namespace detail {
61  DASH__META__DEFINE_TRAIT__HAS_TYPE(domain_type)
62  DASH__META__DEFINE_TRAIT__HAS_TYPE(index_set_type)
63 }
64 
70 template <class ViewableType>
71 // struct is_view : dash::detail::has_type_domain_type<ViewableType> { };
72 struct is_view : dash::detail::has_type_index_set_type<ViewableType> { };
73 
74 
75 
76 namespace detail {
77 
78  // ------------------------------------------------------------------------
79 
80  template <
81  class ViewableType,
82  bool IsView,
83  bool IsRange >
84  struct _view_traits { };
85 
89  template <class ViewT>
90  struct _view_traits<
91  ViewT,
92  true, // is view
93  true // is range
94  >
95  {
96  typedef std::integral_constant<bool, false> is_projection;
97  typedef std::integral_constant<bool, true> is_view;
99  typedef std::integral_constant<bool, false> is_origin;
100 
101  typedef typename ViewT::index_type index_type;
102  typedef typename ViewT::size_type size_type;
103  typedef typename ViewT::index_set_type index_set_type;
104  typedef typename ViewT::domain_type domain_type;
105  typedef std::integral_constant<bool,
106  // either view type is local:
107  ViewT::is_local::value ||
108  // or view domain type is local:
109  _view_traits<domain_type,
110  dash::is_view<domain_type>::value,
112  >::is_local::value > is_local;
113 
114  typedef typename ViewT::local_type local_type;
115  typedef typename ViewT::global_type global_type;
116  typedef typename std::conditional<is_local::value,
117  local_type,
118  global_type >::type image_type;
119  typedef typename dash::view_traits<domain_type>::origin_type origin_type;
120 
121  typedef std::integral_constant<dim_t, ViewT::rank::value> rank;
122 
124  pattern_type;
125  };
126 
130  template <class ContainerT>
131  struct _view_traits<
132  ContainerT,
133  false, // is view
134  true // is range
135  >
136  {
137  typedef ContainerT origin_type;
138  typedef ContainerT domain_type;
139  typedef ContainerT image_type;
140  typedef ContainerT global_type;
141  typedef typename ContainerT::local_type local_type;
142  typedef typename ContainerT::index_type index_type;
143  typedef typename ContainerT::size_type size_type;
144  typedef typename dash::IndexSetIdentity<ContainerT> index_set_type;
145 
146  typedef typename ContainerT::pattern_type pattern_type;
147 
150  typedef std::integral_constant<bool, false> is_projection;
151  typedef std::integral_constant<bool, false> is_view;
153  typedef std::integral_constant<bool, true> is_origin;
157  typedef std::integral_constant<bool, std::is_same<
158  ContainerT,
159  typename ContainerT::local_type
160  >::value > is_local;
161 
162  typedef std::integral_constant<dim_t,
163  ContainerT::rank::value> rank;
164  };
165 
166 } // namespace detail
167 
172 template <class ViewableType>
173 struct view_traits
174 : detail::_view_traits<
175  ViewableType,
176  dash::is_view<ViewableType>::value,
177  dash::is_range<ViewableType>::value > {
178 };
179 
180 #endif // DOXYGEN
181 
182 } // namespace dash
183 
184 #endif // DASH__VIEW__VIEW_TRAITS_H__INCLUDED
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
Definition: Types.h:39
View type traits.
Definition: ViewTraits.h:31
Definition of type trait dash::is_range<T> with static member value indicating whether type T is a mo...
Definition: Range.h:243
constexpr auto domain(ViewT &&view) -> typename std::enable_if< dash::detail::has_type_domain_type< ViewValueT >::value, decltype(std::forward< ViewT >(view).domain()) >::type
Definition: Domain.h:23