Loading...
Searching...
No Matches
filteredcompositenode.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-GPL-2.0-only-with-PDELab-exception
#ifndef DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
#define DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
#include <memory>
#include <tuple>
#include <type_traits>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/filters.hh>
#include <dune/common/shared_ptr.hh>
#include <dune/common/typetraits.hh>
#include <dune/common/indices.hh>
#include <dune/typetree/filters.hh>
#include <dune/typetree/nodetags.hh>
namespace Dune {
namespace TypeTree {
#ifndef DOXYGEN
namespace {
// ********************************************************************************
// Utility structs for filter construction and application
// ********************************************************************************
// Gets the filter and wraps it in case of a SimpleFilter.
template<typename Filter, typename Tag>
struct get_filter;
// Helper struct to extract the child template parameter pack from the ChildTypes tuple.
template<typename Filter, typename Node, typename ChildTypes>
struct apply_filter_wrapper;
template<typename Filter, typename Node, typename... Children>
struct apply_filter_wrapper<Filter,Node,std::tuple<Children...> >
: public Filter::template apply<Node,Children...>
{};
// specialization for SimpleFilter
template<typename Filter>
struct get_filter<Filter,SimpleFilterTag>
{
struct type
{
template<typename Node, typename ChildTypes>
struct apply
: public apply_filter_wrapper<filter<Filter>,Node,ChildTypes>
{};
};
};
// specialization for AdvancedFilter
template<typename Filter>
struct get_filter<Filter,AdvancedFilterTag>
{
struct type
{
template<typename Node, typename ChildTypes>
struct apply
: public apply_filter_wrapper<Filter,Node,ChildTypes>
{};
};
};
} // anonymous namespace
#endif // DOXYGEN
template<typename Node, typename Filter>
class FilteredCompositeNode
{
typedef typename get_filter<Filter,typename Filter::FilterTag>::type filter;
typedef typename filter::template apply<Node,typename Node::ChildTypes>::type filter_result;
typedef typename filter_result::template apply<Node> mapped_children;
static const bool nodeIsConst = std::is_const<typename std::remove_reference<Node>::type>::value;
template<std::size_t k>
struct lazy_enable
{
static const bool value = !nodeIsConst;
};
public:
typedef CompositeNodeTag NodeTag;
typedef typename mapped_children::NodeStorage NodeStorage;
typedef typename mapped_children::ChildTypes ChildTypes;
static const bool isLeaf = false;
static const bool isPower = false;
static const bool isComposite = true;
static constexpr auto degree ()
{
return std::integral_constant<std::size_t,filter_result::size>{};
}
template<std::size_t k>
struct Child {
#ifndef DOXYGEN
typedef typename std::tuple_element<k,typename mapped_children::Children>::type OriginalChild;
static const std::size_t mapped_index = std::tuple_element<k,typename filter_result::IndexMap>::type::original_index;
#endif // DOXYGEN
typedef typename OriginalChild::Type Type;
typedef typename OriginalChild::type type;
};
template<std::size_t k,
typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
auto& child (index_constant<k> = {})
{
return _node->template child<Child<k>::mapped_index>();
}
template<std::size_t k>
const auto& child (index_constant<k> = {}) const
{
return _node->template child<Child<k>::mapped_index>();
}
template<std::size_t k,
typename std::enable_if<lazy_enable<k>::value, int>::type = 0>
auto childStorage (index_constant<k> = {})
{
return _node->template childStorage<Child<k>::mapped_index>();
}
template<std::size_t k>
auto childStorage (index_constant<k> = {}) const
{
return _node->template childStorage<Child<k>::mapped_index>();
}
template<std::size_t k, class ChildType>
void setChild (ChildType&& child, typename std::enable_if<lazy_enable<k>::value,void*>::type = 0)
{
_node->template setChild<Child<k>::mapped_index>(std::forward<ChildType>(child));
}
protected:
template<bool enabled = !nodeIsConst>
typename std::enable_if<enabled,Node&>::type
unfiltered ()
{
return *_node;
}
const Node& unfiltered () const
{
return *_node;
}
template<bool enabled = !nodeIsConst>
typename std::enable_if<enabled,std::shared_ptr<Node> >::type
unfilteredStorage ()
{
return _node;
}
std::shared_ptr<const Node> unfilteredStorage () const
{
return _node;
}
public:
FilteredCompositeNode (std::shared_ptr<Node> node)
: _node(std::move(node))
{}
FilteredCompositeNode (Node& node)
: _node(stackobject_to_shared_ptr(node))
{}
private:
std::shared_ptr<Node> _node;
};
} // namespace TypeTree
} //namespace Dune
#endif // DUNE_TYPETREE_FILTEREDCOMPOSITENODE_HH
nodetags.hh
filters.hh
Dune
Definition accumulate_static.hh:17
Dune::TypeTree
Definition accumulate_static.hh:18
Dune::TypeTree::childStorage
auto childStorage(Node &&node, Indices... indices)
Definition childextraction.hh:75
Dune::TypeTree::FilteredCompositeNode::childStorage
auto childStorage(index_constant< k >={}) const
Returns the storage of the k-th child (const version).
Definition filteredcompositenode.hh:181
Dune::TypeTree::FilteredCompositeNode::degree
static constexpr auto degree()
Definition filteredcompositenode.hh:117
Dune::TypeTree::FilteredCompositeNode::NodeStorage
mapped_children::NodeStorage NodeStorage
The type used for storing the children.
Definition filteredcompositenode.hh:103
Dune::TypeTree::FilteredCompositeNode::setChild
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
Dune::TypeTree::FilteredCompositeNode::isLeaf
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition filteredcompositenode.hh:109
Dune::TypeTree::FilteredCompositeNode::unfiltered
const Node & unfiltered() const
Returns the unfiltered node (const version).
Definition filteredcompositenode.hh:215
Dune::TypeTree::FilteredCompositeNode::isComposite
static const bool isComposite
Mark this class as a composite in the dune-typetree.
Definition filteredcompositenode.hh:115
Dune::TypeTree::FilteredCompositeNode::unfilteredStorage
std::enable_if< enabled, std::shared_ptr< Node > >::type unfilteredStorage()
Returns the storage object of the unfiltered node.
Definition filteredcompositenode.hh:226
Dune::TypeTree::FilteredCompositeNode::isPower
static const bool isPower
Mark this class as a non power in the dune-typetree.
Definition filteredcompositenode.hh:112
Dune::TypeTree::FilteredCompositeNode::FilteredCompositeNode
FilteredCompositeNode(Node &node)
Initialize the CompositeNode with a copy of the passed-in storage type.
Definition filteredcompositenode.hh:253
Dune::TypeTree::FilteredCompositeNode::FilteredCompositeNode
FilteredCompositeNode(std::shared_ptr< Node > node)
Initialize the CompositeNode with copies of the passed in Storage objects.
Definition filteredcompositenode.hh:248
Dune::TypeTree::FilteredCompositeNode::childStorage
auto childStorage(index_constant< k >={})
Returns the storage of the k-th child.
Definition filteredcompositenode.hh:171
Dune::TypeTree::FilteredCompositeNode::child
const auto & child(index_constant< k >={}) const
Returns the k-th child (const version).
Definition filteredcompositenode.hh:160
Dune::TypeTree::FilteredCompositeNode::child
auto & child(index_constant< k >={})
Returns the k-th child.
Definition filteredcompositenode.hh:150
Dune::TypeTree::FilteredCompositeNode::NodeTag
CompositeNodeTag NodeTag
The type tag that describes a CompositeNode.
Definition filteredcompositenode.hh:100
Dune::TypeTree::FilteredCompositeNode::ChildTypes
mapped_children::ChildTypes ChildTypes
A tuple storing the types of all children.
Definition filteredcompositenode.hh:106
Dune::TypeTree::FilteredCompositeNode::unfiltered
std::enable_if< enabled, Node & >::type unfiltered()
Returns the unfiltered node.
Definition filteredcompositenode.hh:206
Dune::TypeTree::FilteredCompositeNode::unfilteredStorage
std::shared_ptr< const Node > unfilteredStorage() const
Returns the storage object of the unfiltered node (const version).
Definition filteredcompositenode.hh:235
Dune::TypeTree::FilteredCompositeNode::Child
Access to the type and storage type of the i-th child.
Definition filteredcompositenode.hh:124
Dune::TypeTree::FilteredCompositeNode::Child::type
OriginalChild::type type
The type of the child.
Definition filteredcompositenode.hh:138
Dune::TypeTree::FilteredCompositeNode::Child::Type
OriginalChild::Type Type
The type of the child.
Definition filteredcompositenode.hh:135
Dune::TypeTree::SimpleFilterTag
Tag describing a simple filter that can only decide whether or not to include a single given child.
Definition filters.hh:58
Dune::TypeTree::AdvancedFilterTag
Tag describing an advanced filter that has full control over the construction of the list of FilterEn...
Definition filters.hh:61
Dune::TypeTree::CompositeNodeTag
Tag designating a composite node.
Definition nodetags.hh:27