From f7de1b851c6f77285d90fa29cd44c6f82969439f Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@tu-dortmund.de> Date: Sat, 16 Feb 2019 14:26:07 +0100 Subject: [PATCH] added walk() to traverse the tree --- Environment/VolumeTreeNode.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Environment/VolumeTreeNode.h b/Environment/VolumeTreeNode.h index 3331c41bf..093708a61 100644 --- a/Environment/VolumeTreeNode.h +++ b/Environment/VolumeTreeNode.h @@ -66,6 +66,24 @@ namespace corsika::environment { } } + /** + * Traverses the VolumeTree pre- or post-order and calls the functor \p func for each + * node. \p func takes a reference to VolumeTreeNode as argument. The return value \p + * func is ignored. + */ + template <typename TCallable, bool preorder = true> + void walk(TCallable func) { + if constexpr (preorder) { + func(*this); + std::for_each(fChildNodes.begin(), fChildNodes.end(), + [&](auto& v) { v->walk(func); }); + } else { + std::for_each(fChildNodes.begin(), fChildNodes.end(), + [&](auto& v) { v->walk(func); }); + t(*this); + } + } + void AddChild(VTNUPtr pChild) { pChild->fParentNode = this; fChildNodes.push_back(std::move(pChild)); @@ -88,6 +106,8 @@ namespace corsika::environment { auto const& GetModelProperties() const { return *fModelProperties; } + IMPSharedPtr GetModelPropertiesPtr() const { return fModelProperties; } + template <typename TModelProperties, typename... Args> auto SetModelProperties(Args&&... args) { static_assert(std::is_base_of_v<IModelProperties, TModelProperties>, -- GitLab