RTI Routing Service  Version 6.0.1
 All Data Structures Files Functions Typedefs Enumerations Enumerator Groups Pages
rti::routing::processor::LoanedSamples< T, U > Class Template Reference

Provides temporary access to a collection of samples (data and info) from a TypedInput. More...

#include <LoanedSamples.hpp>

Public Types

typedef SampleIterator< T, U > iterator
 The iterator type.
 

Public Member Functions

 LoanedSamples ()
 Creates an empty LoanedSamples object.
 
 ~LoanedSamples () throw ()
 Automatically returns the loan to the TypedInput used to obtained these samples.
 
LoanedSample< T, U > operator[] (size_t index)
 Provides access to the underlying LoanedSample object in array-like syntax.
 
int32_t length () const
 Gets the number of samples in this collection.
 
void return_loan ()
 Returns the samples to the TypedInput used to get these samples.
 
iterator begin ()
 Gets an iterator to the first sample.
 
iterator end ()
 Gets an iterator to one past the last sample.
 
const_iterator begin () const
 Gets an iterator to the first sample.
 
const_iterator end () const
 Gets an iterator to one past the last sample.
 
void swap (LoanedSamples &other) throw ()
 Swaps two LoanedSamples containers.
 

Detailed Description

template<typename T, typename U = dds::sub::SampleInfo>
class rti::routing::processor::LoanedSamples< T, U >

Provides temporary access to a collection of samples (data and info) from a TypedInput.

Template Parameters
TThe sample data type representation. It has to match the type of the underlying rti::routing::adapter::StreamReader of the TypedInput.
UThe sample info type representation. It has to match the type of the underlying rti::routing::adapter::StreamReader of the TypedInput.

This STL-like container encapsulates a collection of loaned, read-only data samples rti::sub::LoanedSample::data() and rti::sub::LoanedSample::info() from a TypedInput.

To obtain a LoanedSamples, you need to call one of the read/take operations from a TypedInput. The samples have to be eventually returned to the TypedInput by calling rti::routing::adapter::StreamReader::return_loan on the underlying rti::routing::adapter::StreamReader of the TypedInput. The destructor takes care of that, and the return_loan() function lets you do it explicitly if needed.

As a move-only type, copying a LoanedSamples is not allowed. If you need to return a LoanedSamples from a function or assign it to another variable, use dds::core::move() (or std::move() for C++11).

Iterators and overloaded subscript operators let you access the samples in this container, which are of the type rti::routing::processor::LoanedSample.

This code demonstrates how to access the info and data of each sample in a DataReader:

auto samples = reader.take();
for (const auto& sample : samples) {
if (sample.info().valid()) {
std::cout << sample.data() << std::endl;
}
}
See Also
dds::sub::LoanedSamples

Member Typedef Documentation

template<typename T, typename U = dds::sub::SampleInfo>
typedef SampleIterator<T, U> rti::routing::processor::LoanedSamples< T, U >::iterator

The iterator type.

Constructor & Destructor Documentation

template<typename T, typename U = dds::sub::SampleInfo>
rti::routing::processor::LoanedSamples< T, U >::LoanedSamples ( )
inline

Creates an empty LoanedSamples object.

template<typename T, typename U = dds::sub::SampleInfo>
rti::routing::processor::LoanedSamples< T, U >::~LoanedSamples ( ) throw ()
inline

Automatically returns the loan to the TypedInput used to obtained these samples.

See Also
return_loan

References rti::routing::processor::LoanedSamples< T, U >::return_loan().

Member Function Documentation

template<typename T, typename U = dds::sub::SampleInfo>
LoanedSample<T,U> rti::routing::processor::LoanedSamples< T, U >::operator[] ( size_t  index)
inline

Provides access to the underlying LoanedSample object in array-like syntax.

Parameters
[in]indexThe index of the Sample. Allowed values are from 0 to length()-1.
Returns
A LoanedSample object that refers to data and info at the specified index.
template<typename T, typename U = dds::sub::SampleInfo>
int32_t rti::routing::processor::LoanedSamples< T, U >::length ( ) const
inline

Gets the number of samples in this collection.

template<typename T, typename U = dds::sub::SampleInfo>
void rti::routing::processor::LoanedSamples< T, U >::return_loan ( )
inline

Returns the samples to the TypedInput used to get these samples.

Thes operation returns the samples by calling the return_loan operation on the underlying rti::routing::stream::StreamReader of the TypedInput.

Note
Explicitly calling return_loan is optional, since the destructor does it implicitly.

This operation tells the TypedInput that the application is done accessing the collection of samples.

It is not necessary for an application to return the loans immediately after the call to read or take. However, as these buffers correspond to internal resources, the application should not retain them indefinitely.

Exceptions
std::exceptionIf there was an error returning the loan to the TypedInput.

Referenced by rti::routing::processor::LoanedSamples< T, U >::~LoanedSamples().

template<typename T, typename U = dds::sub::SampleInfo>
iterator rti::routing::processor::LoanedSamples< T, U >::begin ( )
inline

Gets an iterator to the first sample.

template<typename T, typename U = dds::sub::SampleInfo>
iterator rti::routing::processor::LoanedSamples< T, U >::end ( )
inline

Gets an iterator to one past the last sample.

template<typename T, typename U = dds::sub::SampleInfo>
const_iterator rti::routing::processor::LoanedSamples< T, U >::begin ( ) const
inline

Gets an iterator to the first sample.

template<typename T, typename U = dds::sub::SampleInfo>
const_iterator rti::routing::processor::LoanedSamples< T, U >::end ( ) const
inline

Gets an iterator to one past the last sample.

template<typename T, typename U = dds::sub::SampleInfo>
void rti::routing::processor::LoanedSamples< T, U >::swap ( LoanedSamples< T, U > &  other) throw ()
inline

Swaps two LoanedSamples containers.


RTI Routing Service Version 6.0.1 Copyright © Sun Nov 17 2019 Real-Time Innovations, Inc