Orocos Real-Time Toolkit  2.8.3
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
RTT::internal::InputPortSource< T > Class Template Referenceabstract

This class represents a read port using the data source interface. More...

#include <rtt/internal/InputPortSource.hpp>

Inheritance diagram for RTT::internal::InputPortSource< T >:
RTT::internal::AssignableDataSource< T > RTT::internal::DataSource< T > RTT::base::DataSourceBase

Public Types

typedef boost::intrusive_ptr< InputPortSource< T > > shared_ptr
 
typedef DataSource< T >::value_t value_t
 
typedef DataSource< T >::const_reference_t const_reference_t
 
typedef boost::call_traits< value_t >::param_type param_t
 
typedef boost::call_traits< value_t >::reference reference_t
 
typedef boost::intrusive_ptr< const AssignableDataSource< T > > const_ptr
 
typedef T result_t
 

Public Member Functions

 InputPortSource (InputPort< T > &port)
 
void reset ()
 Reset the data to initial values. More...
 
bool evaluate () const
 Force an evaluation of the DataSourceBase. More...
 
DataSource< T >::result_t value () const
 Return the result of the last evaluate() function. More...
 
DataSource< T >::const_reference_t rvalue () const
 Get a const reference to the value of this DataSource. More...
 
DataSource< T >::result_t get () const
 Return the data as type T. More...
 
virtual void set (typename AssignableDataSource< T >::param_t t)
 
virtual AssignableDataSource< T >::reference_t set ()
 Get a reference to the value of this DataSource. More...
 
AssignableDataSource< T > * clone () const
 Return a shallow clone of this DataSource. More...
 
AssignableDataSource< T > * copy (std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
 Create a deep copy of this internal::DataSource, unless it is already cloned. More...
 
virtual void set (param_t t)=0
 Set this DataSource with a value. More...
 
void * getRawPointer ()
 Generic implementation of getRawPointer() based on set() More...
 
virtual bool isAssignable () const
 Returns true if this object can be cast to an AssignableDataSource. More...
 
virtual bool update (base::DataSourceBase *other)
 Update the value of this internal::DataSource with the value of an other DataSource. More...
 
virtual base::ActionInterfaceupdateAction (base::DataSourceBase *other)
 Generate a ActionInterface object which will update this internal::DataSource with the value of another internal::DataSource when execute()'ed. More...
 
 BOOST_STATIC_ASSERT (!details::HasConst< T >::value)
 If you get a compile error here, it means T has const or reference qualifiers, which is not allowed for DataSource<T> More...
 
void const * getRawConstPointer ()
 Generic implementation of getRawConstPointer() based on rvalue() More...
 
template<>
void const * getRawConstPointer ()
 Returns a const pointer to the sample contained in this data source, if there is any. More...
 
virtual std::string getType () const
 Return useful type info in a human readable format. More...
 
virtual const types::TypeInfogetTypeInfo () const
 Return the Orocos type info object. More...
 
virtual std::string getTypeName () const
 Return the Orocos type name, without const, pointer or reference qualifiers. More...
 
void ref () const
 Increase the reference count by one. More...
 
void deref () const
 Decrease the reference count by one and delete this on zero. More...
 
virtual void updated ()
 In case the internal::DataSource returns a 'reference' type, call this method to notify it that the data was updated in the course of an invocation of get(). More...
 
virtual shared_ptr getMember (const std::string &member_name)
 Get a (const) reference data source to a member of the structure of this data source. More...
 
virtual shared_ptr getMember (DataSourceBase::shared_ptr member_id, DataSourceBase::shared_ptr offset)
 Same as above, but with run-time lookup of the member to use. More...
 
virtual std::vector< std::string > getMemberNames () const
 Returns the names of all members of the structure contained in this data source, or an empty list if none. More...
 
virtual shared_ptr getParent ()
 Returns the top level data source that contains the full data structure this data source refers to. More...
 
std::ostream & write (std::ostream &os)
 Stream the contents of this object. More...
 
std::string toString ()
 Get the contents of this object as a string. More...
 

Static Public Member Functions

static AssignableDataSource< T > * narrow (base::DataSourceBase *db)
 This method narrows a base::DataSourceBase to a typeded AssignableDataSource, possibly returning a new object. More...
 
static std::string GetType ()
 Return usefull type info in a human readable format. More...
 
static const types::TypeInfoGetTypeInfo ()
 Return the Orocos type info. More...
 
static std::string GetTypeName ()
 Return the Orocos type name, without const, pointer or reference qualifiers. More...
 
static shared_ptr stack_shared_ptr (DataSourceBase *dsb)
 Returns a shared ptr to a DataSourceBase living on the stack. More...
 
static const_ptr stack_const_ptr (const DataSourceBase *dsb)
 Returns a const shared_ptr to a DataSourceBase living on the stack. More...
 

Protected Attributes

os::AtomicInt refcount
 We keep the refcount ourselves. More...
 

Detailed Description

template<typename T>
class RTT::internal::InputPortSource< T >

This class represents a read port using the data source interface.

Beware that, depending on the connection used, ports actually change their state when read. For instance, a buffer connection will lose one element when get() or evaluate() are called. For that reason, it is considered bad practice to use a data source on a read port that is bound to a buffer connection.

This class should not be used directly in normal code. What you would usually do is create a new read port using OutputPort::antiClone() and 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.

Definition at line 67 of file InputPortSource.hpp.

Member Typedef Documentation

template<typename T>
typedef boost::intrusive_ptr<const AssignableDataSource<T> > RTT::internal::AssignableDataSource< T >::const_ptr
inherited

Definition at line 199 of file DataSource.hpp.

template<typename T>
typedef DataSource<T>::const_reference_t RTT::internal::AssignableDataSource< T >::const_reference_t
inherited

Definition at line 191 of file DataSource.hpp.

template<typename T>
typedef boost::call_traits<value_t>::param_type RTT::internal::AssignableDataSource< T >::param_t
inherited

Definition at line 192 of file DataSource.hpp.

template<typename T>
typedef boost::call_traits<value_t>::reference RTT::internal::AssignableDataSource< T >::reference_t
inherited

Definition at line 193 of file DataSource.hpp.

template<typename T>
typedef T RTT::internal::DataSource< T >::result_t
inherited

Definition at line 106 of file DataSource.hpp.

template<typename T>
typedef boost::intrusive_ptr<InputPortSource<T> > RTT::internal::InputPortSource< T >::shared_ptr

Definition at line 73 of file InputPortSource.hpp.

template<typename T>
typedef DataSource<T>::value_t RTT::internal::AssignableDataSource< T >::value_t
inherited

Definition at line 190 of file DataSource.hpp.

Constructor & Destructor Documentation

template<typename T>
RTT::internal::InputPortSource< T >::InputPortSource ( InputPort< T > &  port)
inline

Definition at line 75 of file InputPortSource.hpp.

References RTT::InputPort< T >::getDataSample().

Member Function Documentation

template<typename T>
RTT::internal::DataSource< T >::BOOST_STATIC_ASSERT ( !details::HasConst< T >::value  )
inherited

If you get a compile error here, it means T has const or reference qualifiers, which is not allowed for DataSource<T>

template<typename T>
AssignableDataSource<T>* RTT::internal::InputPortSource< T >::clone ( ) const
inlinevirtual

Return a shallow clone of this DataSource.

This method returns a duplicate of this instance which re-uses the DataSources this internal::DataSource holds reference to. The clone() function is thus a non-deep copy.

Implements RTT::internal::AssignableDataSource< T >.

Definition at line 105 of file InputPortSource.hpp.

template<typename T>
AssignableDataSource<T>* RTT::internal::InputPortSource< T >::copy ( std::map< const base::DataSourceBase *, base::DataSourceBase * > &  alreadyCloned) const
inlinevirtual

Create a deep copy of this internal::DataSource, unless it is already cloned.

Places the association (parent, clone) in alreadyCloned. If the internal::DataSource is non-copyable (for example it represents the Property of a Task ), this may be returned.

Implements RTT::internal::AssignableDataSource< T >.

Definition at line 107 of file InputPortSource.hpp.

void RTT::DataSourceBase::deref ( ) const
inherited

Decrease the reference count by one and delete this on zero.

Definition at line 81 of file DataSource.cpp.

References RTT::os::AtomicInt::dec_and_test(), and RTT::base::DataSourceBase::refcount.

Referenced by RTT::base::intrusive_ptr_release().

template<typename T>
bool RTT::internal::InputPortSource< T >::evaluate ( ) const
inlinevirtual

Force an evaluation of the DataSourceBase.

Returns
true on successful evaluation.

Reimplemented from RTT::internal::DataSource< T >.

Definition at line 81 of file InputPortSource.hpp.

References RTT::NewData, and RTT::InputPort< T >::read().

Referenced by RTT::internal::InputPortSource< T >::get().

template<typename T>
DataSource<T>::result_t RTT::internal::InputPortSource< T >::get ( ) const
inlinevirtual
DataSourceBase::shared_ptr RTT::DataSourceBase::getMember ( const std::string &  member_name)
virtualinherited

Get a (const) reference data source to a member of the structure of this data source.

You must call getMember() in turn on the returned member to access sub-members.

Parameters
member_nameThe name of the member to get access to.
Returns
null if the member does not exist, this if member_name.empty(), and a reference data source to the member otherwise.

Definition at line 124 of file DataSource.cpp.

References RTT::types::TypeInfo::getMember(), and RTT::base::DataSourceBase::getTypeInfo().

DataSourceBase::shared_ptr RTT::DataSourceBase::getMember ( DataSourceBase::shared_ptr  member_id,
DataSourceBase::shared_ptr  offset 
)
virtualinherited

Same as above, but with run-time lookup of the member to use.

Also takes an optional offset argument which can be used to offset the member in memory. This is necessary when using sequences of sequences. DataSources which are a sequence/offset member themselves must override this function to let the returned member take the offset into account.

Definition at line 130 of file DataSource.cpp.

References RTT::types::TypeInfo::getMember(), and RTT::base::DataSourceBase::getTypeInfo().

vector< string > RTT::DataSourceBase::getMemberNames ( ) const
virtualinherited

Returns the names of all members of the structure contained in this data source, or an empty list if none.

If this data source is a sequence, it will not return the allowed index numbers.

Definition at line 134 of file DataSource.cpp.

References RTT::types::TypeInfo::getMemberNames(), and RTT::base::DataSourceBase::getTypeInfo().

DataSourceBase::shared_ptr RTT::DataSourceBase::getParent ( )
virtualinherited

Returns the top level data source that contains the full data structure this data source refers to.

Defaults to returning this.

Definition at line 138 of file DataSource.cpp.

template<>
void const * RTT::internal::DataSource< void >::getRawConstPointer ( )
inlinevirtualinherited

Returns a const pointer to the sample contained in this data source, if there is any.

Returns 0 otherwise

Reimplemented from RTT::base::DataSourceBase.

Definition at line 59 of file DataSource.inl.

template<typename T>
void const* RTT::internal::DataSource< T >::getRawConstPointer ( )
inlinevirtualinherited

Generic implementation of getRawConstPointer() based on rvalue()

Reimplemented from RTT::base::DataSourceBase.

Definition at line 141 of file DataSource.hpp.

template<typename T>
void* RTT::internal::AssignableDataSource< T >::getRawPointer ( )
inlinevirtualinherited

Generic implementation of getRawPointer() based on set()

Reimplemented from RTT::base::DataSourceBase.

Definition at line 214 of file DataSource.hpp.

template<typename T >
std::string RTT::internal::DataSource< T >::getType ( ) const
virtualinherited

Return useful type info in a human readable format.

Implements RTT::base::DataSourceBase.

Reimplemented in RTT::corba::DataSourceProxy< T >.

Definition at line 20 of file DataSource.inl.

References RTT::internal::DataSource< T >::GetType().

template<typename T >
std::string RTT::internal::DataSource< T >::GetType ( )
staticinherited
template<typename T >
const types::TypeInfo * RTT::internal::DataSource< T >::getTypeInfo ( ) const
virtualinherited

Return the Orocos type info object.

Implements RTT::base::DataSourceBase.

Definition at line 46 of file DataSource.inl.

template<typename T >
const types::TypeInfo * RTT::internal::DataSource< T >::GetTypeInfo ( )
staticinherited
template<typename T >
std::string RTT::internal::DataSource< T >::GetTypeName ( )
staticinherited

Return the Orocos type name, without const, pointer or reference qualifiers.

Definition at line 39 of file DataSource.inl.

References RTT::internal::DataSourceTypeInfo< T >::getTypeName().

Referenced by RTT::internal::DataSource< T >::getTypeName().

template<typename T >
std::string RTT::internal::DataSource< T >::getTypeName ( ) const
virtualinherited

Return the Orocos type name, without const, pointer or reference qualifiers.

Implements RTT::base::DataSourceBase.

Definition at line 26 of file DataSource.inl.

References RTT::internal::DataSource< T >::GetTypeName().

Referenced by RTT::types::SequenceTypeInfoBase< std::vector< double > >::getMember(), and RTT::corba::RemoteChannelElement< T >::read().

template<typename T>
virtual bool RTT::internal::AssignableDataSource< T >::isAssignable ( ) const
inlinevirtualinherited

Returns true if this object can be cast to an AssignableDataSource.

When this method returns true, all update functions below will return as well when valid input is given.

Reimplemented from RTT::base::DataSourceBase.

Definition at line 216 of file DataSource.hpp.

template<class T >
AssignableDataSource< T > * RTT::internal::AssignableDataSource< T >::narrow ( base::DataSourceBase db)
staticinherited
void RTT::DataSourceBase::ref ( ) const
inherited
template<typename T>
void RTT::internal::InputPortSource< T >::reset ( )
inlinevirtual

Reset the data to initial values.

Reimplemented from RTT::base::DataSourceBase.

Definition at line 80 of file InputPortSource.hpp.

References RTT::base::InputPortInterface::clear().

template<typename T>
DataSource<T>::const_reference_t RTT::internal::InputPortSource< T >::rvalue ( ) const
inlinevirtual

Get a const reference to the value of this DataSource.

You must call evaluate() prior to calling this function in order to get the most recent value of this attribute.

Note
Getting a reference to an internal data structure is not thread-safe.

Implements RTT::internal::DataSource< T >.

Definition at line 88 of file InputPortSource.hpp.

template<typename T>
virtual void RTT::internal::InputPortSource< T >::set ( typename AssignableDataSource< T >::param_t  t)
inlinevirtual

Definition at line 97 of file InputPortSource.hpp.

template<typename T>
virtual AssignableDataSource<T>::reference_t RTT::internal::InputPortSource< T >::set ( )
inlinevirtual

Get a reference to the value of this DataSource.

Getting a reference to an internal data structure is not thread-safe.

Implements RTT::internal::AssignableDataSource< T >.

Definition at line 101 of file InputPortSource.hpp.

template<typename T>
virtual void RTT::internal::AssignableDataSource< T >::set ( param_t  t)
pure virtualinherited

Set this DataSource with a value.

Referenced by RTT::internal::SendHandleC::collect(), RTT::internal::SendHandleC::collectIfDone(), RTT::types::TemplateCompositionFactory< bool >::composeType(), RTT::types::StdVectorTypeInfo::composeType(), RTT::types::StdVectorTemplateTypeInfo< T, has_ostream >::composeType(), RTT::types::EnumTypeInfo< T >::composeType(), RTT::types::BoostArrayTypeInfo< T, has_ostream >::composeType(), RTT::types::SequenceTypeInfoBase< std::vector< double > >::composeType(), RTT::types::CArrayTypeInfo< T, has_ostream >::composeType(), RTT::Property< bool >::copy(), RTT::scripting::ConditionCache::evaluate(), RTT::scripting::TryCommand::execute(), RTT::scripting::EvalCommand::execute(), CorbaOperationCallerCall::execute(), RTT::corba::ValueDataSourceProxy< T >::get(), RTT::types::BoostArrayTypeInfo< T, has_ostream >::getMember(), RTT::types::StructTypeInfo< T, has_ostream >::getMember(), RTT::types::CArrayTypeInfo< T, has_ostream >::getMember(), RTT::Property< bool >::operator=(), RTT::types::BoolTypeInfo::read(), RTT::types::PrimitiveTypeInfo< std::vector< T >, use_ostream >::read(), RTT::InputPort< T >::read(), RTT::scripting::TryCommand::readArguments(), RTT::InputPort< T >::readNewest(), RTT::Property< bool >::refresh(), RTT::scripting::ConditionCache::reset(), RTT::scripting::TryCommand::reset(), RTT::scripting::EvalCommand::reset(), RTT::types::SequenceTypeInfoBase< std::vector< double > >::resize(), RTT::corba::ValueDataSourceProxy< T >::set(), RTT::Attribute< T >::set(), RTT::Property< bool >::set(), RTT::internal::ActionAliasAssignableDataSource< T >::set(), RTT::internal::ReferenceDataSource< ds_type >::setReference(), RTT::Property< bool >::update(), RTT::corba::CorbaTemplateProtocol< T >::updateFromAny(), RTT::mqueue::MQTemplateProtocol< T >::updateFromBlob(), RTT::mqueue::MQSerializationProtocol< T >::updateFromBlob(), and RTT::internal::SendHandleC::E::OperationKeeper::~OperationKeeper().

DataSourceBase::const_ptr RTT::DataSourceBase::stack_const_ptr ( const DataSourceBase dsb)
staticinherited

Returns a const shared_ptr to a DataSourceBase living on the stack.

Make sure that the const_ptr does not outlive the stacked element.

Definition at line 74 of file DataSource.cpp.

References RTT::base::DataSourceBase::ref().

DataSourceBase::shared_ptr RTT::DataSourceBase::stack_shared_ptr ( DataSourceBase dsb)
staticinherited

Returns a shared ptr to a DataSourceBase living on the stack.

Make sure that the shared_ptr does not outlive the stacked element.

Definition at line 69 of file DataSource.cpp.

References RTT::base::DataSourceBase::ref().

std::string RTT::DataSourceBase::toString ( )
inherited

Get the contents of this object as a string.

See also
types::TypeInfo

Definition at line 98 of file DataSource.cpp.

template<class T >
bool RTT::internal::AssignableDataSource< T >::update ( base::DataSourceBase other)
virtualinherited

Update the value of this internal::DataSource with the value of an other DataSource.

Update does a full update of the value, adding extra information if necessary.

Precondition
this->isAssignable() == true
Returns
false if the DataSources are of different type OR if the contents of this internal::DataSource can not be updated.

Reimplemented from RTT::base::DataSourceBase.

Definition at line 78 of file DataSource.inl.

References RTT::types::TypeInfo::convert(), RTT::internal::DataSource< T >::evaluate(), RTT::internal::DataSourceTypeInfo< T >::getTypeInfo(), and RTT::internal::DataSource< T >::value().

template<class T >
base::ActionInterface * RTT::internal::AssignableDataSource< T >::updateAction ( base::DataSourceBase other)
virtualinherited

Generate a ActionInterface object which will update this internal::DataSource with the value of another internal::DataSource when execute()'ed.

Precondition
this->isAssignable() == true
Returns
zero if the internal::DataSource types do not match OR if the contents of this internal::DataSource can not be updated.

Reimplemented from RTT::base::DataSourceBase.

Definition at line 94 of file DataSource.inl.

References RTT::types::TypeInfo::convert(), and RTT::internal::DataSourceTypeInfo< T >::getTypeInfo().

void RTT::DataSourceBase::updated ( )
virtualinherited
template<typename T>
DataSource<T>::result_t RTT::internal::InputPortSource< T >::value ( ) const
inlinevirtual

Return the result of the last evaluate() function.

You must call evaluate() prior to calling this function in order to get the most recent value of this attribute.

Implements RTT::internal::DataSource< T >.

Definition at line 86 of file InputPortSource.hpp.

Referenced by RTT::internal::InputPortSource< T >::get().

std::ostream & RTT::DataSourceBase::write ( std::ostream &  os)
inherited

Stream the contents of this object.

See also
types::TypeInfo

Definition at line 91 of file DataSource.cpp.

Member Data Documentation

os::AtomicInt RTT::base::DataSourceBase::refcount
mutableprotectedinherited

We keep the refcount ourselves.

We aren't using boost::shared_ptr, because boost::intrusive_ptr is better, exactly because it can be used with refcounts that are stored in the class itself. Advantages are that the shared_ptr's for derived classes use the same refcount, which is of course very much desired, and that refcounting happens in an efficient way, which is also nice :)

Definition at line 88 of file DataSourceBase.hpp.

Referenced by RTT::base::DataSourceBase::deref(), and RTT::base::DataSourceBase::ref().


The documentation for this class was generated from the following file: