Loading...
Searching...
No Matches
dynamicpowernode.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_DYNAMICPOWERNODE_HH
#define DUNE_TYPETREE_DYNAMICPOWERNODE_HH
#include <cassert>
#include <vector>
#include <memory>
#include <type_traits>
#include <dune/common/typetraits.hh>
#include <dune/common/std/type_traits.hh>
#include <dune/typetree/nodetags.hh>
#include <dune/typetree/utility.hh>
#include <dune/typetree/typetraits.hh>
namespace Dune {
namespace TypeTree {
template<typename T>
class DynamicPowerNode
{
public:
static const bool isLeaf = false;
static const bool isPower = true;
static const bool isComposite = false;
std::size_t degree() const
{
return _children.size();
}
typedef DynamicPowerNodeTag NodeTag;
typedef T ChildType;
typedef std::shared_ptr<T> ChildStorageType;
typedef std::shared_ptr<const T> ChildConstStorageType;
typedef std::vector<ChildStorageType> NodeStorage;
ChildType& child (std::size_t i)
{
assert(i < degree() && "child index out of range");
return *_children[i];
}
const ChildType& child (std::size_t i) const
{
assert(i < degree() && "child index out of range");
return *_children[i];
}
ChildStorageType childStorage (std::size_t i)
{
assert(i < degree() && "child index out of range");
return _children[i];
}
ChildConstStorageType childStorage (std::size_t i) const
{
assert(i < degree() && "child index out of range");
return _children[i];
}
void setChild (std::size_t i, ChildType& t)
{
assert(i < degree() && "child index out of range");
_children[i] = stackobject_to_shared_ptr(t);
}
void setChild (std::size_t i, ChildType&& t)
{
assert(i < degree() && "child index out of range");
_children[i] = convert_arg(std::move(t));
}
void setChild (std::size_t i, ChildStorageType st)
{
assert(i < degree() && "child index out of range");
_children[i] = std::move(st);
}
const NodeStorage& nodeStorage () const
{
return _children;
}
protected:
DynamicPowerNode () = delete;
explicit DynamicPowerNode (std::size_t size)
: _children(size)
{}
explicit DynamicPowerNode (NodeStorage children)
: _children(std::move(children))
{}
#ifdef DOXYGEN
DynamicPowerNode (T& t1, T& t2, ...)
{}
#else
template<typename... Children,
std::enable_if_t<(std::is_same_v<ChildType, std::decay_t<Children>> &&...), bool> = true>
DynamicPowerNode (Children&&... children)
{
_children = NodeStorage{convert_arg(std::forward<Children>(children))...};
}
template<typename... Children,
std::enable_if_t<(std::is_same_v<ChildType, std::decay_t<Children>> &&...), bool> = true>
DynamicPowerNode (std::shared_ptr<Children>... children)
{
_children = NodeStorage{std::move(children)...};
}
#endif // DOXYGEN
private:
NodeStorage _children;
};
} // namespace TypeTree
} //namespace Dune
#endif // DUNE_TYPETREE_DYNAMICPOWERNODE_HH
typetraits.hh
nodetags.hh
utility.hh
Dune
Definition accumulate_static.hh:17
Dune::TypeTree
Definition accumulate_static.hh:18
Dune::TypeTree::DynamicPowerNode::isPower
static const bool isPower
Mark this class as a power in the dune-typetree.
Definition dynamicpowernode.hh:43
Dune::TypeTree::DynamicPowerNode::NodeStorage
std::vector< ChildStorageType > NodeStorage
The type used for storing the children.
Definition dynamicpowernode.hh:67
Dune::TypeTree::DynamicPowerNode::nodeStorage
const NodeStorage & nodeStorage() const
Definition dynamicpowernode.hh:137
Dune::TypeTree::DynamicPowerNode::childStorage
ChildConstStorageType childStorage(std::size_t i) const
Returns the storage of the i-th child (const version).
Definition dynamicpowernode.hh:110
Dune::TypeTree::DynamicPowerNode::child
const ChildType & child(std::size_t i) const
Returns the i-th child (const version).
Definition dynamicpowernode.hh:87
Dune::TypeTree::DynamicPowerNode::ChildStorageType
std::shared_ptr< T > ChildStorageType
The storage type of each child.
Definition dynamicpowernode.hh:61
Dune::TypeTree::DynamicPowerNode::DynamicPowerNode
DynamicPowerNode(T &t1, T &t2,...)
Initialize all children with the passed-in objects.
Definition dynamicpowernode.hh:174
Dune::TypeTree::DynamicPowerNode::ChildConstStorageType
std::shared_ptr< const T > ChildConstStorageType
The const version of the storage type of each child.
Definition dynamicpowernode.hh:64
Dune::TypeTree::DynamicPowerNode::DynamicPowerNode
DynamicPowerNode(NodeStorage children)
Initialize the DynamicPowerNode with a copy of the passed-in storage type.
Definition dynamicpowernode.hh:167
Dune::TypeTree::DynamicPowerNode::NodeTag
DynamicPowerNodeTag NodeTag
The type tag that describes the node.
Definition dynamicpowernode.hh:55
Dune::TypeTree::DynamicPowerNode::ChildType
T ChildType
The type of each child.
Definition dynamicpowernode.hh:58
Dune::TypeTree::DynamicPowerNode::setChild
void setChild(std::size_t i, ChildType &t)
Sets the i-th child to the passed-in value.
Definition dynamicpowernode.hh:117
Dune::TypeTree::DynamicPowerNode::setChild
void setChild(std::size_t i, ChildStorageType st)
Sets the stored value representing the i-th child to the passed-in value.
Definition dynamicpowernode.hh:131
Dune::TypeTree::DynamicPowerNode::DynamicPowerNode
DynamicPowerNode(std::size_t size)
Construct a node with the given number of children.
Definition dynamicpowernode.hh:162
Dune::TypeTree::DynamicPowerNode::isComposite
static const bool isComposite
Mark this class as a non composite in the dune-typetree.
Definition dynamicpowernode.hh:46
Dune::TypeTree::DynamicPowerNode::setChild
void setChild(std::size_t i, ChildType &&t)
Store the passed value in i-th child.
Definition dynamicpowernode.hh:124
Dune::TypeTree::DynamicPowerNode::child
ChildType & child(std::size_t i)
Returns the i-th child.
Definition dynamicpowernode.hh:77
Dune::TypeTree::DynamicPowerNode::degree
std::size_t degree() const
The number of children.
Definition dynamicpowernode.hh:49
Dune::TypeTree::DynamicPowerNode::childStorage
ChildStorageType childStorage(std::size_t i)
Returns the storage of the i-th child.
Definition dynamicpowernode.hh:97
Dune::TypeTree::DynamicPowerNode::isLeaf
static const bool isLeaf
Mark this class as non leaf in the dune-typetree.
Definition dynamicpowernode.hh:40
Dune::TypeTree::DynamicPowerNode::DynamicPowerNode
DynamicPowerNode()=delete
Dune::TypeTree::DynamicPowerNodeTag
Tag designating a power node with runtime degree.
Definition nodetags.hh:24