From 38a3665335487880d8530edc86c307a16d751c2e Mon Sep 17 00:00:00 2001 From: Raphael <ufdrv@student.kit.edu> Date: Wed, 24 May 2017 09:38:07 +0200 Subject: [PATCH] add a function to get all sensors of a robot with a given type --- VirtualRobot/Robot.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/VirtualRobot/Robot.h b/VirtualRobot/Robot.h index 08fc8a287..f1abba9c3 100644 --- a/VirtualRobot/Robot.h +++ b/VirtualRobot/Robot.h @@ -370,6 +370,21 @@ namespace VirtualRobot */ virtual std::vector<SensorPtr> getSensors(); + template<class SensorType> + std::vector<boost::shared_ptr<SensorType>> getSensors() + { + std::vector<boost::shared_ptr<SensorType>> result; + std::vector<SensorPtr> sensors = getSensors(); + result.reserve(sensors.size()); + for(SensorPtr& sensor:sensors) + { + if(dynamic_cast<SensorType*>(sensor.get())) + { + result.emplace_back(boost::static_pointer_cast<SensorType>(sensor)); + } + } + return result; + } /*! Creates an XML string that defines the complete robot. Filenames of all visualization models are set to modelPath/RobotNodeName_visu and/or modelPath/RobotNodeName_colmodel. @see RobotIO::saveXML. -- GitLab