DUNE PDELab (git)

simpletransformationdescriptors.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_SIMPLETRANSFORMATIONDESCRIPTORS_HH
7#define DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
8
9#include <array>
10#include <memory>
11
12#include <dune/typetree/nodeinterface.hh>
13#include <dune/typetree/nodetags.hh>
15
16
17namespace Dune {
18 namespace TypeTree {
19
25 template<typename SourceNode, typename Transformation, typename TransformedNode>
26 struct SimpleLeafNodeTransformation
27 {
28
29 static const bool recursive = false;
30
31 typedef TransformedNode transformed_type;
32 typedef std::shared_ptr<transformed_type> transformed_storage_type;
33
34 static transformed_type transform(const SourceNode& s, const Transformation& t)
35 {
36 return transformed_type();
37 }
38
39 static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
40 {
41 return std::make_shared<transformed_type>();
42 }
43
44 };
45
46
47 template<typename SourceNode, typename Transformation, template<typename Child, std::size_t> class TransformedNode>
48 struct SimplePowerNodeTransformation
49 {
50
51 static const bool recursive = true;
52
53 template<typename TC>
54 struct result
55 {
56 typedef TransformedNode<TC, StaticDegree<SourceNode>::value> type;
57 typedef std::shared_ptr<type> storage_type;
58 static const std::size_t degree = StaticDegree<type>::value;
59 };
60
61 template<typename TC>
62 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
63 {
64 return typename result<TC>::type(children);
65 }
66
67 template<typename TC>
68 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)
69 {
70 return std::make_shared<typename result<TC>::type>(children);
71 }
72
73 };
74
75
76 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNode>
77 struct SimpleDynamicPowerNodeTransformation
78 {
79
80 static const bool recursive = true;
81
82 template<typename TC>
83 struct result
84 {
85 typedef TransformedNode<TC> type;
86 typedef std::shared_ptr<type> storage_type;
87 };
88
89 template<typename TC>
90 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
91 {
92 return typename result<TC>::type(children);
93 }
94
95 template<typename TC>
96 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)
97 {
98 return std::make_shared<typename result<TC>::type>(children);
99 }
100
101 };
102
103
104 template<typename SourceNode, typename Transformation, template<typename...> class TransformedNode>
105 struct SimpleCompositeNodeTransformation
106 {
107
108 static const bool recursive = true;
109
110 template<typename... TC>
111 struct result
112 {
113 typedef TransformedNode<TC...> type;
114 typedef std::shared_ptr<type> storage_type;
115 };
116
117 template<typename... TC>
118 static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
119 {
120 return typename result<TC...>::type(children...);
121 }
122
123 template<typename... TC>
124 static typename result<TC...>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, std::shared_ptr<TC>... children)
125 {
126 return std::make_shared<typename result<TC...>::type>(children...);
127 }
128
129 };
130
132
133 } // namespace TypeTree
134} //namespace Dune
135
136#endif // DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_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)