From 531e5f31b24fc4e1ecf8d4d20b6353c0e6e0f6ab Mon Sep 17 00:00:00 2001 From: Peter Soetens Date: Mon, 12 Nov 2012 15:47:32 +0100 Subject: [PATCH 1/3] internal: make InputPortSource assignable This allows other code to have a reference to the internal data, in case this is needed for performance reasons. Signed-off-by: Peter Soetens --- rtt/internal/InputPortSource.hpp | 21 +++++++++++++++++---- 1 files changed, 17 insertions(+), 4 deletions(-) diff --git a/rtt/internal/InputPortSource.hpp b/rtt/internal/InputPortSource.hpp index bcd074c..cc9d76b 100644 --- a/rtt/internal/InputPortSource.hpp +++ b/rtt/internal/InputPortSource.hpp @@ -57,9 +57,14 @@ namespace RTT * call base::InputPortInterface::getDataSource() to get the corresponding data * source. This is your duty to destroy the port when it is not needed * anymore. + * + * @note Although this DataSource is assignable, writing to it is not causing + * any change in the port. You should not use the set() functions of this object. + * We provide this interface in order to allow other + * code to take a non-const reference to the read data. */ template - class InputPortSource : public DataSource + class InputPortSource : public AssignableDataSource { InputPort* port; mutable T mvalue; @@ -83,7 +88,7 @@ namespace RTT void reset() { port->clear(); } bool evaluate() const { - return port->read(mvalue) == NewData; + return port->read(mvalue, false) == NewData; } typename DataSource::result_t value() const @@ -97,9 +102,17 @@ namespace RTT else return T(); } - DataSource* clone() const + virtual void set( typename AssignableDataSource::param_t t ) { + mvalue = t; + } + + virtual typename AssignableDataSource::reference_t set() { + return mvalue; + } + + AssignableDataSource* clone() const { return new InputPortSource(*port); } - DataSource* copy( std::map& alreadyCloned ) const + AssignableDataSource* copy( std::map& alreadyCloned ) const { return const_cast*>(this); } }; }} -- 1.7.5.4