4 #ifndef DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
5 #define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
13 #include <dune/common/shared_ptr.hh>
14 #include <dune/common/typetraits.hh>
15 #include <dune/common/indices.hh>
36 template<
typename Filter,
typename Tag>
40 template<
typename Filter,
typename Node,
typename ChildTypes>
41 struct apply_filter_wrapper;
43 template<
typename Filter,
typename Node,
typename... Children>
44 struct apply_filter_wrapper<Filter,Node,std::tuple<Children...> >
45 :
public Filter::template apply<Node,Children...>
49 template<
typename Filter>
50 struct get_filter<Filter,SimpleFilterTag>
54 template<
typename Node,
typename ChildTypes>
56 :
public apply_filter_wrapper<filter<Filter>,Node,ChildTypes>
62 template<
typename Filter>
63 struct get_filter<Filter,AdvancedFilterTag>
67 template<
typename Node,
typename ChildTypes>
69 :
public apply_filter_wrapper<Filter,Node,ChildTypes>
79 template<
typename Node,
typename Filter>
83 typedef typename get_filter<Filter,typename Filter::FilterTag>::type filter;
84 typedef typename filter::template apply<Node,typename Node::ChildTypes>::type filter_result;
85 typedef typename filter_result::template apply<Node> mapped_children;
87 static const bool nodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
89 template<std::
size_t k>
92 static const bool value = !nodeIsConst;
116 static const std::size_t
CHILDREN = filter_result::size;
120 return std::integral_constant<std::size_t,filter_result::size>{};
124 template<std::
size_t k>
129 typedef typename std::tuple_element<k,typename mapped_children::Children>::type OriginalChild;
131 static const std::size_t mapped_index = std::tuple_element<k,typename filter_result::IndexMap>::type::original_index;
139 typedef typename OriginalChild::type
type;
149 template<std::size_t k,
150 typename std::enable_if<lazy_enable<k>::value,
int>::type = 0>
151 auto&
child (index_constant<k> = {})
153 return _node->template child<Child<k>::mapped_index>();
160 template<std::
size_t k>
161 const auto&
child (index_constant<k> = {})
const
163 return _node->template child<Child<k>::mapped_index>();
170 template<std::size_t k,
171 typename std::enable_if<lazy_enable<k>::value,
int>::type = 0>
174 return _node->template childStorage<Child<k>::mapped_index>();
181 template<std::
size_t k>
184 return _node->template childStorage<Child<k>::mapped_index>();
188 template<std::
size_t k,
class ChildType>
189 void setChild (ChildType&&
child,
typename std::enable_if<lazy_enable<k>::value,
void*>::type = 0)
191 _node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(
child));
205 template<
bool enabled = !nodeIsConst>
206 typename std::enable_if<enabled,Node&>::type
225 template<
bool enabled = !nodeIsConst>
226 typename std::enable_if<enabled,std::shared_ptr<Node> >::type
250 : _node(std::move(node))
255 : _node(stackobject_to_shared_ptr(node))
261 std::shared_ptr<Node> _node;
Definition: accumulate_static.hh:13
Type
Definition: treepath.hh:30
Base class for composite nodes representing a filtered view on an underlying composite node.
Definition: filteredcompositenode.hh:81
std::enable_if< enabled, std::shared_ptr< Node > >::type unfilteredStorage()
Returns the storage object of the unfiltered node.
Definition: filteredcompositenode.hh:227
auto childStorage(index_constant< k >={}) const
Returns the storage of the k-th child (const version).
Definition: filteredcompositenode.hh:182
static constexpr auto degree()
Definition: filteredcompositenode.hh:118
mapped_children::NodeStorage NodeStorage
The type used for storing the children.
Definition: filteredcompositenode.hh:101
const auto & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition: filteredcompositenode.hh:161
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:189
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: filteredcompositenode.hh:107
auto & child(index_constant< k >={})
Returns the k-th child.
Definition: filteredcompositenode.hh:151
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: filteredcompositenode.hh:113
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: filteredcompositenode.hh:110
std::shared_ptr< const Node > unfilteredStorage() const
Returns the storage object of the unfiltered node (const version).
Definition: filteredcompositenode.hh:236
FilteredCompositeNode(Node &node)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition: filteredcompositenode.hh:254
FilteredCompositeNode(std::shared_ptr< Node > node)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition: filteredcompositenode.hh:249
auto childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition: filteredcompositenode.hh:172
const Node & unfiltered() const
Returns the unfiltered node (const version).
Definition: filteredcompositenode.hh:216
std::enable_if< enabled, Node & >::type unfiltered()
Returns the unfiltered node.
Definition: filteredcompositenode.hh:207
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition: filteredcompositenode.hh:98
mapped_children::ChildTypes ChildTypes
A tuple storing the types of all children.
Definition: filteredcompositenode.hh:104
static const std::size_t CHILDREN
The number of children.
Definition: filteredcompositenode.hh:116
Access to the type and storage type of the i-th child.
Definition: filteredcompositenode.hh:125
OriginalChild::type type
The type of the child.
Definition: filteredcompositenode.hh:139
OriginalChild::Type Type
The type of the child.
Definition: filteredcompositenode.hh:136
Tag designating a composite node.
Definition: nodetags.hh:25