dune-typetree 2.11
Loading...
Searching...
No Matches
filters.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_FILTERS_HH
7#define DUNE_TYPETREE_FILTERS_HH
8
9#include <tuple>
10#include <memory>
11
12#include <dune/common/typetraits.hh>
13
14namespace Dune {
15 namespace TypeTree {
16
21
23 template<std::size_t new_k, std::size_t old_k>
25 {
26
27#ifndef DOXYGEN
28
29 // The precise contents of this class is an implementation detail.
30
31 static const std::size_t filtered_index = new_k;
32 static const std::size_t original_index = old_k;
33
34#endif // DOXYGEN
35
36 };
37
39 template<typename... FilterEntries>
41 {
42
43 static const std::size_t size = sizeof...(FilterEntries);
44
45 typedef std::tuple<FilterEntries...> IndexMap;
46
47 template<typename Node>
48 struct apply
49 {
50 typedef std::tuple<typename Node::template Child<FilterEntries::original_index>...> Children;
51 typedef std::tuple<typename Node::template Child<FilterEntries::original_index>::Type...> ChildTypes;
52 typedef std::tuple<std::shared_ptr<typename Node::template Child<FilterEntries::original_index>::Type>...> NodeStorage;
53 };
54
55 };
56
58 struct SimpleFilterTag {};
59
62
63
66 {
67
70
71#ifdef DOXYGEN
72
74 template<typename Node, typename... Children>
75 struct apply
76 {
78
81 typedef implementation-defined type;
82 };
83
84#endif // DOXYGEN
85
86 };
87
89
95 {
96
99
100
102 template<typename Node>
103 struct validate
104 {
106 static const bool value = true;
107 };
108
110
118 template<typename Child, std::size_t new_index, std::size_t old_index>
119 struct apply
120 {
122 static const bool value = true;
123 };
124
125 };
126
127 namespace {
128
129 // ********************************************************************************
130 // IndexFilter helpers
131 // ********************************************************************************
132
133 template<typename Node, std::size_t new_index, std::size_t... indices>
134 struct index_filter_helper
135 {
136 template<typename... FilterEntries>
137 struct apply
138 {
139 typedef FilterResult<FilterEntries...> type;
140 };
141 };
142
143 template<typename Node, std::size_t new_index, std::size_t old_index, std::size_t... indices>
144 struct index_filter_helper<Node,new_index,old_index,indices...>
145 {
146 template<typename... FilterEntries>
147 struct apply
148 : public index_filter_helper<Node,new_index+1,indices...>::template apply<FilterEntries...,
149 FilterEntry<new_index,
150 old_index>
151 >
152 {};
153 };
154
155 } // anonymous namespace
156
157
159 template<std::size_t... indices>
161 : public AdvancedFilter
162 {
163
164#ifndef DOXYGEN
165
166 template<typename Node, typename... Children>
167 struct apply
168 {
169 typedef typename index_filter_helper<Node,0,indices...>::template apply<>::type type;
170 };
171
172#endif // DOXYGEN
173
174 };
175
176
177 // ********************************************************************************
178 // filter: Wrapper class for turning a simple filter into an advanced filter
179 // usable by FilteredCompositeNode
180 // ********************************************************************************
181
182 namespace {
183
184 template<typename Filter, std::size_t new_k, std::size_t old_k, typename... tail>
185 struct filter_helper
186 {
187 template<typename... FilterDescriptors>
188 struct apply
189 {
190 typedef FilterResult<FilterDescriptors...> type;
191 };
192 };
193
194 template<typename Filter, std::size_t new_k, std::size_t old_k, typename child, typename... tail>
195 struct filter_helper<Filter,new_k,old_k,child,tail...>
196 {
197
198 template<typename... FilterDescriptors>
199 struct apply
200 : public std::conditional<Filter::template apply<child,new_k,old_k>::value,
201 typename filter_helper<Filter,new_k+1,old_k+1,tail...>::template apply<FilterDescriptors...,FilterEntry<new_k,old_k> >,
202 typename filter_helper<Filter,new_k,old_k+1,tail...>::template apply<FilterDescriptors...>
203 >::type
204 {};
205
206 };
207
208 } // anonymous namespace
209
211 template<typename Filter>
212 struct filter
213 {
214
216 template<typename Node, typename... Children>
217 struct apply
218 {
219
220 static_assert((Filter::template validate<Node>::value),"Invalid simple filter");
221
222 typedef typename filter_helper<Filter,0,0,Children...>::template apply<>::type type;
223
224 };
225
226 };
227
229
230 } // namespace TypeTree
231} //namespace Dune
232
233#endif // DUNE_TYPETREE_FILTERS_HH
Definition accumulate_static.hh:17
Definition accumulate_static.hh:18
A filter entry describing the mapping of one child in the filtered node.
Definition filters.hh:25
The result of a filter.
Definition filters.hh:41
std::tuple< FilterEntries... > IndexMap
Definition filters.hh:45
static const std::size_t size
Definition filters.hh:43
Definition filters.hh:49
std::tuple< typename Node::template Child< FilterEntries::original_index >... > Children
Definition filters.hh:50
std::tuple< typename Node::template Child< FilterEntries::original_index >::Type... > ChildTypes
Definition filters.hh:51
std::tuple< std::shared_ptr< typename Node::template Child< FilterEntries::original_index >::Type >... > NodeStorage
Definition filters.hh:52
Tag describing a simple filter that can only decide whether or not to include a single given child.
Definition filters.hh:58
Tag describing an advanced filter that has full control over the construction of the list of FilterEn...
Definition filters.hh:61
Base class for advanced filters.
Definition filters.hh:66
AdvancedFilterTag FilterTag
Filter tag for deciding on filter application mechanism.
Definition filters.hh:69
Apply this filter to the given node and children.
Definition filters.hh:76
implementation defined type
The result of the filtering process.
Definition filters.hh:81
Default simple filter that accepts any node and leaves its child structure unchanged.
Definition filters.hh:95
SimpleFilterTag FilterTag
Filter tag for deciding on filter application mechanism.
Definition filters.hh:98
Validates the combination of filter and node.
Definition filters.hh:104
static const bool value
True if the combination of filter and node is valid.
Definition filters.hh:106
Applies the filter to the given child node.
Definition filters.hh:120
static const bool value
True if the child will be included in the filtered node.
Definition filters.hh:122
Filter class for FilteredCompositeNode that selects the children with the given indices.
Definition filters.hh:162
Adapter class that takes a SimpleFilter, validated it and turns it into an AdvancedFilter.
Definition filters.hh:213
Apply the filter.
Definition filters.hh:218
filter_helper< Filter, 0, 0, Children... >::template apply ::type type
Definition filters.hh:222