dune-typetree 2.10
Loading...
Searching...
No Matches
simpletransformationdescriptors.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// 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
14#include <dune/common/exceptions.hh>
15
16
17namespace Dune {
18 namespace TypeTree {
19
25 template<typename SourceNode, typename Transformation, typename TransformedNode>
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>
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>
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>
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
decltype(Node::degree()) StaticDegree
Returns the statically known degree of the given Node type as a std::integral_constant.
Definition nodeinterface.hh:107
Definition accumulate_static.hh:16
Definition simpletransformationdescriptors.hh:27
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition simpletransformationdescriptors.hh:34
static const bool recursive
Definition simpletransformationdescriptors.hh:29
std::shared_ptr< transformed_type > transformed_storage_type
Definition simpletransformationdescriptors.hh:32
static transformed_storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition simpletransformationdescriptors.hh:39
TransformedNode transformed_type
Definition simpletransformationdescriptors.hh:31
Definition simpletransformationdescriptors.hh:49
static 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)
Definition simpletransformationdescriptors.hh:68
static const bool recursive
Definition simpletransformationdescriptors.hh:51
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::array< std::shared_ptr< TC >, result< TC >::degree > &children)
Definition simpletransformationdescriptors.hh:62
Definition simpletransformationdescriptors.hh:55
TransformedNode< TC, StaticDegree< SourceNode >::value > type
Definition simpletransformationdescriptors.hh:56
static const std::size_t degree
Definition simpletransformationdescriptors.hh:58
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:57
Definition simpletransformationdescriptors.hh:78
static const bool recursive
Definition simpletransformationdescriptors.hh:80
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::vector< std::shared_ptr< TC > > &children)
Definition simpletransformationdescriptors.hh:90
static result< TC >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, const std::vector< std::shared_ptr< TC > > &children)
Definition simpletransformationdescriptors.hh:96
Definition simpletransformationdescriptors.hh:84
TransformedNode< TC > type
Definition simpletransformationdescriptors.hh:85
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:86
Definition simpletransformationdescriptors.hh:106
static const bool recursive
Definition simpletransformationdescriptors.hh:108
static result< TC... >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >... children)
Definition simpletransformationdescriptors.hh:124
static result< TC... >::type transform(const SourceNode &s, const Transformation &t, std::shared_ptr< TC >... children)
Definition simpletransformationdescriptors.hh:118
Definition simpletransformationdescriptors.hh:112
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:114
TransformedNode< TC... > type
Definition simpletransformationdescriptors.hh:113