From 7b01f6b6a282ffc035646e87827848a87ebac253 Mon Sep 17 00:00:00 2001 From: Raphael Grimm <raphael.grimm@kit.edu> Date: Tue, 29 May 2018 15:04:34 +0200 Subject: [PATCH] Add a templated version of SensorDevice::getSensorValue / JointController::getControlTarget casting the result to the given type --- .../components/units/RobotUnit/Devices/SensorDevice.h | 7 +++++++ .../units/RobotUnit/JointControllers/JointController.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/source/RobotAPI/components/units/RobotUnit/Devices/SensorDevice.h b/source/RobotAPI/components/units/RobotUnit/Devices/SensorDevice.h index 5b9cb4e87..5019b2003 100644 --- a/source/RobotAPI/components/units/RobotUnit/Devices/SensorDevice.h +++ b/source/RobotAPI/components/units/RobotUnit/Devices/SensorDevice.h @@ -65,6 +65,13 @@ namespace armarx /// @return The SensorDevice's sensor value virtual const SensorValueBase* getSensorValue() const = 0; + /// @return The SensorDevice's sensor value casted to the given type (may be nullptr) + template<class T> + const T* getSensorValue() const + { + return getSensorValue()->asA<const T*>(); + } + /** * @brief Returns the \ref SensorValueBase "SensorValue's" type as a string. * @param withoutNamespaceSpecifier Whether namespace specifiers should be removed from the name. diff --git a/source/RobotAPI/components/units/RobotUnit/JointControllers/JointController.h b/source/RobotAPI/components/units/RobotUnit/JointControllers/JointController.h index 1fdb7fe24..4d12be87a 100644 --- a/source/RobotAPI/components/units/RobotUnit/JointControllers/JointController.h +++ b/source/RobotAPI/components/units/RobotUnit/JointControllers/JointController.h @@ -46,6 +46,13 @@ namespace armarx virtual const ControlTargetBase* getControlTarget() const; + /// @return The \ref JointController's \ref ControlTargetBase "ControlTarget" casted to the given type (may be nullptr) + template<class T> + const T* getControlTarget() const + { + return getControlTarget()->asA<const T*>(); + } + virtual void rtResetTarget(); virtual bool rtIsTargetVaild() const; -- GitLab