6#ifndef DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
7#define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
15#include <dune/common/shared_ptr.hh>
16#include <dune/common/typetraits.hh>
17#include <dune/common/indices.hh>
38 template<
typename Filter,
typename Tag>
42 template<
typename Filter,
typename Node,
typename ChildTypes>
43 struct apply_filter_wrapper;
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...>
51 template<
typename Filter>
52 struct get_filter<Filter,SimpleFilterTag>
56 template<
typename Node,
typename ChildTypes>
58 :
public apply_filter_wrapper<filter<Filter>,Node,ChildTypes>
64 template<
typename Filter>
65 struct get_filter<Filter,AdvancedFilterTag>
69 template<
typename Node,
typename ChildTypes>
71 :
public apply_filter_wrapper<Filter,Node,ChildTypes>
81 template<
typename Node,
typename Filter>
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;
89 static const bool nodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
91 template<std::
size_t k>
94 static const bool value = !nodeIsConst;
119 return std::integral_constant<std::size_t,filter_result::size>{};
123 template<std::
size_t k>
128 typedef typename std::tuple_element<k,typename mapped_children::Children>::type OriginalChild;
130 static const std::size_t mapped_index = std::tuple_element<k,typename filter_result::IndexMap>::type::original_index;
135 typedef typename OriginalChild::Type
Type;
138 typedef typename OriginalChild::type
type;
148 template<std::size_t k,
149 typename std::enable_if<lazy_enable<k>::value,
int>::type = 0>
150 auto&
child (index_constant<k> = {})
152 return _node->template child<Child<k>::mapped_index>();
159 template<std::
size_t k>
160 const auto&
child (index_constant<k> = {})
const
162 return _node->template child<Child<k>::mapped_index>();
169 template<std::size_t k,
170 typename std::enable_if<lazy_enable<k>::value,
int>::type = 0>
173 return _node->template childStorage<Child<k>::mapped_index>();
180 template<std::
size_t k>
183 return _node->template childStorage<Child<k>::mapped_index>();
187 template<std::
size_t k,
class ChildType>
188 void setChild (ChildType&&
child,
typename std::enable_if<lazy_enable<k>::value,
void*>::type = 0)
190 _node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(
child));
204 template<
bool enabled = !nodeIsConst>
205 typename std::enable_if<enabled,Node&>::type
224 template<
bool enabled = !nodeIsConst>
225 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
249 : _node(std::move(node))
254 : _node(stackobject_to_shared_ptr(node))
260 std::shared_ptr<Node> _node;
Definition accumulate_static.hh:16
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
static constexpr auto degree()
Definition filteredcompositenode.hh:117
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
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
Tag designating a composite node.
Definition nodetags.hh:27