dune-typetree  2.4-dev
generictransformationdescriptors.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_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
5 #define DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
6 
7 #include <array>
8 
11 #include <dune/common/exceptions.hh>
12 #include <dune/common/shared_ptr.hh>
13 #include <dune/common/tuples.hh>
14 
15 
16 namespace Dune {
17  namespace TypeTree {
18 
24  template<typename SourceNode, typename Transformation, typename TransformedNode>
26  {
27 
28  static const bool recursive = false;
29 
30  typedef TransformedNode transformed_type;
31  typedef shared_ptr<transformed_type> transformed_storage_type;
32 
33  static transformed_type transform(const SourceNode& s, const Transformation& t)
34  {
35  return transformed_type(s,t);
36  }
37 
38  static transformed_type transform(shared_ptr<const SourceNode> s, const Transformation& t)
39  {
40  return transformed_type(s,t);
41  }
42 
43  static transformed_storage_type transform_storage(shared_ptr<const SourceNode> s, const Transformation& t)
44  {
45  return make_shared<transformed_type>(s,t);
46  }
47 
48  };
49 
50 
51  template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
53  {
54 
55  static const bool recursive = true;
56 
57  template<typename TC>
58  struct result
59  {
60  typedef typename TransformedNodeTemplate<TC>::type type;
61  typedef shared_ptr<type> storage_type;
62  };
63 
64  template<typename TC>
65  static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
66  {
67  return typename result<TC>::type(s,t,children);
68  }
69 
70  template<typename TC>
71  static typename result<TC>::type transform(shared_ptr<const SourceNode> s, const Transformation& t, const std::array<shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
72  {
73  return typename result<TC>::type(s,t,children);
74  }
75 
76  template<typename TC>
77  static typename result<TC>::storage_type transform_storage(shared_ptr<const SourceNode> s, const Transformation& t, const std::array<shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
78  {
79  return make_shared<typename result<TC>::type>(s,t,children);
80  }
81 
82  };
83 
84 
85  template<typename SourceNode, typename Transformation, template<typename,typename,std::size_t> class TransformedNode>
88  Transformation,
89  GenericPowerNodeTransformationTemplate<SourceNode,
90  Transformation,
91  TransformedNode>::template result
92  >
93  {};
94 
95 
96  template<typename SourceNode, typename Transformation, template<typename...> class TransformedNodeTemplate>
98  {
99 
100  static const bool recursive = true;
101 
102  template<typename... TC>
103  struct result
104  {
105  typedef typename TransformedNodeTemplate<TC...>::type type;
106  typedef shared_ptr<type> storage_type;
107  };
108 
109  template<typename... TC>
110  static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, shared_ptr<TC>... children)
111  {
112  return typename result<TC...>::type(s,t,children...);
113  }
114 
115  template<typename... TC>
116  static typename result<TC...>::type transform(shared_ptr<const SourceNode> s, const Transformation& t, shared_ptr<TC>... children)
117  {
118  return typename result<TC...>::type(s,t,children...);
119  }
120 
121  template<typename... TC>
122  static typename result<TC...>::storage_type transform_storage(shared_ptr<const SourceNode> s, const Transformation& t, shared_ptr<TC>... children)
123  {
124  return make_shared<typename result<TC...>::type>(s,t,children...);
125  }
126 
127  };
128 
129 
130  template<typename SourceNode, typename Transformation, template<typename,typename...> class TransformedNode>
133  Transformation,
134  GenericCompositeNodeTransformationTemplate<SourceNode,
135  Transformation,
136  TransformedNode>::template result
137  >
138  {};
139 
141 
142  } // namespace TypeTree
143 } //namespace Dune
144 
145 #endif // DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
static result< TC...>::type transform(shared_ptr< const SourceNode > s, const Transformation &t, shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:116
static transformed_type transform(shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:38
static const bool recursive
Definition: generictransformationdescriptors.hh:55
Definition: generictransformationdescriptors.hh:25
TransformedNodeTemplate< TC >::type type
Definition: generictransformationdescriptors.hh:60
static result< TC...>::type transform(const SourceNode &s, const Transformation &t, shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:110
Definition: accumulate_static.hh:12
Definition: generictransformationdescriptors.hh:103
static result< TC >::type transform(shared_ptr< const SourceNode > s, const Transformation &t, const std::array< shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:71
Definition: generictransformationdescriptors.hh:58
shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:106
static transformed_storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t)
Definition: generictransformationdescriptors.hh:43
Definition: generictransformationdescriptors.hh:131
TransformedNodeTemplate< TC...>::type type
Definition: generictransformationdescriptors.hh:105
TransformedNode transformed_type
Definition: generictransformationdescriptors.hh:30
static const bool recursive
Definition: generictransformationdescriptors.hh:28
Definition: generictransformationdescriptors.hh:86
Definition: generictransformationdescriptors.hh:52
static result< TC >::storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t, const std::array< shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:77
static result< TC...>::storage_type transform_storage(shared_ptr< const SourceNode > s, const Transformation &t, shared_ptr< TC >...children)
Definition: generictransformationdescriptors.hh:122
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< shared_ptr< TC >, result< TC >::type::CHILDREN > &children)
Definition: generictransformationdescriptors.hh:65
shared_ptr< transformed_type > transformed_storage_type
Definition: generictransformationdescriptors.hh:31
static const bool recursive
Definition: generictransformationdescriptors.hh:100
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition: generictransformationdescriptors.hh:33
static const result_type result
Definition: accumulate_static.hh:109
Definition: generictransformationdescriptors.hh:97
shared_ptr< type > storage_type
Definition: generictransformationdescriptors.hh:61