DUNE PDELab (git)

filters.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_FILTERS_HH
7#define DUNE_TYPETREE_FILTERS_HH
8
9#include <tuple>
10
12
13namespace Dune {
14 namespace TypeTree {
15
22 template<std::size_t new_k, std::size_t old_k>
24 {
25
26#ifndef DOXYGEN
27
28 // The precise contents of this class is an implementation detail.
29
30 static const std::size_t filtered_index = new_k;
31 static const std::size_t original_index = old_k;
32
33#endif // DOXYGEN
34
35 };
36
38 template<typename... FilterEntries>
40 {
41
42 static const std::size_t size = sizeof...(FilterEntries);
43
44 typedef std::tuple<FilterEntries...> IndexMap;
45
46 template<typename Node>
47 struct apply
48 {
49 typedef std::tuple<typename Node::template Child<FilterEntries::original_index>...> Children;
50 typedef std::tuple<typename Node::template Child<FilterEntries::original_index>::Type...> ChildTypes;
51 typedef std::tuple<std::shared_ptr<typename Node::template Child<FilterEntries::original_index>::Type>...> NodeStorage;
52 };
53
54 };
55
57 struct SimpleFilterTag {};
58
61
62
65 {
66
69
70#ifdef DOXYGEN
71
73 template<typename Node, typename... Children>
74 struct apply
75 {
77
80 typedef implementation-defined type;
81 };
82
83#endif // DOXYGEN
84
85 };
86
88
94 {
95
98
99
101 template<typename Node>
102 struct validate
103 {
105 static const bool value = true;
106 };
107
109
117 template<typename Child, std::size_t new_index, std::size_t old_index>
118 struct apply
119 {
121 static const bool value = true;
122 };
123
124 };
125
126 namespace {
127
128 // ********************************************************************************
129 // IndexFilter helpers
130 // ********************************************************************************
131
132 template<typename Node, std::size_t new_index, std::size_t... indices>
133 struct index_filter_helper
134 {
135 template<typename... FilterEntries>
136 struct apply
137 {
138 typedef FilterResult<FilterEntries...> type;
139 };
140 };
141
142 template<typename Node, std::size_t new_index, std::size_t old_index, std::size_t... indices>
143 struct index_filter_helper<Node,new_index,old_index,indices...>
144 {
145 template<typename... FilterEntries>
146 struct apply
147 : public index_filter_helper<Node,new_index+1,indices...>::template apply<FilterEntries...,
148 FilterEntry<new_index,
149 old_index>
150 >
151 {};
152 };
153
154 } // anonymous namespace
155
156
158 template<std::size_t... indices>
160 : public AdvancedFilter
161 {
162
163#ifndef DOXYGEN
164
165 template<typename Node, typename... Children>
166 struct apply
167 {
168 typedef typename index_filter_helper<Node,0,indices...>::template apply<>::type type;
169 };
170
171#endif // DOXYGEN
172
173 };
174
175
176 // ********************************************************************************
177 // filter: Wrapper class for turning a simple filter into an advanced filter
178 // usable by FilteredCompositeNode
179 // ********************************************************************************
180
181 namespace {
182
183 template<typename Filter, std::size_t new_k, std::size_t old_k, typename... tail>
184 struct filter_helper
185 {
186 template<typename... FilterDescriptors>
187 struct apply
188 {
189 typedef FilterResult<FilterDescriptors...> type;
190 };
191 };
192
193 template<typename Filter, std::size_t new_k, std::size_t old_k, typename child, typename... tail>
194 struct filter_helper<Filter,new_k,old_k,child,tail...>
195 {
196
197 template<typename... FilterDescriptors>
198 struct apply
199 : public std::conditional<Filter::template apply<child,new_k,old_k>::value,
200 typename filter_helper<Filter,new_k+1,old_k+1,tail...>::template apply<FilterDescriptors...,FilterEntry<new_k,old_k> >,
201 typename filter_helper<Filter,new_k,old_k+1,tail...>::template apply<FilterDescriptors...>
202 >::type
203 {};
204
205 };
206
207 } // anonymous namespace
208
210 template<typename Filter>
211 struct filter
212 {
213
215 template<typename Node, typename... Children>
216 struct apply
217 {
218
219 static_assert((Filter::template validate<Node>::value),"Invalid simple filter");
220
221 typedef typename filter_helper<Filter,0,0,Children...>::template apply<>::type type;
222
223 };
224
225 };
226
228
229 } // namespace TypeTree
230} //namespace Dune
231
232#endif // DUNE_TYPETREE_FILTERS_HH
Traits for type conversions and type information.
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:128
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integer_sequence< T, II... > tail(std::integer_sequence< T, I0, II... >)
For a sequence [head,tail...) return the tail sequence.
Definition: integersequence.hh:58
Tag describing an advanced filter that has full control over the construction of the list of FilterEn...
Definition: filters.hh:60
Apply this filter to the given node and children.
Definition: filters.hh:75
implementation defined type
The result of the filtering process.
Definition: filters.hh:80
Base class for advanced filters.
Definition: filters.hh:65
AdvancedFilterTag FilterTag
Filter tag for deciding on filter application mechanism.
Definition: filters.hh:68
A filter entry describing the mapping of one child in the filtered node.
Definition: filters.hh:24
The result of a filter.
Definition: filters.hh:40
Filter class for FilteredCompositeNode that selects the children with the given indices.
Definition: filters.hh:161
Tag describing a simple filter that can only decide whether or not to include a single given child.
Definition: filters.hh:57
Applies the filter to the given child node.
Definition: filters.hh:119
static const bool value
True if the child will be included in the filtered node.
Definition: filters.hh:121
Validates the combination of filter and node.
Definition: filters.hh:103
static const bool value
True if the combination of filter and node is valid.
Definition: filters.hh:105
Default simple filter that accepts any node and leaves its child structure unchanged.
Definition: filters.hh:94
SimpleFilterTag FilterTag
Filter tag for deciding on filter application mechanism.
Definition: filters.hh:97
Apply the filter.
Definition: filters.hh:217
Adapter class that takes a SimpleFilter, validated it and turns it into an AdvancedFilter.
Definition: filters.hh:212
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)