From 48fb8128a054d67e0b2054713de0c6d10c5adedb Mon Sep 17 00:00:00 2001 From: jvallve <jvallve@iri.upc.edu> Date: Fri, 5 Aug 2022 10:53:59 +0200 Subject: [PATCH] frameBase::getCapturesOfType of specific type --- include/core/frame/frame_base.h | 40 +++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/include/core/frame/frame_base.h b/include/core/frame/frame_base.h index 8d6466358..fe2b7164d 100644 --- a/include/core/frame/frame_base.h +++ b/include/core/frame/frame_base.h @@ -139,17 +139,17 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha bool isConstrainedBy(const FactorBaseConstPtr& _factor) const; template <class C> - CaptureBaseConstPtr getCaptureOfType() const; + std::shared_ptr<const C> getCaptureOfType() const; template <class C> - CaptureBasePtr getCaptureOfType(); + std::shared_ptr<C> getCaptureOfType(); CaptureBaseConstPtr getCaptureOfType(const std::string& type) const; CaptureBasePtr getCaptureOfType(const std::string& type); template <class C> - CaptureBaseConstPtrList getCapturesOfType() const; + std::list<std::shared_ptr<const C>> getCapturesOfType() const; template <class C> - CaptureBasePtrList getCapturesOfType(); + std::list<std::shared_ptr<C>> getCapturesOfType(); CaptureBaseConstPtrList getCapturesOfType(const std::string& type) const; CaptureBasePtrList getCapturesOfType(const std::string& type); @@ -290,40 +290,52 @@ inline void FrameBase::setTrajectory(TrajectoryBasePtr _trj_ptr) } template <class C> -inline CaptureBaseConstPtr FrameBase::getCaptureOfType() const +inline std::shared_ptr<const C> FrameBase::getCaptureOfType() const { for (auto capture_ptr : getCaptureList()) - if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + { + auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr); + if (cap_derived) return capture_ptr; + } return nullptr; } template <class C> -inline CaptureBasePtr FrameBase::getCaptureOfType() +inline std::shared_ptr<C> FrameBase::getCaptureOfType() { for (auto capture_ptr : getCaptureList()) - if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + { + auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr); + if (cap_derived) return capture_ptr; + } return nullptr; } template <class C> -inline CaptureBaseConstPtrList FrameBase::getCapturesOfType() const +inline std::list<std::shared_ptr<const C>> FrameBase::getCapturesOfType() const { - CaptureBaseConstPtrList captures; + std::list<std::shared_ptr<const C>> captures; for (auto capture_ptr : getCaptureList()) - if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + { + auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr); + if (cap_derived) captures.push_back(capture_ptr); + } return captures; } template <class C> -inline CaptureBasePtrList FrameBase::getCapturesOfType() +inline std::list<std::shared_ptr<C>> FrameBase::getCapturesOfType() { - CaptureBasePtrList captures; + std::list<std::shared_ptr<C>> captures; for (auto capture_ptr : getCaptureList()) - if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + { + auto cap_derived = std::dynamic_pointer_cast<C>(capture_ptr); + if (cap_derived) captures.push_back(capture_ptr); + } return captures; } -- GitLab