dune-typetree 2.11
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#include <vector>
12
15#include <dune/common/exceptions.hh>
16
17
18namespace Dune {
19 namespace TypeTree {
20
25
26 template<typename SourceNode, typename Transformation, typename TransformedNode>
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>
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>
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>
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
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:17
Definition accumulate_static.hh:18
Definition simpletransformationdescriptors.hh:28
static transformed_type transform(const SourceNode &s, const Transformation &t)
Definition simpletransformationdescriptors.hh:35
static const bool recursive
Definition simpletransformationdescriptors.hh:30
std::shared_ptr< transformed_type > transformed_storage_type
Definition simpletransformationdescriptors.hh:33
static transformed_storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t)
Definition simpletransformationdescriptors.hh:40
TransformedNode transformed_type
Definition simpletransformationdescriptors.hh:32
Definition simpletransformationdescriptors.hh:50
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:69
static const bool recursive
Definition simpletransformationdescriptors.hh:52
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:63
Definition simpletransformationdescriptors.hh:56
TransformedNode< TC, StaticDegree< SourceNode >::value > type
Definition simpletransformationdescriptors.hh:57
static const std::size_t degree
Definition simpletransformationdescriptors.hh:59
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:58
Definition simpletransformationdescriptors.hh:79
static const bool recursive
Definition simpletransformationdescriptors.hh:81
static result< TC >::type transform(const SourceNode &s, const Transformation &t, const std::vector< std::shared_ptr< TC > > &children)
Definition simpletransformationdescriptors.hh:91
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:97
Definition simpletransformationdescriptors.hh:85
TransformedNode< TC > type
Definition simpletransformationdescriptors.hh:86
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:87
Definition simpletransformationdescriptors.hh:107
static const bool recursive
Definition simpletransformationdescriptors.hh:109
static result< TC... >::storage_type transform_storage(std::shared_ptr< const SourceNode > s, const Transformation &t, std::shared_ptr< TC >... children)
Definition simpletransformationdescriptors.hh:125
static result< TC... >::type transform(const SourceNode &s, const Transformation &t, std::shared_ptr< TC >... children)
Definition simpletransformationdescriptors.hh:119
Definition simpletransformationdescriptors.hh:113
std::shared_ptr< type > storage_type
Definition simpletransformationdescriptors.hh:115
TransformedNode< TC... > type
Definition simpletransformationdescriptors.hh:114