RTI Connext Traditional C++ API Version 7.2.0
connext::SampleRef< T > Class Template Reference

A data sample and related information received from the middleware. More...

Public Member Functions

 SampleRef ()
 Creates an object with no data. More...
 
 SampleRef (T *data, Info *info)
 Creates an object with a reference to a data object. More...
 
 SampleRef (T &data, Info &info)
 Creates an object with a reference to a data object. More...
 
 SampleRef (Sample< T > &sample)
 Copies the references to data and info. More...
 
SampleRefoperator= (Sample< T > &sample)
 Copies the references to data and info. More...
 
T & data () const
 Gets the data this sample contains. More...
 
Info & info () const
 Gets the SampleInfo. More...
 
 operator T& () const
 Gets the data this sample contains. More...
 
void set_data (T &data)
 Sets a reference to a data object. More...
 
void set_info (DDS_SampleInfo &info)
 Sets the info object. More...
 
bool is_nil_data () const
 Indicates if this SampleRef contains a reference to data or not. More...
 
bool is_nil_info () const
 Indicates if this SampleRef contains a reference to data or not. More...
 
SampleIdentity_t identity () const
 Gets the identity of this sample. More...
 
SampleIdentity_t related_identity () const
 Gets the identity of a sample that is related to this one. More...
 

Detailed Description

template<typename T>
class connext::SampleRef< T >

A data sample and related information received from the middleware.

A SampleRef can be used much like a connext::Sample, but it's different in that it holds references to data and DDS_SampleInfo, whereas a Sample is a value type and owns its data and info.

When calling an operation that copies data from the middleware into a Sample (e.g. connext::Requester::take_reply(Sample<TRep>&)), the references to its data and information must have been set explicitly (see connext::SampleRef::set_data(T&) and connext::SampleRef::set_info(DDS_SampleInfo&))

When a SampleRef is copied, the destination SampleRef references the same data and info objects as the source. Copying and passing by value are inexpensive operations.

SampleRef is also the type of the elements in a connext::LoanedSamples container and they hold references to data from the middleware.

Template Parameters
TThe data type that this sample contains
See also
connext::Requester::receive_reply(Sample<TRep>&, const Duration_t&)
connext::Requester::take_reply(Sample<TRep>&)
connext::Replier::receive_request(Sample<TReq>&, const Duration_t&)
Basic Requester example using SampleRef
Template Parameters
TThe data type that this sample can contain

Constructor & Destructor Documentation

◆ SampleRef() [1/4]

template<typename T >
connext::SampleRef< T >::SampleRef ( )
inline

Creates an object with no data.

See also
set_data(T&)

Referenced by connext::SampleRef< T >::operator=().

◆ SampleRef() [2/4]

template<typename T >
connext::SampleRef< T >::SampleRef ( T *  data,
Info *  info 
)
inline

Creates an object with a reference to a data object.

See also
set_data(T&)

◆ SampleRef() [3/4]

template<typename T >
connext::SampleRef< T >::SampleRef ( T &  data,
Info &  info 
)
inline

Creates an object with a reference to a data object.

See also
set_data(T&)

◆ SampleRef() [4/4]

template<typename T >
connext::SampleRef< T >::SampleRef ( Sample< T > &  sample)
inline

Copies the references to data and info.

After this operation, this object contains a reference to the same data and info instances as the source.

Member Function Documentation

◆ operator=()

template<typename T >
SampleRef & connext::SampleRef< T >::operator= ( Sample< T > &  sample)
inline

Copies the references to data and info.

After this operation, this object contains a reference to the same data and info instances as the source.

References connext::SampleRef< T >::SampleRef().

◆ data()

template<typename T >
T & connext::SampleRef< T >::data ( ) const
inline

Gets the data this sample contains.

Precondition
Data must have been set before
See also
connext::WriteSampleRef::set_data
connext::WriteSample::data()

Referenced by connext::SampleRef< T >::set_data().

◆ info()

template<typename T >
Info & connext::SampleRef< T >::info ( ) const
inline

◆ operator T&()

template<typename T >
connext::SampleRef< T >::operator T& ( ) const
inline

Gets the data this sample contains.

Precondition
Data must have been set before
See also
connext::WriteSampleRef::set_data
connext::WriteSample::data()

◆ set_data()

template<typename T >
void connext::SampleRef< T >::set_data ( T &  data)
inline

Sets a reference to a data object.

Parameters
dataThe data object this sample will reference

References connext::SampleRef< T >::data().

◆ set_info()

template<typename T >
void connext::SampleRef< T >::set_info ( DDS_SampleInfo info)
inline

Sets the info object.

References connext::SampleRef< T >::info().

◆ is_nil_data()

template<typename T >
bool connext::SampleRef< T >::is_nil_data ( ) const
inline

Indicates if this SampleRef contains a reference to data or not.

Returns
True if this sample does not contain a reference to data.
See also
connext::SampleRef::data
connext::SampleRef::set_data(T&)

◆ is_nil_info()

template<typename T >
bool connext::SampleRef< T >::is_nil_info ( ) const
inline

Indicates if this SampleRef contains a reference to data or not.

Returns
True if this sample does not contain a reference to info.
See also
connext::SampleRef::info()
connext::SampleRef::set_info(DDS_SampleInfo&)

◆ identity()

template<typename T >
SampleIdentity_t connext::SampleRef< T >::identity ( ) const
inline

Gets the identity of this sample.

Precondition
The info object must have been set
See also
set_info(DDS_SampleInfo&)
connext::Sample::identity()

References connext::SampleRef< T >::info().

◆ related_identity()

template<typename T >
SampleIdentity_t connext::SampleRef< T >::related_identity ( ) const
inline

Gets the identity of a sample that is related to this one.

Precondition
The info object must have been set
See also
connext::Sample::related_identity()

References connext::SampleRef< T >::info().