DUNE PDELab (git)

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// 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_FILTEREDCOMPOSITENODE_HH
7#define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
8
9#include <memory>
10#include <tuple>
11#include <type_traits>
12
13#include <dune/typetree/nodetags.hh>
14#include <dune/typetree/filters.hh>
17#include <dune/common/indices.hh>
18
19#include <dune/typetree/filters.hh>
20#include <dune/typetree/nodetags.hh>
21
22namespace Dune {
23 namespace TypeTree {
24
30#ifndef DOXYGEN
31 namespace {
32
33 // ********************************************************************************
34 // Utility structs for filter construction and application
35 // ********************************************************************************
36
37 // Gets the filter and wraps it in case of a SimpleFilter.
38 template<typename Filter, typename Tag>
39 struct get_filter;
40
41 // Helper struct to extract the child template parameter pack from the ChildTypes tuple.
42 template<typename Filter, typename Node, typename ChildTypes>
43 struct apply_filter_wrapper;
44
45 template<typename Filter, typename Node, typename... Children>
46 struct apply_filter_wrapper<Filter,Node,std::tuple<Children...> >
47 : public Filter::template apply<Node,Children...>
48 {};
49
50 // specialization for SimpleFilter
51 template<typename Filter>
52 struct get_filter<Filter,SimpleFilterTag>
53 {
54 struct type
55 {
56 template<typename Node, typename ChildTypes>
57 struct apply
58 : public apply_filter_wrapper<filter<Filter>,Node,ChildTypes>
59 {};
60 };
61 };
62
63 // specialization for AdvancedFilter
64 template<typename Filter>
65 struct get_filter<Filter,AdvancedFilterTag>
66 {
67 struct type
68 {
69 template<typename Node, typename ChildTypes>
70 struct apply
71 : public apply_filter_wrapper<Filter,Node,ChildTypes>
72 {};
73 };
74 };
75
76 } // anonymous namespace
77#endif // DOXYGEN
78
79
81 template<typename Node, typename Filter>
83 {
84
85 typedef typename get_filter<Filter,typename Filter::FilterTag>::type filter;
86 typedef typename filter::template apply<Node,typename Node::ChildTypes>::type filter_result;
87 typedef typename filter_result::template apply<Node> mapped_children;
88
89 static const bool nodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
90
91 template<std::size_t k>
92 struct lazy_enable
93 {
94 static const bool value = !nodeIsConst;
95 };
96
97 public:
98
101
103 typedef typename mapped_children::NodeStorage NodeStorage;
104
106 typedef typename mapped_children::ChildTypes ChildTypes;
107
109 static const bool isLeaf = false;
110
112 static const bool isPower = false;
113
115 static const bool isComposite = true;
116
117 static constexpr auto degree ()
118 {
119 return std::integral_constant<std::size_t,filter_result::size>{};
120 }
121
123 template<std::size_t k>
124 struct Child {
125
126#ifndef DOXYGEN
127
128 typedef typename std::tuple_element<k,typename mapped_children::Children>::type OriginalChild;
129
130 static const std::size_t mapped_index = std::tuple_element<k,typename filter_result::IndexMap>::type::original_index;
131
132#endif // DOXYGEN
133
135 typedef typename OriginalChild::Type Type;
136
138 typedef typename OriginalChild::type type;
139 };
140
143
145
148 template<std::size_t k,
149 typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
150 auto& child (index_constant<k> = {})
151 {
152 return _node->template child<Child<k>::mapped_index>();
153 }
154
156
159 template<std::size_t k>
160 const auto& child (index_constant<k> = {}) const
161 {
162 return _node->template child<Child<k>::mapped_index>();
163 }
164
166
169 template<std::size_t k,
170 typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
171 auto childStorage (index_constant<k> = {})
172 {
173 return _node->template childStorage<Child<k>::mapped_index>();
174 }
175
177
180 template<std::size_t k>
181 auto childStorage (index_constant<k> = {}) const
182 {
183 return _node->template childStorage<Child<k>::mapped_index>();
184 }
185
187 template<std::size_t k, class ChildType>
188 void setChild (ChildType&& child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
189 {
190 _node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(child));
191 }
192
194
197
198 protected:
199
201
204 template<bool enabled = !nodeIsConst>
205 typename std::enable_if<enabled,Node&>::type
207 {
208 return *_node;
209 }
210
212
215 const Node& unfiltered () const
216 {
217 return *_node;
218 }
219
221
224 template<bool enabled = !nodeIsConst>
225 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
227 {
228 return _node;
229 }
230
232
235 std::shared_ptr<const Node> unfilteredStorage () const
236 {
237 return _node;
238 }
239
241
242 public:
243
246
248 FilteredCompositeNode (std::shared_ptr<Node> node)
249 : _node(std::move(node))
250 {}
251
254 : _node(stackobject_to_shared_ptr(node))
255 {}
256
258
259 private:
260 std::shared_ptr<Node> _node;
261 };
262
264
265 } // namespace TypeTree
266} //namespace Dune
267
268#endif // DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
Base class for composite nodes representing a filtered view on an underlying composite node.
Definition: filteredcompositenode.hh:83
auto childStorage(index_constant< k >={}) const
Returns the storage of the k-th child (const version).
Definition: filteredcompositenode.hh:181
mapped_children::NodeStorage NodeStorage
The type used for storing the children.
Definition: filteredcompositenode.hh:103
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:188
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: filteredcompositenode.hh:109
const Node & unfiltered() const
Returns the unfiltered node (const version).
Definition: filteredcompositenode.hh:215
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: filteredcompositenode.hh:115
std::enable_if< enabled, std::shared_ptr< Node > >::type unfilteredStorage()
Returns the storage object of the unfiltered node.
Definition: filteredcompositenode.hh:226
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: filteredcompositenode.hh:112
FilteredCompositeNode(Node &node)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: filteredcompositenode.hh:253
FilteredCompositeNode(std::shared_ptr< Node > node)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: filteredcompositenode.hh:248
auto childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition: filteredcompositenode.hh:171
const auto & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition: filteredcompositenode.hh:160
auto & child(index_constant< k >={})
Returns the k-th child.
Definition: filteredcompositenode.hh:150
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: filteredcompositenode.hh:100
mapped_children::ChildTypes ChildTypes
A tuple storing the types of all children.
Definition: filteredcompositenode.hh:106
std::enable_if< enabled, Node & >::type unfiltered()
Returns the unfiltered node.
Definition: filteredcompositenode.hh:206
std::shared_ptr< const Node > unfilteredStorage() const
Returns the storage object of the unfiltered node (const version).
Definition: filteredcompositenode.hh:235
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:27
Access to the type and storage type of the i-th child.
Definition: filteredcompositenode.hh:124
OriginalChild::type type
The type of the child.
Definition: filteredcompositenode.hh:138
OriginalChild::Type Type
The type of the child.
Definition: filteredcompositenode.hh:135
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 24, 23:30, 2024)