Dune TypeTree (unstable)

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#include <vector>
12
13#include <dune/typetree/nodeinterface.hh>
14#include <dune/typetree/nodetags.hh>
15#include <dune/common/exceptions.hh>
16
17
18namespace Dune {
19 namespace TypeTree {
20
26 template<typename SourceNode, typename Transformation, typename TransformedNode>
27 struct SimpleLeafNodeTransformation
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();
38 }
39
40 static transformed_storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t)
41 {
42 return std::make_shared<transformed_type>();
43 }
44
45 };
46
47
48 template<typename SourceNode, typename Transformation, template<typename Child, std::size_t> class TransformedNode>
49 struct SimplePowerNodeTransformation
50 {
51
52 static const bool recursive = true;
53
54 template<typename TC>
55 struct result
56 {
57 typedef TransformedNode<TC, StaticDegree<SourceNode>::value> type;
58 typedef std::shared_ptr<type> storage_type;
59 static const std::size_t degree = StaticDegree<type>::value;
60 };
61
62 template<typename TC>
63 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::degree>& children)
64 {
65 return typename result<TC>::type(children);
66 }
67
68 template<typename TC>
69 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)
70 {
71 return std::make_shared<typename result<TC>::type>(children);
72 }
73
74 };
75
76
77 template<typename SourceNode, typename Transformation, template<typename Child> class TransformedNode>
78 struct SimpleDynamicPowerNodeTransformation
79 {
80
81 static const bool recursive = true;
82
83 template<typename TC>
84 struct result
85 {
86 typedef TransformedNode<TC> type;
87 typedef std::shared_ptr<type> storage_type;
88 };
89
90 template<typename TC>
91 static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::vector<std::shared_ptr<TC>>& children)
92 {
93 return typename result<TC>::type(children);
94 }
95
96 template<typename TC>
97 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)
98 {
99 return std::make_shared<typename result<TC>::type>(children);
100 }
101
102 };
103
104
105 template<typename SourceNode, typename Transformation, template<typename...> class TransformedNode>
106 struct SimpleCompositeNodeTransformation
107 {
108
109 static const bool recursive = true;
110
111 template<typename... TC>
112 struct result
113 {
114 typedef TransformedNode<TC...> type;
115 typedef std::shared_ptr<type> storage_type;
116 };
117
118 template<typename... TC>
119 static typename result<TC...>::type transform(const SourceNode& s, const Transformation& t, std::shared_ptr<TC>... children)
120 {
121 return typename result<TC...>::type(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, std::shared_ptr<TC>... children)
126 {
127 return std::make_shared<typename result<TC...>::type>(children...);
128 }
129
130 };
131
133
134 } // namespace TypeTree
135} //namespace Dune
136
137#endif // DUNE_TYPETREE_SIMPLETRANSFORMATIONDESCRIPTORS_HH
std::size_t degree(const Node &node)
Returns the degree of node as run time information.
Definition: nodeinterface.hh:79
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Feb 3, 23:36, 2026)