Dune Core Modules (2.9.0)

filteredcompositenode.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
5#define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
6
7#include <memory>
8#include <tuple>
9#include <type_traits>
10
11#include <dune/typetree/nodetags.hh>
12#include <dune/typetree/filters.hh>
15#include <dune/common/indices.hh>
16
17#include <dune/typetree/filters.hh>
18#include <dune/typetree/nodetags.hh>
19
20namespace Dune {
21 namespace TypeTree {
22
28#ifndef DOXYGEN
29 namespace {
30
31 // ********************************************************************************
32 // Utility structs for filter construction and application
33 // ********************************************************************************
34
35 // Gets the filter and wraps it in case of a SimpleFilter.
36 template<typename Filter, typename Tag>
37 struct get_filter;
38
39 // Helper struct to extract the child template parameter pack from the ChildTypes tuple.
40 template<typename Filter, typename Node, typename ChildTypes>
41 struct apply_filter_wrapper;
42
43 template<typename Filter, typename Node, typename... Children>
44 struct apply_filter_wrapper<Filter,Node,std::tuple<Children...> >
45 : public Filter::template apply<Node,Children...>
46 {};
47
48 // specialization for SimpleFilter
49 template<typename Filter>
50 struct get_filter<Filter,SimpleFilterTag>
51 {
52 struct type
53 {
54 template<typename Node, typename ChildTypes>
55 struct apply
56 : public apply_filter_wrapper<filter<Filter>,Node,ChildTypes>
57 {};
58 };
59 };
60
61 // specialization for AdvancedFilter
62 template<typename Filter>
63 struct get_filter<Filter,AdvancedFilterTag>
64 {
65 struct type
66 {
67 template<typename Node, typename ChildTypes>
68 struct apply
69 : public apply_filter_wrapper<Filter,Node,ChildTypes>
70 {};
71 };
72 };
73
74 } // anonymous namespace
75#endif // DOXYGEN
76
77
79 template<typename Node, typename Filter>
81 {
82
83 typedef typename get_filter<Filter,typename Filter::FilterTag>::type filter;
84 typedef typename filter::template apply<Node,typename Node::ChildTypes>::type filter_result;
85 typedef typename filter_result::template apply<Node> mapped_children;
86
87 static const bool nodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
88
89 template<std::size_t k>
90 struct lazy_enable
91 {
92 static const bool value = !nodeIsConst;
93 };
94
95 public:
96
99
101 typedef typename mapped_children::NodeStorage NodeStorage;
102
104 typedef typename mapped_children::ChildTypes ChildTypes;
105
107 static const bool isLeaf = false;
108
110 static const bool isPower = false;
111
113 static const bool isComposite = true;
114
116 [[deprecated("Will be removed after release 2.9. Use degree()")]]
117 static const std::size_t CHILDREN = filter_result::size;
118
119 static constexpr auto degree ()
120 {
121 return std::integral_constant<std::size_t,filter_result::size>{};
122 }
123
125 template<std::size_t k>
126 struct Child {
127
128#ifndef DOXYGEN
129
130 typedef typename std::tuple_element<k,typename mapped_children::Children>::type OriginalChild;
131
132 static const std::size_t mapped_index = std::tuple_element<k,typename filter_result::IndexMap>::type::original_index;
133
134#endif // DOXYGEN
135
137 typedef typename OriginalChild::Type Type;
138
140 typedef typename OriginalChild::type type;
141 };
142
145
147
150 template<std::size_t k,
151 typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
152 auto& child (index_constant<k> = {})
153 {
154 return _node->template child<Child<k>::mapped_index>();
155 }
156
158
161 template<std::size_t k>
162 const auto& child (index_constant<k> = {}) const
163 {
164 return _node->template child<Child<k>::mapped_index>();
165 }
166
168
171 template<std::size_t k,
172 typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
173 auto childStorage (index_constant<k> = {})
174 {
175 return _node->template childStorage<Child<k>::mapped_index>();
176 }
177
179
182 template<std::size_t k>
183 auto childStorage (index_constant<k> = {}) const
184 {
185 return _node->template childStorage<Child<k>::mapped_index>();
186 }
187
189 template<std::size_t k, class ChildType>
190 void setChild (ChildType&& child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
191 {
192 _node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(child));
193 }
194
196
199
200 protected:
201
203
206 template<bool enabled = !nodeIsConst>
207 typename std::enable_if<enabled,Node&>::type
209 {
210 return *_node;
211 }
212
214
217 const Node& unfiltered () const
218 {
219 return *_node;
220 }
221
223
226 template<bool enabled = !nodeIsConst>
227 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
229 {
230 return _node;
231 }
232
234
237 std::shared_ptr<const Node> unfilteredStorage () const
238 {
239 return _node;
240 }
241
243
244 public:
245
248
250 FilteredCompositeNode (std::shared_ptr<Node> node)
251 : _node(std::move(node))
252 {}
253
256 : _node(stackobject_to_shared_ptr(node))
257 {}
258
260
261 private:
262 std::shared_ptr<Node> _node;
263 };
264
266
267 } // namespace TypeTree
268} //namespace Dune
269
270#endif // DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
Base class for composite nodes representing a filtered view on an underlying composite node.
Definition: filteredcompositenode.hh:81
auto childStorage(index_constant< k >={}) const
Returns the storage of the k-th child (const version).
Definition: filteredcompositenode.hh:183
mapped_children::NodeStorage NodeStorage
The type used for storing the children.
Definition: filteredcompositenode.hh:101
void setChild(ChildType &&child, typename std::enable_if< lazy_enable< k >::value, void * >::type=0)
Sets the k-th child to the passed-in value.
Definition: filteredcompositenode.hh:190
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: filteredcompositenode.hh:107
const Node & unfiltered() const
Returns the unfiltered node (const version).
Definition: filteredcompositenode.hh:217
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: filteredcompositenode.hh:113
std::enable_if< enabled, std::shared_ptr< Node > >::type unfilteredStorage()
Returns the storage object of the unfiltered node.
Definition: filteredcompositenode.hh:228
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: filteredcompositenode.hh:110
FilteredCompositeNode(Node &node)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: filteredcompositenode.hh:255
FilteredCompositeNode(std::shared_ptr< Node > node)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: filteredcompositenode.hh:250
auto childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition: filteredcompositenode.hh:173
const auto & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition: filteredcompositenode.hh:162
auto & child(index_constant< k >={})
Returns the k-th child.
Definition: filteredcompositenode.hh:152
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: filteredcompositenode.hh:98
mapped_children::ChildTypes ChildTypes
A tuple storing the types of all children.
Definition: filteredcompositenode.hh:104
std::enable_if< enabled, Node & >::type unfiltered()
Returns the unfiltered node.
Definition: filteredcompositenode.hh:208
static const std::size_t CHILDREN
The number of children.
Definition: filteredcompositenode.hh:117
std::shared_ptr< const Node > unfilteredStorage() const
Returns the storage object of the unfiltered node (const version).
Definition: filteredcompositenode.hh:237
Traits for type conversions and type information.
Dune namespace.
Definition: alignedallocator.hh:13
std::shared_ptr< T > stackobject_to_shared_ptr(T &t)
Create a shared_ptr for a stack-allocated object.
Definition: shared_ptr.hh:72
STL namespace.
This file implements several utilities related to std::shared_ptr.
Tag designating a composite node.
Definition: nodetags.hh:25
Access to the type and storage type of the i-th child.
Definition: filteredcompositenode.hh:126
OriginalChild::type type
The type of the child.
Definition: filteredcompositenode.hh:140
OriginalChild::Type Type
The type of the child.
Definition: filteredcompositenode.hh:137
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)