DUNE PDELab (2.8)

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