dune-pdelab  2.0.0
decorator.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 
4 #ifndef DUNE_PDELAB_ORDERING_DECORATOR_HH
5 #define DUNE_PDELAB_ORDERING_DECORATOR_HH
6 
7 #include <dune/typetree/typetree.hh>
8 
12 
13 namespace Dune {
14  namespace PDELab {
15 
18 
19  namespace ordering {
20 
21 #ifndef DOXYGEN
22 
23  // Forward declaration for is_decorated specialization
24  template<typename D, typename U>
26 
27  namespace impl {
28 
29  struct is_decorated
30  {};
31 
32  template<typename DecoratedOrderingTag, std::size_t level>
33  struct basetag_access_provider
34  {};
35 
36  // provide access to the base tag for disambiguation of member
37  // accesses in case those are overloaded by a decorator.
38  template<typename D, typename U>
39  struct basetag_access_provider<decorated_ordering_tag<D,U>,0>
40  : public is_decorated
41  {
42  typedef U BaseTag;
43 
44  const BaseTag& baseTag() const
45  {
46  return static_cast<decorated_ordering_tag<D,U>& >(*this);
47  }
48 
49  BaseTag& baseTag()
50  {
51  return static_cast<decorated_ordering_tag<D,U>& >(*this);
52  }
53 
54  };
55 
56  template<typename T, T v>
57  struct lazy_constant
58  {
59  typedef integral_constant<T,v> type;
60  };
61 
62  template<typename D>
63  struct lazy_level
64  {
65  typedef integral_constant<std::size_t,D::level> type;
66  };
67 
68  template<typename D>
69  struct decoration_level
70  : public conditional<
71  is_base_of<is_decorated, D>::value,
72  lazy_level<D>,
73  lazy_constant<std::size_t,0>
74  >::type::type
75  {};
76 
77  } // namespace impl
78 
79 #endif // DOXYGEN
80 
81  template<typename D, typename U>
83  : U
84  , impl::basetag_access_provider<decorated_ordering_tag<D,U>,impl::decoration_level<U>::value>
85  {
86 
87  typedef D Decorator;
88  typedef U Undecorated;
89 
90  static const std::size_t level = impl::decoration_level<U>::value + 1;
91 
93  {}
94 
96  : Undecorated(u)
97  {}
98 
99 #if HAVE_RVALUE_REFERENCES
100 
102  : Undecorated(std::move(u))
103  {}
104 
105 #endif // HAVE_RVALUE_REFERENCES
106 
107  };
108 
109 
110  template<typename GFS,typename Transformation,typename Undecorated,typename GlueTag, typename Tag>
112  : public TypeTree::meta_function
113  {
114  typedef DUNE_DECLTYPE(
116  TypeTree::declptr<GFS>(), // the source GridFunctionSpace
117  TypeTree::declptr<Transformation>(), // the full transformation descriptor
118  TypeTree::declptr<Undecorated>(), // the type of the undecorated Ordering to be wrapped in the decorator
119  TypeTree::declptr<GlueTag>(), // the decorated_ordering_tag for the current decoration nesting level
120  TypeTree::declptr<Tag>() // the decorator tag
121  )
122  ) type;
123  };
124 
125 
126  template<typename GFS, typename Transformation, typename OrderingTag>
128  {
129 
130  static const bool recursive = false;
131 
132  typedef typename leaf_gfs_to_ordering_descriptor<
133  GFS,
134  Transformation,
135  typename OrderingTag::Undecorated
137 
138  typedef typename undecorated_descriptor::transformed_type undecorated_type;
139 
140  typedef typename gfs_to_decorator_descriptor<
141  GFS,
142  Transformation,
144  OrderingTag,
145  typename OrderingTag::Decorator
147 
148  typedef typename decorator_descriptor::transformed_type transformed_type;
149  typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
150 
151  static transformed_type transform(const GFS& gfs, const Transformation& t)
152  {
153  return decorator_descriptor::transform(gfs,t,make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
154  }
155 
156  static transformed_storage_type transform(shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
157  {
158  return decorator_descriptor::transform(gfs_pointer,t,undecorated_descriptor::transform(gfs_pointer,t));
159  }
160 
161  };
162 
163  template<typename GFS, typename Transformation, typename D, typename U>
164  leaf_gfs_to_decorated<GFS,Transformation,decorated_ordering_tag<D,U> >
165  register_leaf_gfs_to_ordering_descriptor(GFS*,Transformation*,decorated_ordering_tag<D,U>*);
166 
167 
168  template<typename GFS, typename Transformation, typename OrderingTag>
170  {
171 
172  static const bool recursive = true;
173 
174  template<typename TC>
175  struct result
176  {
177 
178  typedef typename power_gfs_to_ordering_descriptor<
179  GFS,
180  Transformation,
181  typename OrderingTag::Undecorated
183 
184  typedef typename undecorated_descriptor::template result<TC>::type undecorated_type;
185  typedef typename gfs_to_decorator_descriptor<
186  GFS,
187  Transformation,
189  OrderingTag,
190  typename OrderingTag::Decorator
192 
193  typedef typename decorator_descriptor::transformed_type type;
194  typedef typename decorator_descriptor::transformed_storage_type storage_type;
195 
196  };
197 
198  template<typename TC>
199  static typename result<TC>::type transform(const GFS& gfs, const Transformation& t, const array<shared_ptr<TC>,GFS::CHILDREN>& children)
200  {
202  }
203 
204  template<typename TC>
205  static typename result<TC>::storage_type transform_storage(shared_ptr<const GFS> gfs_pointer, const Transformation& t, const array<shared_ptr<TC>,GFS::CHILDREN>& children)
206  {
208  }
209 
210  };
211 
212 
213  template<typename GFS, typename Transformation, typename OrderingTag>
215  {
216 
217  static const bool recursive = false;
218 
219  typedef typename power_gfs_to_ordering_descriptor<
220  GFS,
221  Transformation,
222  typename OrderingTag::Undecorated
224 
225  typedef typename undecorated_descriptor::transformed_type undecorated_type;
226 
227  typedef typename gfs_to_decorator_descriptor<
228  GFS,
229  Transformation,
231  OrderingTag,
232  typename OrderingTag::Decorator
234 
235  typedef typename decorator_descriptor::transformed_type transformed_type;
236  typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
237 
238  static transformed_type transform(const GFS& gfs, const Transformation& t)
239  {
240  return decorator_descriptor::transform(gfs,t,make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
241  }
242 
243  static transformed_storage_type transform(shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
244  {
245  return decorator_descriptor::transform(gfs_pointer,t,undecorated_descriptor::transform(gfs_pointer,t));
246  }
247 
248  };
249 
250 
251  template<typename GFS, typename Transformation, typename OrderingTag>
253  : public std::conditional<
254  power_gfs_to_ordering_descriptor<
255  GFS,
256  Transformation,
257  typename OrderingTag::Undecorated
258  >::type::recursive,
259  recursive_power_gfs_to_decorated<
260  GFS,
261  Transformation,
262  OrderingTag
263  >,
264  nonrecursive_power_gfs_to_decorated<
265  GFS,
266  Transformation,
267  OrderingTag>
268  >::type
269  {};
270 
271  template<typename GFS, typename Transformation, typename D, typename U>
273  GFS,
274  Transformation,
276  >
278 
279 
280 
281 
282 
283 
284  template<typename GFS, typename Transformation, typename OrderingTag>
286  {
287 
288  static const bool recursive = true;
289 
290  template<typename... TC>
291  struct result
292  {
293 
294  typedef typename composite_gfs_to_ordering_descriptor<
295  GFS,
296  Transformation,
297  typename OrderingTag::Undecorated
299 
300  typedef typename undecorated_descriptor::template result<TC...>::type undecorated_type;
301  typedef typename gfs_to_decorator_descriptor<
302  GFS,
303  Transformation,
305  OrderingTag,
306  typename OrderingTag::Decorator
308 
309  typedef typename decorator_descriptor::transformed_type type;
310  typedef typename decorator_descriptor::transformed_storage_type storage_type;
311 
312  };
313 
314  template<typename... TC>
315  static typename result<TC...>::type transform(const GFS& gfs, const Transformation& t, shared_ptr<TC>... children)
316  {
318  }
319 
320  template<typename... TC>
321  static typename result<TC...>::storage_type transform_storage(shared_ptr<const GFS> gfs_pointer, const Transformation& t, shared_ptr<TC>... children)
322  {
324  }
325 
326  };
327 
328 
329  template<typename GFS, typename Transformation, typename OrderingTag>
331  {
332 
333  static const bool recursive = false;
334 
335  typedef typename composite_gfs_to_ordering_descriptor<
336  GFS,
337  Transformation,
338  typename OrderingTag::Undecorated
340 
341  typedef typename undecorated_descriptor::transformed_type undecorated_type;
342 
343  typedef typename gfs_to_decorator_descriptor<
344  GFS,
345  Transformation,
347  OrderingTag,
348  typename OrderingTag::Decorator
350 
351  typedef typename decorator_descriptor::transformed_type transformed_type;
352  typedef typename decorator_descriptor::transformed_storage_type transformed_storage_type;
353 
354  static transformed_type transform(const GFS& gfs, const Transformation& t)
355  {
356  return decorator_descriptor::transform(gfs,t,make_shared<undecorated_type>(undecorated_descriptor::transform(gfs,t)));
357  }
358 
359  static transformed_storage_type transform(shared_ptr<const GFS>& gfs_pointer, const Transformation& t)
360  {
361  return decorator_descriptor::transform(gfs_pointer,t,undecorated_descriptor::transform(gfs_pointer,t));
362  }
363 
364  };
365 
366 
367  template<typename GFS, typename Transformation, typename OrderingTag>
369  : public std::conditional<
370  composite_gfs_to_ordering_descriptor<
371  GFS,
372  Transformation,
373  typename OrderingTag::Undecorated
374  >::type::recursive,
375  recursive_composite_gfs_to_decorated<
376  GFS,
377  Transformation,
378  OrderingTag
379  >,
380  nonrecursive_composite_gfs_to_decorated<
381  GFS,
382  Transformation,
383  OrderingTag>
384  >::type
385  {};
386 
387 
388  template<typename GFS, typename Transformation, typename D, typename U>
391 
392  } // namespace ordering
393 
395 
396  } // namespace PDELab
397 } // namespace Dune
398 
399 #endif // DUNE_PDELAB_ORDERING_DECORATOR_HH
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:341
decorator_descriptor::transformed_storage_type storage_type
Definition: decorator.hh:310
undecorated_descriptor::template result< TC >::type undecorated_type
Definition: decorator.hh:184
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:138
undecorated_descriptor::transformed_type undecorated_type
Definition: decorator.hh:225
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:238
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:351
static result< TC >::storage_type transform_storage(shared_ptr< const GFS > gfs_pointer, const Transformation &t, const array< shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: decorator.hh:205
decorator_descriptor::transformed_storage_type storage_type
Definition: decorator.hh:194
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:148
decorated_ordering_tag()
Definition: decorator.hh:92
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typename OrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:349
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typename OrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:233
static transformed_storage_type transform(shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:243
composite_gfs_to_ordering_descriptor< GFS, Transformation, typename OrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:339
static result< TC...>::storage_type transform_storage(shared_ptr< const GFS > gfs_pointer, const Transformation &t, shared_ptr< TC >...children)
Definition: decorator.hh:321
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typename OrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:146
undecorated_descriptor::template result< TC...>::type undecorated_type
Definition: decorator.hh:300
decorator_descriptor::transformed_type transformed_type
Definition: decorator.hh:235
static const bool recursive
Definition: decorator.hh:172
static result< TC >::type transform(const GFS &gfs, const Transformation &t, const array< shared_ptr< TC >, GFS::CHILDREN > &children)
Definition: decorator.hh:199
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:236
leaf_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_leaf_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:149
D Decorator
Definition: decorator.hh:87
U Undecorated
Definition: decorator.hh:88
static const bool recursive
Definition: decorator.hh:288
gfs_to_permuted< GFS, Transformation, Undecorated, GlueTag > register_gfs_to_decorator_descriptor(GFS *, Transformation *, Undecorated *, GlueTag *, Permuted< UndecoratedTag > *)
composite_gfs_to_ordering_descriptor< GFS, Transformation, typename OrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:298
static const bool recursive
Definition: decorator.hh:333
power_gfs_to_ordering_descriptor< GFS, Transformation, typename OrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:182
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:151
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typename OrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:191
decorator_descriptor::transformed_storage_type transformed_storage_type
Definition: decorator.hh:352
decorator_descriptor::transformed_type type
Definition: decorator.hh:193
static const unsigned int value
Definition: gridfunctionspace/tags.hh:175
leaf_gfs_to_ordering_descriptor< GFS, Transformation, typename OrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:136
power_gfs_to_ordering_descriptor< GFS, Transformation, typename OrderingTag::Undecorated >::type undecorated_descriptor
Definition: decorator.hh:223
decorated_ordering_tag(const Undecorated &u)
Definition: decorator.hh:95
static transformed_storage_type transform(shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:156
static const bool recursive
Definition: decorator.hh:130
static const std::size_t level
Definition: decorator.hh:90
gfs_to_decorator_descriptor< GFS, Transformation, undecorated_type, OrderingTag, typename OrderingTag::Decorator >::type decorator_descriptor
Definition: decorator.hh:307
static transformed_type transform(const GFS &gfs, const Transformation &t)
Definition: decorator.hh:354
static const bool recursive
Definition: decorator.hh:217
decorator_descriptor::transformed_type type
Definition: decorator.hh:309
power_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_power_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)
typedef DUNE_DECLTYPE(register_gfs_to_decorator_descriptor(TypeTree::declptr< GFS >(), TypeTree::declptr< Transformation >(), TypeTree::declptr< Undecorated >(), TypeTree::declptr< GlueTag >(), TypeTree::declptr< Tag >())) type
static result< TC...>::type transform(const GFS &gfs, const Transformation &t, shared_ptr< TC >...children)
Definition: decorator.hh:315
static transformed_storage_type transform(shared_ptr< const GFS > &gfs_pointer, const Transformation &t)
Definition: decorator.hh:359
composite_gfs_to_decorated< GFS, Transformation, decorated_ordering_tag< D, U > > register_composite_gfs_to_ordering_descriptor(GFS *, Transformation *, decorated_ordering_tag< D, U > *)