RTI Connext C++ API  Version 5.1.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.
 
 SampleRef (T *data, Info *info)
 Creates an object with a reference to a data object.
 
 SampleRef (T &data, Info &info)
 Creates an object with a reference to a data object.
 
 SampleRef (Sample< T > &sample)
 Copies the references to data and info.
 
SampleRefoperator= (Sample< T > &sample)
 Copies the references to data and info.
 
T & data () const
 Gets the data this sample contains.
 
Infoinfo () const
 Gets the SampleInfo.
 
 operator T & () const
 Gets the data this sample contains.
 
void set_data (T &data)
 Sets a reference to a data object.
 
void set_info (DDS_SampleInfo &info)
 Sets the info object.
 
bool is_nil_data () const
 Indicates if this SampleRef contains a reference to data or not.
 
bool is_nil_info () const
 
SampleIdentity_t identity () const
 Gets the identity of this sample.
 
SampleIdentity_t related_identity () const
 Gets the identity of a sample that is related to this one.
 

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

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

Creates an object with no data.

See Also
set_data(T&)
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&)
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&)
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

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.

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
set_data
connext::WriteSample::data()
template<typename T >
Info& connext::SampleRef< T >::info ( ) const
inline

Gets the SampleInfo.

Precondition
The info object must have been set
See Also
set_info(DDS_SampleInfo&)
connext::SampleRef::identity()
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
set_data
connext::WriteSample::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
template<typename T >
void connext::SampleRef< T >::set_info ( DDS_SampleInfo info)
inline

Sets the info object.

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&)
template<typename T >
bool connext::SampleRef< T >::is_nil_info ( ) const
inline
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()
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()

RTI Connext C++ API Version 5.1.0 Copyright © Mon Feb 3 2014 Real-Time Innovations, Inc