RTI Connext Modern C++ API
Version 6.0.1
|
The element type of a dds::sub::LoanedSamples collection. More...
#include <LoanedSample.hpp>
Public Types | |
typedef T | DataType |
The data type. | |
typedef dds::sub::SampleInfo | InfoType |
dds::sub::SampleInfo | |
Public Member Functions | |
const DataType & | data () const |
Gets the data. | |
const InfoType & | info () const |
Gets the sample info. | |
operator const DataType & () const | |
Allows implicit conversion to the data type. | |
bool | operator== (const LoanedSample &other) const |
Compares the data and info. | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T > | |
dds::sub::Sample< T > | copy_to_sample (const rti::sub::LoanedSample< T > &ls) |
Copies the contents of a rti::sub::LoanedSample into a dds::sub::Sample. | |
template<typename T > | |
std::ostream & | operator<< (std::ostream &out, const LoanedSample< T > &sample) |
Calls the operator on the data or prints [invalid data]. | |
The element type of a dds::sub::LoanedSamples collection.
This class encapsulates loaned, read-only data and SampleInfo from a DataReader.
LoanedSample instances are always the element of a dds::sub::LoanedSamples collection and have to be returned through that collection. A LoanedSample instance is a lightweight handle to data owned by the DataReader from where you received a LoanedSamples collection.
This type is not exactly a reference type, value type or move-only type. Copying a LoanedSample simply creates a new handle to the same loaned data.
The difference between LoanedSample and dds::sub::Sample is that the latter is a value type that the application owns. A Sample can be constructed by copying the data and meta-data referenced by a LoanedSample.
In most cases the only thing applications care about is that the elements of a dds::sub::LoanedSamples collection have two methods, data() and info(). For example:
typedef T rti::sub::LoanedSample< T >::DataType |
The data type.
typedef dds::sub::SampleInfo rti::sub::LoanedSample< T >::InfoType |
|
inline |
Gets the data.
dds::core::PreconditionNotMetError | if !info().valid(). |
|
inline |
Gets the sample info.
|
inline |
Allows implicit conversion to the data type.
One use of this conversion operator is to simplify the usage of generic algorithms that iterate on a LoanedSamples collection.
For example, the following example copies all the data of in a LoanedSamples collection into a vector of the data type. The call to std::copy
works as-is thanks to this conversion.
Note: the example above may throw dds::core::PreconditionNotMetError if any of the samples has invalid data. See valid_data() to iterate only over samples with valid data.
dds::core::PreconditionNotMetError | if !info ().valid(). |
|
inline |
Compares the data and info.
|
related |
Copies the contents of a rti::sub::LoanedSample into a dds::sub::Sample.
Example:
|
related |
Calls the operator on the data or prints [invalid data].