4 #ifndef DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
5 #define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
7 #if !(HAVE_VARIADIC_TEMPLATES || DOXYGEN || HEADERCHECK)
8 #error The class FilteredCompositeNode requires compiler support for variadic templates, which your compiler lacks.
11 #if (HAVE_VARIADIC_TEMPLATES || DOXYGEN)
12 #include <dune/common/shared_ptr.hh>
13 #include <dune/common/static_assert.hh>
14 #include <dune/common/tuples.hh>
15 #include <dune/common/typetraits.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,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 = IsConst<typename 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;
119 template<std::
size_t k>
124 typedef typename tuple_element<k,typename mapped_children::Children>::type OriginalChild;
126 static const std::size_t mapped_index = tuple_element<k,typename filter_result::IndexMap>::type::original_index;
134 typedef typename OriginalChild::type
type;
137 typedef typename OriginalChild::Storage
Storage;
150 template<std::
size_t k>
154 return _node->template child<Child<k>::mapped_index>();
161 template<std::
size_t k>
164 return _node->template child<Child<k>::mapped_index>();
171 template<std::
size_t k>
175 return _node->template childStorage<Child<k>::mapped_index>();
185 template<std::
size_t k>
188 return _node->template childStorage<Child<k>::mapped_index>();
192 template<std::
size_t k>
195 _node->template childStorage<Child<k>::mapped_index>() = stackobject_to_shared_ptr(child);
199 template<std::
size_t k>
202 _node->template childStorage<Child<k>::mapped_index>() = child;
216 template<
bool enabled = !nodeIsConst>
217 typename enable_if<enabled,Node&>::type
236 template<
bool enabled = !nodeIsConst>
237 typename enable_if<enabled,shared_ptr<Node> >::type
266 : _node(stackobject_to_shared_ptr(node))
272 shared_ptr<Node> _node;
280 #endif // (HAVE_VARIADIC_TEMPLATES || DOXYGEN)
282 #endif // DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
OriginalChild::Storage Storage
The storage type of the child.
Definition: filteredcompositenode.hh:137
Child< k >::ConstStorage childStorage() const
Returns the storage of the i-th child (const version).
Definition: filteredcompositenode.hh:186
Access to the type and storage type of the i-th child.
Definition: filteredcompositenode.hh:120
shared_ptr< const Node > unfilteredStorage() const
Returns the storage object of the unfiltered node (const version).
Definition: filteredcompositenode.hh:247
OriginalChild::type type
The type of the child.
Definition: filteredcompositenode.hh:134
enable_if< lazy_enable< k >::value, typename Child< k >::Storage >::type childStorage()
Returns the storage of the i-th child.
Definition: filteredcompositenode.hh:173
VariadicCompositeNodeTag NodeTag
The type tag that describes a VariadicCompositeNode.
Definition: filteredcompositenode.hh:98
enable_if< enabled, shared_ptr< Node > >::type unfilteredStorage()
Returns the storage object of the unfiltered node.
Definition: filteredcompositenode.hh:238
mapped_children::ChildTypes ChildTypes
A tuple storing the types of all children.
Definition: filteredcompositenode.hh:104
OriginalChild::Type Type
The type of the child.
Definition: filteredcompositenode.hh:131
enable_if< lazy_enable< k >::value, typename Child< k >::Type & >::type child()
Returns the i-th child.
Definition: filteredcompositenode.hh:152
OriginalChild::ConstStorage ConstStorage
The const storage type of the child.
Definition: filteredcompositenode.hh:140
FilteredCompositeNode(Node &node)
Initialize the VariadicCompositeNode with a copy of the passed-in storage type.
Definition: filteredcompositenode.hh:265
enable_if< enabled, Node & >::type unfiltered()
Returns the unfiltered node.
Definition: filteredcompositenode.hh:218
static const std::size_t CHILDREN
The number of children.
Definition: filteredcompositenode.hh:116
FilteredCompositeNode(shared_ptr< Node > node)
Initialize the VariadicCompositeNode with copies of the passed in Storage objects.
Definition: filteredcompositenode.hh:260
Tag designating a composite node that is based on variadic templates.
Definition: nodetags.hh:25
const Child< k >::Type & child() const
Returns the i-th child (const version).
Definition: filteredcompositenode.hh:162
void setChild(typename Child< k >::storage_type child, typename enable_if< lazy_enable< k >::value, void * >::type=0)
Sets the storage of the i-th child to the passed-in value.
Definition: filteredcompositenode.hh:200
mapped_children::NodeStorage NodeStorage
The type used for storing the children.
Definition: filteredcompositenode.hh:101
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition: filteredcompositenode.hh:107
const Node & unfiltered() const
Returns the unfiltered node (const version).
Definition: filteredcompositenode.hh:227
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition: filteredcompositenode.hh:110
Base class for composite nodes representing a filtered view on an underlying composite node...
Definition: filteredcompositenode.hh:80
void setChild(typename Child< k >::type &child, typename enable_if< lazy_enable< k >::value, void * >::type=0)
Sets the i-th child to the passed-in value.
Definition: filteredcompositenode.hh:193
static const std::size_t value
Definition: compositenode.hh:38
Type
Definition: treepath.hh:26
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition: filteredcompositenode.hh:113