RTI Connext Modern C++ API  Version 6.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
dds::sub::SharedSamples Class Reference

<<reference-type>> A sharable and container-safe version of LoanedSamples. More...

#include <dds/sub/SharedSamples.hpp>

Public Member Functions

 SharedSamples (dds::sub::LoanedSamples< T > &ls)
 Constructs and instance of SharedSamples removing the ownership of the loan from the LoanedSamples.
 
const_iterator begin () const
 Same as LoanedSamples::begin()
 
const_iterator end () const
 Same as LoanedSamples::end()
 
DELEGATE< T >::value_type operator[] (size_t index) const
 Same as LoanedSamples::operator[](size_t)
 
uint32_t length () const
 Returns the number of samples.
 

Related Functions

(Note that these are not member functions.)

template<typename T >
void unpack (const dds::sub::SharedSamples< T > &samples, std::vector< std::shared_ptr< const T > > &sample_vector)
 <<extension>> <<C++11>> Unpacks a SharedSamples collection into individual shared_ptr's in a vector
 
template<typename T >
std::vector< std::shared_ptr
< const T > > 
unpack (const dds::sub::SharedSamples< T > &samples)
 <<extension>> <<C++11>> Unpacks a SharedSamples collection into individual shared_ptr's in a vector
 
template<typename T >
std::vector< std::shared_ptr
< const T > > 
unpack (dds::sub::LoanedSamples< T > &&samples)
 <<extension>> <<C++11>> Unpacks a LoanedSamples collection into individual shared_ptr's in a vector
 

Detailed Description

<<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

Constructor & Destructor Documentation

dds::sub::SharedSamples::SharedSamples ( dds::sub::LoanedSamples< T > &  ls)
inline

Constructs and instance of SharedSamples removing the ownership of the loan from the LoanedSamples.

The constructor is implicit to simplify statements like the following:

SharedSamples<Foo> samples = reader.take(); // reader.take() returns LoanedSamples
Parameters
lsthe loaned samples.

Member Function Documentation

const_iterator dds::sub::SharedSamples::begin ( ) const
inline
const_iterator dds::sub::SharedSamples::end ( ) const
inline
DELEGATE<T>::value_type dds::sub::SharedSamples::operator[] ( size_t  index) const
inline
uint32_t dds::sub::SharedSamples::length ( ) const
inline

Returns the number of samples.

See Also
LoanedSamples::length()

Friends And Related Function Documentation

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 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:

dds::sub::SharedSamples<Foo> shared_samples = reader.take();
std::vector<std::shared_ptr<const Foo>> sample_vector;
rti::sub::unpack(shared_samples, sample_vector);
std::cout << *sample_vector[0] << std::endl;
// ...
// Read more samples, unpack them at the end of the same vector
shared_samples = reader.take();
rti::sub::unpack(shared_samples, sample_vector);
// References to the samples can be shared freely
std::shared_ptr<const Foo> sample = sample_vector[3];
// ...
// The loans will be returned automatically
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
TThe topic-type
Parameters
samplesThe collection of samples obtained from the DataReader
sample_vectorThe destination where the samples are pushed back.
template<typename T >
std::vector< std::shared_ptr< const T > > unpack ( const dds::sub::SharedSamples< T > &  samples)
related

<<extension>> <<C++11>> Unpacks a SharedSamples collection into individual shared_ptr's in a vector

This overload returns a new vector instead of adding into an existing one.

See Also
unpack(const dds::sub::SharedSamples<T>&, std::vector<std::shared_ptr<const T> >&)
template<typename T >
std::vector< std::shared_ptr< const T > > unpack ( dds::sub::LoanedSamples< T > &&  samples)
related

<<extension>> <<C++11>> Unpacks a LoanedSamples collection into individual shared_ptr's in a vector

This overload is a shortcut for unpack(SharedSamples<T>(loaned_samples)) to simplify code like the following:

auto sample_vector = unpack(reader.take());
See Also
unpack(const dds::sub::SharedSamples<T>&, std::vector<std::shared_ptr<const T> >&)

RTI Connext Modern C++ API Version 6.0.1 Copyright © Sat Nov 23 2019 Real-Time Innovations, Inc