template<typename T, template< typename Q > class DELEGATE = detail::SharedSamples>
class dds::sub::SharedSamples< T, DELEGATE >
<<reference-type>> A sharable and container-safe version of LoanedSamples.
A SharedSamples instance is constructed from a LoanedSamples instance, removing the ownership of the loan from the LoanedSamples.
The destruction of the LoanedSamples object or the explicit invocation of its method return_loan will have no effect on loaned data.
Constructing a SharedSamples from another SharedSamples, creates a new reference to the same loan. Loaned data will be returned automatically to the DataReader once the reference count reaches zero.
- See also
- LoanedSamples
template<typename T >
void unpack |
( |
const dds::sub::SharedSamples< T > & |
samples, |
|
|
std::vector< std::shared_ptr< const T > > & |
sample_vector |
|
) |
| |
|
related |
<<extension>> <<C++11>> Unpacks a SharedSamples collection into individual shared_ptr's in a vector
- Note
#include
<rti/sub/unpack.hpp>
-
This is a standalone function in the namespace rti::sub
This function creates a reference (not a copy) to each sample with valid data in a SharedSamples container and pushes it back into a vector.
Each individual sample in the vector retains a reference to the original SharedSamples that controls when the loan is returned. These references can be further shared. When all the references go out of scope, the loan is returned.
This can be also useful to insert samples from different calls to read()/take() into the same vector. It is however recommended to not hold these samples indefinitely, since they use internal resources.
Example:
std::vector<std::shared_ptr<const Foo>> sample_vector;
std::cout << *sample_vector[0] << std::endl;
shared_samples = reader.
take();
std::shared_ptr<const Foo> sample = sample_vector[3];
- Note
- To finalize a DataReader, all the shared_ptr obtained via unpack() need to have been released. Otherwise DataReader::close() will fail with dds::core::PreconditionNotMetError.
- Template Parameters
-
- Parameters
-
samples | The collection of samples obtained from the DataReader |
sample_vector | The destination where the samples are pushed back. |