DASH  0.3.0
AllocatorTraits.h
1 #ifndef DASH__ALLOCATOR__ALLOCATOR_TRAITS_H__INCLUDED
2 #define DASH__ALLOCATOR__ALLOCATOR_TRAITS_H__INCLUDED
3 
4 #include <dash/Meta.h>
5 #include <dash/memory/MemorySpace.h>
6 
7 #include <memory>
8 
9 namespace dash {
10 
11 namespace detail {
12 
13 DASH__META__DEFINE_TRAIT__HAS_TYPE(local_pointer)
14 
15 template <class _Alloc, bool = has_type_local_pointer<_Alloc>::value>
16 struct allocator_traits_local_pointer {
17  typedef typename _Alloc::local_pointer type;
18 };
19 
20 template <class _Alloc>
21 struct allocator_traits_local_pointer<_Alloc, false> {
22  typedef typename std::allocator_traits<
23  typename _Alloc::local_allocator_type>::pointer type;
24 };
25 
26 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_local_pointer)
27 
28 template <class _Alloc, bool = has_type_const_local_pointer<_Alloc>::value>
29 struct allocator_traits_const_local_pointer {
30  typedef typename _Alloc::const_local_pointer type;
31 };
32 
33 template <class _Alloc>
34 struct allocator_traits_const_local_pointer<_Alloc, false> {
35  typedef typename std::allocator_traits<
36  typename _Alloc::local_allocator_type>::const_pointer type;
37 };
38 
39 DASH__META__DEFINE_TRAIT__HAS_TYPE(local_void_pointer)
40 
41 template <class _Alloc, bool = has_type_local_void_pointer<_Alloc>::value>
42 struct allocator_traits_local_void_pointer {
43  typedef typename _Alloc::local_void_pointer type;
44 };
45 
46 template <class _Alloc>
47 struct allocator_traits_local_void_pointer<_Alloc, false> {
48  typedef typename std::allocator_traits<
49  typename _Alloc::local_allocator_type>::void_pointer type;
50 };
51 
52 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_local_void_pointer)
53 
54 template <
55  class _Alloc,
56  bool = has_type_const_local_void_pointer<_Alloc>::value>
57 struct allocator_traits_const_local_void_pointer {
58  typedef typename _Alloc::const_local_void_pointer type;
59 };
60 
61 template <class _Alloc>
62 struct allocator_traits_const_local_void_pointer<_Alloc, false> {
63  typedef typename std::allocator_traits<
64  typename _Alloc::local_allocator_type>::const_void_pointer type;
65 };
66 
67 DASH__META__DEFINE_TRAIT__HAS_TYPE(pointer)
68 
69 template <class _Alloc, bool = has_type_pointer<_Alloc>::value>
70 struct allocator_traits_pointer {
71  typedef typename _Alloc::pointer type;
72 };
73 
74 template <class _Alloc>
75 struct allocator_traits_pointer<_Alloc, false> {
76  typedef dart_gptr_t type;
77 };
78 
79 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_pointer)
80 
81 template <class _Alloc, bool = has_type_const_pointer<_Alloc>::value>
82 struct allocator_traits_const_pointer {
83  typedef typename _Alloc::const_pointer type;
84 };
85 
86 template <class _Alloc>
87 struct allocator_traits_const_pointer<_Alloc, false> {
88  typedef const dart_gptr_t type;
89 };
90 
91 DASH__META__DEFINE_TRAIT__HAS_TYPE(void_pointer)
92 
93 template <class _Alloc, bool = has_type_void_pointer<_Alloc>::value>
94 struct allocator_traits_void_pointer {
95  typedef typename _Alloc::void_pointer type;
96 };
97 
98 template <class _Alloc>
99 struct allocator_traits_void_pointer<_Alloc, false> {
100  typedef dart_gptr_t type;
101 };
102 
103 DASH__META__DEFINE_TRAIT__HAS_TYPE(const_void_pointer)
104 
105 template <class _Alloc, bool = has_type_const_void_pointer<_Alloc>::value>
106 struct allocator_traits_const_void_pointer {
107  typedef typename _Alloc::const_void_pointer type;
108 };
109 
110 template <class _Alloc>
111 struct allocator_traits_const_void_pointer<_Alloc, false> {
112  typedef const dart_gptr_t type;
113 };
114 
115 DASH__META__DEFINE_TRAIT__HAS_TYPE(difference_type)
116 
117 template <class _Alloc, bool = has_type_difference_type<_Alloc>::value>
118 struct allocator_traits_difference_type {
119  typedef typename _Alloc::difference_type type;
120 };
121 
122 template <class _Alloc>
123 struct allocator_traits_difference_type<_Alloc, false> {
124  typedef dash::gptrdiff_t type;
125 };
126 
127 DASH__META__DEFINE_TRAIT__HAS_TYPE(size_type)
128 
129 template <class _Alloc, bool = has_type_size_type<_Alloc>::value>
130 struct allocator_traits_size_type {
131  typedef typename _Alloc::size_type type;
132 };
133 
134 template <class _Alloc>
135 struct allocator_traits_size_type<_Alloc, false> {
136  typedef dash::default_size_t type;
137 };
138 } // namespace detail
139 
140 template <class Alloc>
142  // Mandatory definitions
143  typedef Alloc allocator_type;
144  typedef typename Alloc::value_type value_type;
145 #if 0
146  typedef typename Alloc::allocation_policy allocation_policy;
147 #endif
148  typedef typename Alloc::local_allocator_type local_allocator;
149 
150  // Optional Definitions
151  typedef typename detail::allocator_traits_difference_type<Alloc>::type
152  difference_type;
153  typedef typename detail::allocator_traits_size_type<Alloc>::type size_type;
154 
155  // Global Allocator Traits
156  typedef typename detail::allocator_traits_pointer<Alloc>::type pointer;
157  typedef typename detail::allocator_traits_const_pointer<Alloc>::type
158  const_pointer;
159  typedef typename detail::allocator_traits_void_pointer<Alloc>::type
160  void_pointer;
161  typedef typename detail::allocator_traits_const_void_pointer<Alloc>::type
162  const_void_pointer;
163 
164  // Local Allocator Traits
165  typedef typename detail::allocator_traits_local_pointer<Alloc>::type
166  local_pointer;
167  typedef typename detail::allocator_traits_const_local_pointer<Alloc>::type
168  const_local_pointer;
169  typedef typename detail::allocator_traits_local_void_pointer<Alloc>::type
170  local_void_pointer;
171  typedef
172  typename detail::allocator_traits_const_local_void_pointer<Alloc>::type
173  const_local_void_pointer;
174 
175  template <class U>
176  using rebind_alloc = typename allocator_type::template rebind<U>;
177 
178  template <class U>
180 
181  static pointer allocate(allocator_type& a, size_type n)
182  {
183  return a.allocate(n);
184  }
185 
186  static void deallocate(allocator_type& a, pointer p, size_type n)
187  {
188  a.deallocate(p, n);
189  }
190 };
191 
192 } // namespace dash
193 
194 #endif // DASH__ALLOCATOR__ALLOCATOR_TRAITS_H__INCLUDED
internal::default_signed_index gptrdiff_t
Difference type for global pointers.
Definition: Types.h:74
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
Definition: Types.h:69
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
DART Global pointer type.
Definition: dart_globmem.h:77