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
-
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
template<typename T, typename U = dds::sub::SampleInfo>
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::exception | If there was an error returning the loan to the TypedInput. |
Referenced by rti::routing::processor::LoanedSamples< T, U >::~LoanedSamples().