Dune Core Modules (2.9.0)

generictransformationdescriptors.hh
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#include <memory>
9
10#include <dune/typetree/nodeinterface.hh>
11#include <dune/typetree/nodetags.hh>
12#include <dune/typetree/powercompositenodetransformationtemplates.hh>
14
15
16namespace Dune {
17 namespace TypeTree {
18
24 template<typename SourceNode, typename Transformation, typename TransformedNode>
25 struct GenericLeafNodeTransformation
26 {
27
28 static const bool recursive = false;
29
30 typedef TransformedNode transformed_type;
31 typedef std::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(std::shared_ptr<const SourceNode> s, const Transformation& t)
39 {
40 return transformed_type(s,t);
41 }
42
43 static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
44 {
45 return std::make_shared<transformed_type>(s,t);
46 }
47
48 };
49
50
51 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
52 struct TemplatizedGenericPowerNodeTransformation
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 std::shared_ptr<type> storage_type;
62 static const std::size_t degree = StaticDegree<type>::value;
63 };
64
65 template<typename TC>
66 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
67 {
68 return typename result<TC>::type(s,t,children);
69 }
70
71 template<typename TC>
72 static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
73 {
74 return typename result<TC>::type(s,t,children);
75 }
76
77 template<typename TC>
78 static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
79 {
80 return std::make_shared<typename result<TC>::type>(s,t,children);
81 }
82
83 };
84
85
86 template<typename SourceNode, typename Transformation, template<typename,typename,std::size_t> class TransformedNode>
87 struct GenericPowerNodeTransformation
88 : public TemplatizedGenericPowerNodeTransformation<SourceNode,
89 Transformation,
90 GenericPowerNodeTransformationTemplate<SourceNode,
91 Transformation,
92 TransformedNode>::template result
93 >
94 {};
95
96
97 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
98 struct TemplatizedGenericDynamicPowerNodeTransformation
99 {
100
101 static const bool recursive = true;
102
103 template<typename TC>
104 struct result
105 {
106 typedef typename TransformedNodeTemplate<TC>::type type;
107 typedef std::shared_ptr<type> storage_type;
108 };
109
110 template<typename TC>
111 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
112 {
113 return typename result<TC>::type(s,t,children);
114 }
115
116 template<typename TC>
117 static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
118 {
119 return typename result<TC>::type(s,t,children);
120 }
121
122 template<typename TC>
123 static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
124 {
125 return std::make_shared<typename result<TC>::type>(s,t,children);
126 }
127
128 };
129
130
131 template<typename SourceNode, typename Transformation, template<typename,typename> class TransformedNode>
132 struct GenericDynamicPowerNodeTransformation
133 : public TemplatizedGenericDynamicPowerNodeTransformation<SourceNode,
134 Transformation,
135 GenericDynamicPowerNodeTransformationTemplate<SourceNode,
136 Transformation,
137 TransformedNode>::template result
138 >
139 {};
140
141
142 template<typename SourceNode, typename Transformation, template<typename...> class TransformedNodeTemplate>
143 struct TemplatizedGenericCompositeNodeTransformation
144 {
145
146 static const bool recursive = true;
147
148 template<typename... TC>
149 struct result
150 {
151 typedef typename TransformedNodeTemplate<TC...>::type type;
152 typedef std::shared_ptr<type> storage_type;
153 };
154
155 template<typename... TC>
156 static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
157 {
158 return typename result<TC...>::type(s,t,children...);
159 }
160
161 template<typename... TC>
162 static typename result<TC...>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
163 {
164 return typename result<TC...>::type(s,t,children...);
165 }
166
167 template<typename... TC>
168 static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
169 {
170 return std::make_shared<typename result<TC...>::type>(s,t,children...);
171 }
172
173 };
174
175
176 template<typename SourceNode, typename Transformation, template<typename,typename...> class TransformedNode>
177 struct GenericCompositeNodeTransformation
178 : public TemplatizedGenericCompositeNodeTransformation<SourceNode,
179 Transformation,
180 GenericCompositeNodeTransformationTemplate<SourceNode,
181 Transformation,
182 TransformedNode>::template result
183 >
184 {};
185
187
188 } // namespace TypeTree
189} //namespace Dune
190
191#endif // DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
A few common exception classes.
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:85
Dune namespace.
Definition: alignedallocator.hh:13
std::vector< decltype(std::declval< Op >()(std::declval< T >())) > transform(const std::vector< T > &in, Op op)
copy a vector, performing an operation on each element
Definition: misc.hh:24
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)