Commit 96bb98d2 authored by Steffen Müthing's avatar Steffen Müthing

[Cleanup] Replace ::CHILDREN with degree() and staticDegree<>

parent 2a1f33b9
......@@ -5,6 +5,7 @@
#define DUNE_TYPETREE_ACCUMULATE_STATIC_HH
#include <dune/common/typetraits.hh>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/treepath.hh>
......@@ -149,7 +150,7 @@ namespace Dune {
typedef typename Node::template Child<i>::Type child;
static const result_type child_result = accumulate_value<child,Functor,Reduction,ParentChildReduction,current_value,child_tree_path,typename child::NodeTag>::result;
static const result_type child_result = accumulate_value<child,Functor,Reduction,ParentChildReduction,current_value,child_tree_path,NodeTag<child>>::result;
static const result_type result = accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,child_result,TreePath,i+1,n>::result;
......@@ -174,7 +175,7 @@ namespace Dune {
typedef typename Functor::result_type result_type;
static const result_type child_result = accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,0,Node::CHILDREN>::result;
static const result_type child_result = accumulate_over_children<Node,Functor,Reduction,ParentChildReduction,current_value,TreePath,0,staticDegree<Node>>::result;
static const result_type result =
accumulate_node_helper<Node,Functor,ParentChildReduction,child_result,TreePath,Functor::template doVisit<Node,TreePath>::value>::result;
......@@ -261,7 +262,7 @@ namespace Dune {
typedef typename Functor::result_type result_type;
//! The accumulated result of the computation.
static const result_type result = accumulate_value<Tree,Functor,Reduction,ParentChildReduction,startValue,TreePath<>,typename Tree::NodeTag>::result;
static const result_type result = accumulate_value<Tree,Functor,Reduction,ParentChildReduction,startValue,TreePath<>,NodeTag<Tree>>::result;
};
......@@ -415,7 +416,7 @@ namespace Dune {
current_type,
TreePath,
0,
Node::CHILDREN
staticDegree<Node>
>::type children_result_type;
typedef typename accumulate_type_node_helper<
......
......@@ -6,6 +6,7 @@
#include <dune/common/typetraits.hh>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/treepath.hh>
#include <dune/typetree/visitor.hh>
......@@ -219,9 +220,9 @@ namespace Dune {
v.pre(std::forward<N>(n),tp);
typedef typename std::remove_reference<N>::type Node;
typedef typename std::remove_reference<V>::type Visitor;
apply_to_children<Visitor::treePathType,Node::CHILDREN>::apply(std::forward<N>(n),
std::forward<V>(v),
tp);
apply_to_children<Visitor::treePathType,staticDegree<Node>>::apply(std::forward<N>(n),
std::forward<V>(v),
tp);
v.post(std::forward<N>(n),tp);
}
......
......@@ -6,6 +6,7 @@
#include <dune/common/typetraits.hh>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/treepath.hh>
#include <dune/typetree/visitor.hh>
......@@ -242,17 +243,15 @@ namespace Dune {
apply(N1&& n1, N2&& n2, V&& v, TreePath tp)
{
v.pre(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
typedef typename std::remove_reference<N1>::type Node1;
typedef typename std::remove_reference<N2>::type Node2;
// make sure both nodes have the same number of children - otherwise, it
// would be difficult to match the children to each other.
static_assert(Node1::CHILDREN == Node2::CHILDREN,
static_assert(staticDegree<N1> == staticDegree<N2>,
"non-leaf nodes with different numbers of children " \
"are not allowed during simultaneous grid traversal");
apply_to_children_pair<treePathType,Node1::CHILDREN>::apply(std::forward<N1>(n1),
std::forward<N2>(n2),
std::forward<V>(v),
tp);
apply_to_children_pair<treePathType,staticDegree<N1>>::apply(std::forward<N1>(n1),
std::forward<N2>(n2),
std::forward<V>(v),
tp);
v.post(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
}
......
......@@ -7,6 +7,7 @@
#include <array>
#include <memory>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/powercompositenodetransformationtemplates.hh>
#include <dune/common/exceptions.hh>
......@@ -61,19 +62,19 @@ namespace Dune {
};
template<typename TC>
static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,staticDegree<typename result<TC>::type>>& children)
{
return typename result<TC>::type(s,t,children);
}
template<typename TC>
static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
static typename result<TC>::type transform(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,staticDegree<typename result<TC>::type>>& children)
{
return typename result<TC>::type(s,t,children);
}
template<typename TC>
static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,staticDegree<typename result<TC>::type>>& children)
{
return std::make_shared<typename result<TC>::type>(s,t,children);
}
......
......@@ -4,6 +4,7 @@
#ifndef DUNE_TYPETREE_PAIRTRAVERSAL_HH
#define DUNE_TYPETREE_PAIRTRAVERSAL_HH
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/treepath.hh>
#include <dune/typetree/visitor.hh>
......@@ -120,12 +121,12 @@ namespace Dune {
typedef typename std::remove_reference<N2>::type Node2;
typedef typename Node1::template Child<0>::Type C1;
typedef typename Node2::template Child<0>::Type C2;
static_assert(Node1::CHILDREN == Node2::CHILDREN,
static_assert(staticDegree<Node1> == staticDegree<Node2>,
"non-leaf nodes with different numbers of children " \
"are not allowed during simultaneous grid traversal");
const bool visit = std::remove_reference<V>::type
::template VisitChild<Node1,C1,Node2,C2,typename TreePath::ViewType>::value;
for (std::size_t k = 0; k < Node1::CHILDREN; ++k)
for (std::size_t k = 0; k < degree(n1); ++k)
{
v.beforeChild(std::forward<N1>(n1),n1.child(k),std::forward<N2>(n2),n2.child(k),tp.view(),k);
tp.push_back(k);
......@@ -138,7 +139,7 @@ namespace Dune {
tp);
tp.pop_back();
v.afterChild(std::forward<N1>(n1),n1.child(k),std::forward<N2>(n2),n2.child(k),tp.view(),k);
if (k < Node1::CHILDREN-1)
if (k < degree(n1) - 1)
v.in(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
}
v.post(std::forward<N1>(n1),std::forward<N2>(n2),tp.view());
......
......@@ -6,6 +6,8 @@
#include <cstddef>
#include <dune/typetree/nodeinterface.hh>
namespace Dune {
namespace TypeTree {
......@@ -20,7 +22,7 @@ namespace Dune {
template<typename TC>
struct result
{
typedef TransformedNode<SourceNode,TC,SourceNode::CHILDREN> type;
typedef TransformedNode<SourceNode,TC,staticDegree<SourceNode>> type;
};
};
......
......@@ -7,6 +7,7 @@
#include <array>
#include <memory>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/common/exceptions.hh>
......@@ -50,18 +51,18 @@ namespace Dune {
template<typename TC>
struct result
{
typedef TransformedNode<TC, SourceNode::CHILDREN> type;
typedef TransformedNode<TC, staticDegree<SourceNode>> type;
typedef std::shared_ptr<type> storage_type;
};
template<typename TC>
static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
static typename result<TC>::type transform(const SourceNode& s, const Transformation& t, const std::array<std::shared_ptr<TC>,staticDegree<typename result<TC>::type>>& children)
{
return typename result<TC>::type(children);
}
template<typename TC>
static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,result<TC>::type::CHILDREN>& children)
static typename result<TC>::storage_type transform_storage(std::shared_ptr<const SourceNode> s, const Transformation& t, const std::array<std::shared_ptr<TC>,staticDegree<result<TC>::type>>& children)
{
return std::make_shared<typename result<TC>::type>(children);
}
......
......@@ -11,6 +11,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/typetraits.hh>
#include <dune/typetree/typetraits.hh>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/utility.hh>
......@@ -276,7 +277,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_type transformed_child;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<std::shared_ptr<transformed_child>,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(s.childStorage(k),t);
......@@ -290,7 +291,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_type transformed_child;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<std::shared_ptr<transformed_child>,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(s.childStorage(k),t);
......@@ -305,7 +306,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_type transformed_child;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<std::shared_ptr<transformed_child>,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(sp->childStorage(k),t);
......@@ -319,7 +320,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_type transformed_child;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<std::shared_ptr<transformed_child>,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(sp->childStorage(k),t);
......@@ -333,7 +334,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_storage_type transformed_child_storage;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<transformed_child_storage,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(sp->childStorage(k),t);
......@@ -346,7 +347,7 @@ namespace Dune {
// transform children
typedef TransformTree<typename S::ChildType,T,typename S::ChildType::NodeTag,ChildNodeTransformation::recursive> ChildTreeTransformation;
typedef typename ChildTreeTransformation::transformed_storage_type transformed_child_storage;
const std::size_t child_count = S::CHILDREN;
const std::size_t child_count = staticDegree<S>;
std::array<transformed_child_storage,child_count> children;
for (std::size_t k = 0; k < child_count; ++k) {
children[k] = ChildTreeTransformation::transform_storage(sp->childStorage(k),t);
......
......@@ -118,7 +118,7 @@ namespace Dune {
const bool visit = Visitor::template VisitChild<Node,C,typename TreePath::ViewType>::value;
// iterate over children
for (std::size_t k = 0; k < Node::CHILDREN; ++k)
for (std::size_t k = 0; k < degree(n); ++k)
{
// always call beforeChild(), regardless of the value of visit
v.beforeChild(std::forward<N>(n),n.child(k),tp.view(),k);
......@@ -136,7 +136,7 @@ namespace Dune {
v.afterChild(std::forward<N>(n),n.child(k),tp.view(),k);
// if this is not the last child, call infix callback
if (k < Node::CHILDREN-1)
if (k < degree(n) - 1)
v.in(std::forward<N>(n),tp.view());
}
......
......@@ -11,6 +11,7 @@
#include <dune/common/shared_ptr.hh>
#include <dune/common/indices.hh>
#include <dune/typetree/nodeinterface.hh>
#include <dune/typetree/nodetags.hh>
namespace Dune {
......@@ -112,9 +113,9 @@ namespace Dune {
static const std::size_t depth = 1 + ChildInfo::depth;
static const std::size_t nodeCount = 1 + Node::CHILDREN * ChildInfo::nodeCount;
static const std::size_t nodeCount = 1 + staticDegree<Node> * ChildInfo::nodeCount;
static const std::size_t leafCount = Node::CHILDREN * ChildInfo::leafCount;
static const std::size_t leafCount = staticDegree<Node> * ChildInfo::leafCount;
};
......@@ -162,7 +163,7 @@ namespace Dune {
struct GenericCompositeNodeInfo
{
typedef generic_compositenode_children_info<Node,0,Node::CHILDREN> Children;
typedef generic_compositenode_children_info<Node,0,staticDegree<Node>> Children;
static const std::size_t depth = 1 + Children::maxDepth;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment