OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
dds::sub::LoanedSamples< T > Class Template Reference

This class encapsulates and automates the management of loaned samples. More...

#include "LoanedSamples.hpp"

Public Types

typedef DELEGATE< T >::const_iterator const_iterator
 
typedef T DataType
 

Public Member Functions

 LoanedSamples ()
 
 LoanedSamples (const LoanedSamples &other)
 
 ~LoanedSamples ()
 
const_iterator begin () const
 
const_iterator end () const
 
uint32_t length () const
 

Detailed Description

template<typename T>
class dds::sub::LoanedSamples< T >

This class encapsulates and automates the management of loaned samples.

It is a container which is used to hold samples which have been read or taken by the DataReader. Samples are effectively "loaned" from the DataReader to avoid the need to copy the data. When the LoanedSamples container goes out of scope the loan is automatically returned.

LoanedSamples maintains a ref count so that the loan will only be returned once all copies of the same LoanedSamples have been destroyed.

dds::topic::Topic<Foo::Bar> topic(participant, "TopicName");
dds::sub::Subscriber subscriber(participant);
dds::sub::DataReader<Foo::Bar> reader(subscriber, topic);
// Assume there is data to read
{
dds::sub::LoanedSamples<Foo::Bar> samples = reader.read();
for (it = samples.begin(); it != samples.end(); ++it) {
const dds::sub::Sample<Foo::Bar>& sample = *it;
const Foo::Bar& data = sample.data();
const dds::sub::SampleInfo& info = sample.info();
// Use sample data and meta information.
}
function(samples);
}
// LoanedSamples out of scope. Whether the loan is returned, depends what the reference
// count of the LoanedSamples is. That again, depends on what the function() did with it.
// Maybe function() stored the LoanedSamples, maybe not. Whatever the case, LoanedSamples
// takes care of the loan and resource handling.
See also
DataSample for more information
SampleInfo for more information
Subscription for more information

Definition at line 87 of file LoanedSamples.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T>
typedef DELEGATE<T>::const_iterator dds::sub::LoanedSamples< T >::const_iterator

Convenience typedef for the iterator over the loaned samples.

Definition at line 98 of file LoanedSamples.hpp.

◆ DataType

template<typename T>
typedef T dds::sub::LoanedSamples< T >::DataType

Convenience typedef for the type of the data sample.

Definition at line 93 of file LoanedSamples.hpp.

Constructor & Destructor Documentation

◆ LoanedSamples() [1/2]

template<typename T >
dds::sub::LoanedSamples< T >::LoanedSamples ( )

Constructs a LoanedSamples instance.

Definition at line 40 of file LoanedSamplesImpl.hpp.

◆ ~LoanedSamples()

template<typename T >
dds::sub::LoanedSamples< T >::~LoanedSamples ( )

Implicitly return the loan if this is the last object with a reference to the contained loan.

Definition at line 43 of file LoanedSamplesImpl.hpp.

◆ LoanedSamples() [2/2]

template<typename T >
dds::sub::LoanedSamples< T >::LoanedSamples ( const LoanedSamples< T > &  other)

Copies a LoanedSamples instance.

No actual data samples are copied.
Just references and reference counts are updated.

Definition at line 46 of file LoanedSamplesImpl.hpp.

Member Function Documentation

◆ begin()

template<typename T >
LoanedSamples< T >::const_iterator dds::sub::LoanedSamples< T >::begin ( ) const

Gets an iterator pointing to the first sample in the LoanedSamples container.

See example.

Returns
an iterator pointing to the first sample

Definition at line 52 of file LoanedSamplesImpl.hpp.

◆ end()

template<typename T >
LoanedSamples< T >::const_iterator dds::sub::LoanedSamples< T >::end ( ) const

Gets an iterator pointing to the end of the LoanedSamples container.

See example.

Returns
an iterator pointing to the end of the container

Definition at line 58 of file LoanedSamplesImpl.hpp.

◆ length()

template<typename T >
uint32_t dds::sub::LoanedSamples< T >::length ( ) const

Gets the number of samples within the LoanedSamples container.

Returns
the number of samples

Definition at line 76 of file LoanedSamplesImpl.hpp.


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