RTI Connext Modern C++ API Version 7.2.0
|
<<move-only-type>> Provides temporary access to a collection of samples (data and info) from a DataReader. More...
#include <LoanedSamplesImpl.hpp>
Public Types | |
typedef SampleIterator< T > | iterator |
The iterator type. More... | |
Public Member Functions | |
LoanedSamples () | |
Creates an empty LoanedSamples object. More... | |
~LoanedSamples () noexcept | |
Automatically returns the loan to the DataReader. More... | |
value_type | operator[] (size_t index) |
Provides access to the underlying LoanedSample object in array-like syntax. More... | |
unsigned int | length () const |
Gets the number of samples in this collection. More... | |
void | return_loan () |
Returns the samples to the DataReader. More... | |
bool | return_loan_noexcept () noexcept |
Returns the samples to the DataReader (noexcept version) More... | |
iterator | begin () |
Gets an iterator to the first sample. More... | |
iterator | end () |
Gets an iterator to one past the last sample. More... | |
const_iterator | begin () const |
Gets an iterator to the first sample. More... | |
const_iterator | end () const |
Gets an iterator to one past the last sample. More... | |
void | swap (LoanedSamples &other) throw () |
Swap two LoanedSamples containers. More... | |
LoanedSamples (LoanedSamples &&other) | |
<<C++11>> Moves the loan from an existing LoanedSamples to a new one More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
LoanedSamples< T > | move (LoanedSamples< T > &ls) OMG_NOEXCEPT |
Creates a new LoanedSamples instance by moving the contents of an existing one. More... | |
template<typename T > | |
LoanedSamples< T >::iterator | begin (LoanedSamples< T > &ls) |
template<typename T > | |
LoanedSamples< T >::const_iterator | begin (const LoanedSamples< T > &ls) |
template<typename T > | |
LoanedSamples< T >::iterator | end (LoanedSamples< T > &ls) |
template<typename T > | |
LoanedSamples< T >::const_iterator | end (const LoanedSamples< T > &ls) |
template<typename T > | |
void | swap (LoanedSamples< T > &ls1, LoanedSamples< T > &ls2) throw() |
template<typename T > | |
ValidLoanedSamples< T > | valid_data (LoanedSamples< T > &&samples) |
<<C++11>> <<extension>> Returns a collection that provides access only to samples with valid data More... | |
template<typename T > | |
ValidSampleIterator< T > | valid_data (const SampleIterator< T > &sample_iterator) |
<<extension>> Returns an iterator that skips invalid samples More... | |
<<move-only-type>> Provides temporary access to a collection of samples (data and info) from a DataReader.
T | The topic-type. It has to match the type of the DataReader. |
This STL-like container encapsulates a collection of loaned, read-only data samples (data and info) from a DataReader.
To obtain a LoanedSamples you need to call one of the read/take operations from a DataReader. The samples have to be eventually returned to the DataReader. 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 want to have more than one reference to a collection of loaned sample, see SharedSamples. If you need to return a LoanedSamples from a function or assign it to another variable, use dds::core::move()
(or std::move()
<<C++11>>).
Iterators and overloaded subscript operators let you access the samples in this container, which are of the type rti::sub::LoanedSample.
This code demonstrates how to access the info and data of each sample in a DataReader:
typedef SampleIterator<T> dds::sub::LoanedSamples< T >::iterator |
The iterator type.
|
inline |
Creates an empty LoanedSamples object.
|
inlinenoexcept |
Automatically returns the loan to the DataReader.
|
inline |
<<C++11>> Moves the loan from an existing LoanedSamples to a new one
References dds::sub::LoanedSamples< T >::swap().
|
inline |
Provides access to the underlying LoanedSample object in array-like syntax.
index
.
|
inline |
Gets the number of samples in this collection.
|
inline |
Returns the samples to the DataReader.
This operation tells the dds::sub::DataReader 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.
|
inlinenoexcept |
Returns the samples to the DataReader (noexcept version)
This operation has the same behavior as return_loan() but returns false in case of error and doesn't throw exceptions.
|
inline |
Gets an iterator to the first sample.
Referenced by dds::sub::LoanedSamples< T >::begin().
|
inline |
Gets an iterator to one past the last sample.
Referenced by dds::sub::LoanedSamples< T >::end().
|
inline |
Gets an iterator to the first sample.
|
inline |
Gets an iterator to one past the last sample.
|
inline |
Swap two LoanedSamples containers.
Referenced by dds::sub::LoanedSamples< T >::LoanedSamples().
|
related |
Creates a new LoanedSamples instance by moving the contents of an existing one.
Note: in <<C++11>> you can directly use std::move
.
The parameter object loses the ownership of the underlying samples and its state is reset as if it was default initialized. This function must be used to move any named LoanedSamples instance (lvalue) in and out of a function by-value. Using this function is not necessary if the original LoanedSamples is an rvalue. Moving is a very efficient operation and is guaranteed to not throw any exception.
ls | The LoanedSamples object that transfers its ownership of the contained samples into the returned object. After this call, ls is empty. |
ls
had.References dds::sub::move().
|
related |
References dds::sub::LoanedSamples< T >::begin().
|
related |
References dds::sub::LoanedSamples< T >::begin().
|
related |
References dds::sub::LoanedSamples< T >::end().
|
related |
References dds::sub::LoanedSamples< T >::end().
|
related |
|
related |
<<C++11>> <<extension>> Returns a collection that provides access only to samples with valid data
T | The topic-type. It has to match the type of the DataReader. |
This function transforms a LoanedSamples collection into another collection whose iterators only access valid-data samples, skipping any sample such that !sample.info().valid().
This operation is O(1) and will not copy the data samples or allocated any additional memory.
The typical way to use this function is to directly call it on the return value of a read()/take() operation and use it in a for-loop. For example:
samples | The collection of LoanedSamples to transform into a ValidLoanedSamples. It must be an rvalue, so valid actual parameters are the result of one of the read/take operations: auto vs = rti::sub::valid_data(reader.take());
std::move'd existing collection: auto ls = reader.take();
auto vs = rti::sub::valid_data(std::move(ls));
// 'ls' is now invalid and can't be further used
|
samples
is invalid cannot be used after this call
|
related |
<<extension>> Returns an iterator that skips invalid samples
Given a regular sample iterator, this functions creates another iterator it
that behaves exactly the same except that it++
moves to the next valid sample (or to the end of the collection). That is, if it
doesn't point to the end of the collection, it->info.valid()
is always true.
This is useful when your application doesn't need to deal with samples containing meta-information only.
For example, the following code copies all the data in a LoanedSamples collection skipping any invalid samples (otherwise, attempting to copy the data from an invalid sample would throw an exception, see rti::sub::LoanedSample::operator const DataType& ()).
Note that valid_data
(samples.begin()) won't point to the first element if that element is not a valid sample.
A similar utility is the functor rti::sub::IsValidData.