DUNE PDELab (git)

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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
5
6#ifndef DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
7#define DUNE_TYPETREE_GENERICTRANSFORMATIONDESCRIPTORS_HH
8
9#include <array>
10#include <memory>
11
12#include <dune/typetree/nodeinterface.hh>
13#include <dune/typetree/nodetags.hh>
14#include <dune/typetree/powercompositenodetransformationtemplates.hh>
16
17
18namespace Dune {
19 namespace TypeTree {
20
26 template<typename SourceNode, typename Transformation, typename TransformedNode>
27 struct GenericLeafNodeTransformation
28 {
29
30 static const bool recursive = false;
31
32 typedef TransformedNode transformed_type;
33 typedef std::shared_ptr<transformed_type> transformed_storage_type;
34
35 static transformed_type transform(const SourceNode& s, const Transformation& t)
36 {
37 return transformed_type(s,t);
38 }
39
40 static transformed_type transform(std::shared_ptr<const SourceNode> s, const Transformation& t)
41 {
42 return transformed_type(s,t);
43 }
44
45 static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
46 {
47 return std::make_shared<transformed_type>(s,t);
48 }
49
50 };
51
52
53 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
54 struct TemplatizedGenericPowerNodeTransformation
55 {
56
57 static const bool recursive = true;
58
59 template<typename TC>
60 struct result
61 {
62 typedef typename TransformedNodeTemplate<TC>::type type;
63 typedef std::shared_ptr<type> storage_type;
64 static const std::size_t degree = StaticDegree<type>::value;
65 };
66
67 template<typename TC>
68 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
69 {
70 return typename result<TC>::type(s,t,children);
71 }
72
73 template<typename TC>
74 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)
75 {
76 return typename result<TC>::type(s,t,children);
77 }
78
79 template<typename TC>
80 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)
81 {
82 return std::make_shared<typename result<TC>::type>(s,t,children);
83 }
84
85 };
86
87
88 template<typename SourceNode, typename Transformation, template<typename,typename,std::size_t> class TransformedNode>
89 struct GenericPowerNodeTransformation
90 : public TemplatizedGenericPowerNodeTransformation<SourceNode,
91 Transformation,
92 GenericPowerNodeTransformationTemplate<SourceNode,
93 Transformation,
94 TransformedNode>::template result
95 >
96 {};
97
98
99 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNodeTemplate>
100 struct TemplatizedGenericDynamicPowerNodeTransformation
101 {
102
103 static const bool recursive = true;
104
105 template<typename TC>
106 struct result
107 {
108 typedef typename TransformedNodeTemplate<TC>::type type;
109 typedef std::shared_ptr<type> storage_type;
110 };
111
112 template<typename TC>
113 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
114 {
115 return typename result<TC>::type(s,t,children);
116 }
117
118 template<typename TC>
119 static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
120 {
121 return typename result<TC>::type(s,t,children);
122 }
123
124 template<typename TC>
125 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)
126 {
127 return std::make_shared<typename result<TC>::type>(s,t,children);
128 }
129
130 };
131
132
133 template<typename SourceNode, typename Transformation, template<typename,typename> class TransformedNode>
134 struct GenericDynamicPowerNodeTransformation
135 : public TemplatizedGenericDynamicPowerNodeTransformation<SourceNode,
136 Transformation,
137 GenericDynamicPowerNodeTransformationTemplate<SourceNode,
138 Transformation,
139 TransformedNode>::template result
140 >
141 {};
142
143
144 template<typename SourceNode, typename Transformation, template<typename...> class TransformedNodeTemplate>
145 struct TemplatizedGenericCompositeNodeTransformation
146 {
147
148 static const bool recursive = true;
149
150 template<typename... TC>
151 struct result
152 {
153 typedef typename TransformedNodeTemplate<TC...>::type type;
154 typedef std::shared_ptr<type> storage_type;
155 };
156
157 template<typename... TC>
158 static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
159 {
160 return typename result<TC...>::type(s,t,children...);
161 }
162
163 template<typename... TC>
164 static typename result<TC...>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
165 {
166 return typename result<TC...>::type(s,t,children...);
167 }
168
169 template<typename... TC>
170 static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
171 {
172 return std::make_shared<typename result<TC...>::type>(s,t,children...);
173 }
174
175 };
176
177
178 template<typename SourceNode, typename Transformation, template<typename,typename...> class TransformedNode>
179 struct GenericCompositeNodeTransformation
180 : public TemplatizedGenericCompositeNodeTransformation<SourceNode,
181 Transformation,
182 GenericCompositeNodeTransformationTemplate<SourceNode,
183 Transformation,
184 TransformedNode>::template result
185 >
186 {};
187
189
190 } // namespace TypeTree
191} //namespace Dune
192
193#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:79
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)