From 31f1acdf42997e29a36d72adc0462fef1671627c Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Tue, 3 Aug 2021 18:50:35 +0200 Subject: [PATCH] Add missing files --- .../core/base/detail/iteration_mixins.cpp | 6 + .../armem/core/base/detail/iteration_mixins.h | 190 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.cpp create mode 100644 source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.h diff --git a/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.cpp b/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.cpp new file mode 100644 index 000000000..857ca6220 --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.cpp @@ -0,0 +1,6 @@ +#include "AronTyped.h" + +namespace armarx::armem::base::detail +{ + +} diff --git a/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.h b/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.h new file mode 100644 index 000000000..7436a737b --- /dev/null +++ b/source/RobotAPI/libraries/armem/core/base/detail/iteration_mixins.h @@ -0,0 +1,190 @@ +#pragma once + + +namespace armarx::armem::base::detail +{ + + // Helper functions to implement the forEach*() method at the current level. + + // Single-valued containers. + template <class ContainerT, class FunctionT> + bool forEachChildSingle(ContainerT& container, FunctionT&& func) + { + for (auto& child : container) + { + if (!func(child)) + { + return false; + } + } + return true; + } + template <class ContainerT, class FunctionT> + bool forEachChildSingle(const ContainerT& container, FunctionT&& func) + { + for (const auto& child : container) + { + if (!func(child)) + { + return false; + } + } + return true; + } + + // Pair-valued containers. + template <class ContainerT, class FunctionT> + bool forEachChildPair(ContainerT& container, FunctionT&& func) + { + for (auto& [_, child] : container) + { + if (!func(child)) + { + return false; + } + } + return true; + } + template <class ContainerT, class FunctionT> + bool forEachChildPair(const ContainerT& container, FunctionT&& func) + { + for (const auto& [_, child] : container) + { + if (!func(child)) + { + return false; + } + } + return true; + } + + + // We use auto instead of, e.g. DerivedT::EntitySnapshotT, + // as we cannot use the typedef before DerivedT was completely defined. + + template <class DerivedT> + struct ForEachEntityInstanceMixin + { + // not: using EntitySnapshotT = typename DerivedT::EntitySnapshotT; + + /** + * @param func Function like: bool process(EntityInstanceT& instance)> + */ + template <class InstanceFunctionT> + bool forEachEntityInstance(InstanceFunctionT&& func) + { + return static_cast<DerivedT*>(this)->forEachEntitySnapshot( + [&func](auto & snapshot) -> bool + { + return snapshot.forEachEntityInstance(func); + }); + } + + /** + * @param func Function like: bool process(const EntityInstanceT& instance) + */ + template <class InstanceFunctionT> + bool forEachEntityInstance(InstanceFunctionT&& func) const + { + return static_cast<DerivedT*>(this)->forEachEntitySnapshot( + [&func](const auto & snapshot) -> bool + { + return snapshot.forEachEntityInstance(func); + }); + } + }; + + + template <class DerivedT> + struct ForEachEntitySnapshotMixin + { + /** + * @param func Function like: bool process(EntitySnapshotT& snapshot)> + */ + template <class SnapshotFunctionT> + bool forEachEntitySnapshot(SnapshotFunctionT&& func) + { + return static_cast<DerivedT*>(this)->forEachEntity( + [&func](auto & entity) -> bool + { + return entity.forEachEntitySnapshot(func); + }); + } + + /** + * @param func Function like: bool process(const EntitySnapshotT& snapshot) + */ + template <class SnapshotFunctionT> + bool forEachEntitySnapshot(SnapshotFunctionT&& func) const + { + return static_cast<DerivedT*>(this)->forEachEntity( + [&func](const auto & entity) -> bool + { + return entity.forEachEntitySnapshot(func); + }); + } + }; + + + template <class DerivedT> + struct ForEachEntityMixin + { + /** + * @param func Function like: bool process(EntityT& entity)> + */ + template <class FunctionT> + bool forEachEntity(FunctionT&& func) + { + return static_cast<DerivedT*>(this)->forEachProviderSegment( + [&func](auto & providerSegment) -> bool + { + return providerSegment.forEachEntity(func); + }); + } + + /** + * @param func Function like: bool process(const EntityT& entity) + */ + template <class FunctionT> + bool forEachEntity(FunctionT&& func) const + { + return static_cast<DerivedT*>(this)->forEachProviderSegment( + [&func](const auto & providerSegment) -> bool + { + return providerSegment.forEachEntity(func); + }); + } + }; + + + template <class DerivedT> + struct ForEachProviderSegmentMixin + { + /** + * @param func Function like: bool process(ProviderSegmentT& providerSegment)> + */ + template <class FunctionT> + bool forEachProviderSegment(FunctionT&& func) + { + return static_cast<DerivedT*>(this)->forEachCoreSegment( + [&func](auto & coreSegment) -> bool + { + return coreSegment.forEachProviderSegment(func); + }); + } + + /** + * @param func Function like: bool process(const ProviderSegmentT& providerSegment) + */ + template <class FunctionT> + bool forEachProviderSegment(FunctionT&& func) const + { + return static_cast<DerivedT*>(this)->forEachCoreSegment( + [&func](const auto & coreSegment) -> bool + { + return coreSegment.forEachProviderSegment(func); + }); + } + }; + +} -- GitLab