/usr/include/dune/functions/functionspacebases/nodes.hh is in libdune-functions-dev 2.5.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
#include <dune/typetree/leafnode.hh>
#include <dune/typetree/powernode.hh>
#include <dune/typetree/compositenode.hh>
#include <dune/typetree/traversal.hh>
#include <dune/typetree/visitor.hh>
namespace Dune {
namespace Functions {
namespace {
template<typename size_type>
struct ClearSizeVisitor
: public TypeTree::TreeVisitor
, public TypeTree::DynamicTraversal
{
template<typename Node, typename TreePath>
void pre(Node& node, TreePath treePath)
{
leaf(node,treePath);
node.setSize(0);
}
template<typename Node, typename TreePath>
void leaf(Node& node, TreePath treePath)
{
node.setOffset(offset_);
}
ClearSizeVisitor(size_type offset)
: offset_(offset)
{}
const size_type offset_;
};
template<typename Entity, typename size_type>
struct BindVisitor
: public TypeTree::TreeVisitor
, public TypeTree::DynamicTraversal
{
template<typename Node, typename TreePath>
void pre(Node& node, TreePath treePath)
{
node.setOffset(offset_);
}
template<typename Node, typename TreePath>
void post(Node& node, TreePath treePath)
{
node.setSize(offset_ - node.offset());
}
template<typename Node, typename TreePath>
void leaf(Node& node, TreePath treePath)
{
node.setOffset(offset_);
node.bind(entity_);
offset_ += node.size();
}
BindVisitor(const Entity& entity, size_type offset = 0)
: entity_(entity)
, offset_(offset)
{}
const Entity& entity_;
size_type offset_;
};
template<typename size_type>
struct InitializeTreeVisitor :
public TypeTree::TreeVisitor,
public TypeTree::DynamicTraversal
{
template<typename Node, typename TreePath>
void pre(Node& node, TreePath treePath)
{
node.setTreeIndex(treeIndex_);
++treeIndex_;
}
template<typename Node, typename TreePath>
void leaf(Node& node, TreePath treePath)
{
node.setTreeIndex(treeIndex_);
++treeIndex_;
}
InitializeTreeVisitor(size_type treeIndexOffset = 0) :
treeIndex_(treeIndexOffset)
{}
size_type treeIndex_;
};
}
template<typename TP>
class BasisNodeMixin
{
template<typename>
friend struct ClearSizeVisitor;
template<typename,typename>
friend struct BindVisitor;
template<typename>
friend struct InitializeTreeVisitor;
public:
using TreePath = TP;
using size_type = std::size_t;
BasisNodeMixin(const TreePath& treePath) :
offset_(0),
size_(0),
treePath_(treePath),
treeIndex_(0)
{}
size_type localIndex(size_type i) const
{
return offset_ + i;
}
size_type size() const
{
return size_;
}
const TreePath& treePath() const
{
return treePath_;
}
const size_type treeIndex() const
{
return treeIndex_;
}
size_type offset() const
{
return offset_;
}
protected:
void setOffset(const size_type offset)
{
offset_ = offset;
}
void setSize(const size_type size)
{
size_ = size;
}
void setTreeIndex(const size_type treeIndex)
{
treeIndex_ = treeIndex;
}
private:
size_type offset_;
size_type size_;
const TreePath treePath_;
size_type treeIndex_;
};
template<typename SIZE_T_DUMMY, typename TP>
class LeafBasisNode :
public BasisNodeMixin<TP>,
public TypeTree::LeafNode
{
using Mixin = BasisNodeMixin<TP>;
public:
using TreePath = TP;
using size_type = std::size_t;
LeafBasisNode(TreePath treePath = TreePath()) :
Mixin(treePath)
{}
};
template<typename SIZE_T_DUMMY, typename TP, typename T, std::size_t n>
class PowerBasisNode :
public BasisNodeMixin<TP>,
public TypeTree::PowerNode<T,n>
{
using Mixin = BasisNodeMixin<TP>;
using Node = TypeTree::PowerNode<T,n>;
public:
PowerBasisNode(const TP& tp) :
Mixin(tp)
{}
PowerBasisNode(const TP& tp, const typename Node::NodeStorage& children) :
Mixin(tp),
Node(children)
{}
};
template<typename SIZE_T_DUMMY, typename TP, typename... T>
class CompositeBasisNode :
public BasisNodeMixin<TP>,
public TypeTree::CompositeNode<T...>
{
using Mixin = BasisNodeMixin<TP>;
using Node = TypeTree::CompositeNode<T...>;
public:
CompositeBasisNode(const TP& tp)
: Mixin(tp)
{}
CompositeBasisNode(const TP& tp, const typename Node::NodeStorage& children) :
Mixin(tp),
Node(children)
{}
template<typename... Children>
CompositeBasisNode(const shared_ptr<Children>&... children, const TP& tp)
: Mixin(tp)
, Node(children...)
{}
};
template<typename Tree>
void clearSize(Tree& tree, std::size_t offset)
{
TypeTree::applyToTree(tree,ClearSizeVisitor<std::size_t>(offset));
}
template<typename Tree, typename Entity>
void bindTree(Tree& tree, const Entity& entity, std::size_t offset = 0)
{
BindVisitor<Entity,std::size_t> visitor(entity,offset);
TypeTree::applyToTree(tree,visitor);
}
template<typename Tree>
void initializeTree(Tree& tree, std::size_t treeIndexOffset = 0)
{
InitializeTreeVisitor<std::size_t> visitor(treeIndexOffset);
TypeTree::applyToTree(tree,visitor);
}
} // namespace Functions
} // namespace Dune
#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NODES_HH
|