From 8f05890c6605eb7752034f71ffbdbe7aeb0417f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Vallv=C3=A9=20Navarro?= <jvallve@iri.upc.edu> Date: Wed, 3 Nov 2021 16:09:50 +0100 Subject: [PATCH] new methods getCapture(s)OfType --- include/core/frame/frame_base.h | 25 +++++++++++++++++++++++++ src/frame/frame_base.cpp | 17 +++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/core/frame/frame_base.h b/include/core/frame/frame_base.h index 848fa3f12..7234284a5 100644 --- a/include/core/frame/frame_base.h +++ b/include/core/frame/frame_base.h @@ -102,6 +102,12 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha FrameBasePtr getNextFrame() const; const CaptureBasePtrList& getCaptureList() const; + template <class C> + CaptureBasePtr getCaptureOfType() const; + CaptureBasePtr getCaptureOfType(const std::string& type) const; + template <class C> + CaptureBasePtrList getCapturesOfType() const; + CaptureBasePtrList getCapturesOfType(const std::string& type) const; CaptureBasePtr getCaptureOf(const SensorBaseConstPtr _sensor_ptr) const; CaptureBasePtr getCaptureOf(const SensorBasePtr _sensor_ptr, const std::string& type) const; CaptureBasePtrList getCapturesOf(const SensorBasePtr _sensor_ptr) const; @@ -208,6 +214,25 @@ inline void FrameBase::setTrajectory(TrajectoryBasePtr _trj_ptr) trajectory_ptr_ = _trj_ptr; } +template <class C> +inline CaptureBasePtr FrameBase::getCaptureOfType() const +{ + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + return capture_ptr; + return nullptr; +} + +template <class C> +inline CaptureBasePtrList FrameBase::getCapturesOfType() const +{ + CaptureBasePtrList captures; + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (std::dynamic_pointer_cast<C>(capture_ptr) != nullptr) + captures.push_back(capture_ptr); + return captures; +} + } // namespace wolf #endif diff --git a/src/frame/frame_base.cpp b/src/frame/frame_base.cpp index 95233cf96..71e344552 100644 --- a/src/frame/frame_base.cpp +++ b/src/frame/frame_base.cpp @@ -175,6 +175,23 @@ void FrameBase::removeCapture(CaptureBasePtr _capt_ptr) capture_list_.remove(_capt_ptr); } +CaptureBasePtr FrameBase::getCaptureOfType(const std::string& type) const +{ + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (capture_ptr->getType() == type) + return capture_ptr; + return nullptr; +} + +CaptureBasePtrList FrameBase::getCapturesOfType(const std::string& type) const +{ + CaptureBasePtrList captures; + for (CaptureBasePtr capture_ptr : getCaptureList()) + if (capture_ptr->getType() == type) + captures.push_back(capture_ptr); + return captures; +} + CaptureBasePtr FrameBase::getCaptureOf(const SensorBasePtr _sensor_ptr, const std::string& type) const { for (CaptureBasePtr capture_ptr : getCaptureList()) -- GitLab