RTI Connext Modern C++ API  Version 7.0.0
rti::sub Namespace Reference

<<extension>> Extensions to dds::sub More...

Classes

class  AckResponseData
 <<extension>> Data payload associated to an application-level acknowledgment More...
 
struct  IsValidData
 <<extension>> A functor that returns true when a sample has valid data. More...
 
class  LoanedSample
 The element type of a dds::sub::LoanedSamples collection. More...
 
class  ManipulatorSelector
 
class  SampleIterator
 A random-access iterator of LoanedSample. More...
 
class  SampleProcessor
 <<extension>> <<reference-type>> Utility to read and process the data samples that one or more DataReaders receive using a sample handler. More...
 
class  SharedSamples
 Provides access to a collection of middleware-loaned samples. More...
 
class  TopicQuery
 <<extension>> <<reference-type>> Allows a dds::sub::DataReader to query the sample cache of its matching dds::pub::DataWriters. More...
 
class  TopicQueryData
 <<extension>> <<value-type>> Provides information about a TopicQuery More...
 
class  TopicQuerySelection
 <<extension>> <<value-type>> Specifies the data query that defines a TopicQuery. More...
 
struct  TopicQuerySelectionKind_def
 The definition of the dds::core::safe_enum rti::sub::TopicQuerySelectionKind. More...
 
class  ValidLoanedSamples
 <<extension>> <<C++11>> <<move-only-type>> Provides access to only those samples that contain valid data More...
 
class  ValidSampleIterator
 A forward iterator adapter that skips invalid samples. More...
 

Typedefs

typedef dds::core::safe_enum< TopicQuerySelectionKind_defTopicQuerySelectionKind
 Safe Enumeration of TopicQuerySelectionKind_def More...
 

Functions

template<typename T >
dds::topic::ParticipantBuiltinTopicData matched_publication_participant_data (const dds::sub::DataReader< T > &reader, const dds::core::InstanceHandle &handle)
 <<extension>> This operation retrieves the information on the discovered dds::domain::DomainParticipant associated with the publication that is currently matching with the dds::sub::DataReader. More...
 
template<typename T >
bool is_matched_publication_alive (const dds::sub::DataReader< T > &reader, const dds::core::InstanceHandle &handle)
 <<extension>> Check if a matched publication is alive. More...
 
template<typename T >
std::vector< dds::topic::PublicationBuiltinTopicDatamatched_publication_data (const dds::sub::DataReader< T > &reader)
 <<extension>> Obtain the PublicationBuiltinTopicData for all of the publications matched with a DataReader. More...
 
template<typename SubscriberForwardIterator >
uint32_t find_subscribers (const dds::domain::DomainParticipant participant, SubscriberForwardIterator begin, uint32_t max_size)
 <<extension>> Retrieve all of the dds::sub::Subscriber created from this dds::domain::DomainParticipant More...
 
template<typename SubscriberBackInsertIterator >
uint32_t find_subscribers (const dds::domain::DomainParticipant participant, SubscriberBackInsertIterator begin)
 <<extension>> Retrieve all of the dds::sub::Subscriber created from this dds::domain::DomainParticipant More...
 
dds::sub::Subscriber find_subscriber (const dds::domain::DomainParticipant participant, const std::string &subscriber_name)
 <<extension>> Finds a Subscriber by name More...
 
template<typename AnyDataReaderBackInsertIterator >
uint32_t find_datareaders (dds::sub::Subscriber subscriber, AnyDataReaderBackInsertIterator begin)
 <<extension>> Retrieve all the dds::sub::DataReader created from this dds::sub::Subscriber More...
 
template<typename AnyDataReaderForwardIterator >
uint32_t find_datareaders (dds::sub::Subscriber subscriber, AnyDataReaderForwardIterator begin, uint32_t max_size)
 <<extension>> Retrieve all the readers created from a subscriber. More...
 
template<typename Reader >
Reader find_datareader_by_topic_name (dds::sub::Subscriber subscriber, const std::string &topic_name)
 <<extension>> Retrieves a dds::sub::DataReader with the given topic name within the dds::sub::Subscriber More...
 
template<typename Reader >
Reader find_datareader_by_name (dds::sub::Subscriber subscriber, const std::string &datareader_name)
 <<extension>> Retrieves a dds::sub::DataReader with the given name within the dds::sub::Subscriber More...
 
template<typename Reader , typename T >
Reader find_datareader_by_topic_description (const dds::sub::Subscriber &subscriber, const dds::topic::TopicDescription< T > &topic_description)
 <<extension>> Retrieves a dds::sub::DataReader with the given TopicDescription within the dds::sub::Subscriber More...
 
template<typename Reader >
Reader find_datareader_by_name (dds::domain::DomainParticipant participant, const std::string &datareader_name)
 <<extension>> Retrieves a dds::sub::DataReader within the dds::domain::DomainParticipant with the given name More...
 
dds::sub::Subscriber implicit_subscriber (const dds::domain::DomainParticipant &dp)
 <<extension>> Retrieves the implicit dds::sub::Subscriber for the given dds::domain::DomainParticipant. More...
 
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. More...
 
template<typename T >
std::ostream & operator<< (std::ostream &out, const LoanedSample< T > &sample)
 Calls the operator on the data or prints [invalid data]. More...
 
template<typename T >
ValidLoanedSamples< T >::iterator begin (ValidLoanedSamples< T > &ls)
 
template<typename T >
ValidLoanedSamples< T >::const_iterator begin (const ValidLoanedSamples< T > &ls)
 
template<typename T >
ValidLoanedSamples< T >::iterator end (ValidLoanedSamples< T > &ls)
 
template<typename T >
ValidLoanedSamples< T >::const_iterator end (const ValidLoanedSamples< T > &ls)
 
template<typename T >
void swap (ValidLoanedSamples< T > &ls1, ValidLoanedSamples< 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...
 
bool operator== (const SampleInfoImpl &other) const
 Compare two dds::sub::SampleInfo objects for equality. More...
 
template<typename T >
ValidSampleIterator< T > valid_data (const SampleIterator< T > &sample_iterator)
 <<extension>> Returns an iterator that skips invalid samples More...
 
TopicQueryData create_topic_query_data_from_service_request (const rti::topic::ServiceRequest &service_request)
 Creates a TopicQueryData from a ServiceRequest. More...
 
TopicQuery find_topic_query (dds::sub::AnyDataReader datareader, const rti::core::Guid &guid)
 Looks up a TopicQuery by its GUID. More...
 
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 More...
 
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 More...
 
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 More...
 

Detailed Description

<<extension>> Extensions to dds::sub

Function Documentation

◆ matched_publication_participant_data()

template<typename T >
dds::topic::ParticipantBuiltinTopicData rti::sub::matched_publication_participant_data ( const dds::sub::DataReader< T > &  reader,
const dds::core::InstanceHandle handle 
)

<<extension>> This operation retrieves the information on the discovered dds::domain::DomainParticipant associated with the publication that is currently matching with the dds::sub::DataReader.

Note
This is a standalone function in the namespace rti::sub

The publication_handle must correspond to a publication currently associated with the dds::sub::DataReader. Otherwise, the operation will fail with dds::core::InvalidArgumentError. The operation may also fail with dds::core::PreconditionNotMetError if the publication corresponds to the same dds::domain::DomainParticipant that the DataReader belongs to. Use the operation dds::sub::matched_publications to find the publications that are currently matched with the dds::sub::DataReader.

Exceptions
Oneof the Standard Exceptions or dds::core::NotEnabledError
Template Parameters
TThe topic-type that the DataReader subscribes to
Parameters
readerThe reader to lookup the matched participant data of
handleThe InstanceHandle to a specific publication associated with a DataWriter. Must correspond to a publication currently associated with the DataReader. This handle is available in the dds::sub::SampleInfo::publication_handle()
Returns
The dds::topic::ParticipantBuiltinTopicData of the DomainParticipant of a matched publication of a dds::sub::DataReader

◆ is_matched_publication_alive()

template<typename T >
bool rti::sub::is_matched_publication_alive ( const dds::sub::DataReader< T > &  reader,
const dds::core::InstanceHandle handle 
)

<<extension>> Check if a matched publication is alive.

Note
This is a standalone function in the namespace rti::sub
Template Parameters
TThe topic-type that the DataReader subscribes to.
Parameters
readerThe DataReader.
handleThe dds::core::InstanceHandle of the matched publication.

This API is used for querying the endpoint liveliness of a matched publication. A matched publication will be marked as not alive if the liveliness that it committed to through its LIVELINESS QoS policy was not respected. Note that if the participant associated with the matched publication loses liveliness, the dds::core::InstanceHandle will become invalid and this function will fail with dds::core::InvalidArgumentError.

Parameters
reader<<in>> The DataReader.
handle<<in>> The dds::core::InstanceHandle of the matched publication. See dds::sub::matched_publications for a description of what is considered a matched publication.
Exceptions
Oneof the Standard Exceptions
Returns
A boolean indicating whether or not the matched publication is alive.

◆ matched_publication_data()

template<typename T >
std::vector< dds::topic::PublicationBuiltinTopicData > rti::sub::matched_publication_data ( const dds::sub::DataReader< T > &  reader)

<<extension>> Obtain the PublicationBuiltinTopicData for all of the publications matched with a DataReader.

Note
This is a standalone function in the namespace rti::sub

This API retrieves the matched subscription data from all of the publications currently matched a DataReader.

Template Parameters
TThe topic-type that the DataReader subscribes to.
Parameters
readerThe DataReader.
Returns
A std::vector containing all of the matched publication data.

◆ find_subscribers() [1/2]

template<typename SubscriberForwardIterator >
uint32_t rti::sub::find_subscribers ( const dds::domain::DomainParticipant  participant,
SubscriberForwardIterator  begin,
uint32_t  max_size 
)

<<extension>> Retrieve all of the dds::sub::Subscriber created from this dds::domain::DomainParticipant

Note
This is a standalone function in the namespace rti::sub
Template Parameters
SubscriberForwardIteratorType of the forward iterator passed into this function, whose value_type must be dds::sub::Subscriber.
Parameters
participantThe dds::domain::DomainParticipant the Publishers belong to
beginA forward iterator to the position in the destination container where to begin copying the found Subscribers into
max_sizeThe maximum size of Subscribers to add
Returns
The number of found Subscribers

References dds::sub::begin(), and find_subscribers().

Referenced by find_subscribers().

◆ find_subscribers() [2/2]

template<typename SubscriberBackInsertIterator >
uint32_t rti::sub::find_subscribers ( const dds::domain::DomainParticipant  participant,
SubscriberBackInsertIterator  begin 
)

<<extension>> Retrieve all of the dds::sub::Subscriber created from this dds::domain::DomainParticipant

Note
This is a standalone function in the namespace rti::sub
Template Parameters
AnyDataReaderBackInsertIteratorType of the back-inserting iterator passed into this function, whose value_type must be dds::sub::Subscriber.
Parameters
participantThe dds::domain::DomainParticipant the Subscribers belong to
beginA back-inserting iterator to the position in the destination container to insert the found Subscribers into
Returns
The number of found Subscribers

References dds::sub::begin(), find_subscriber(), and find_subscribers().

◆ find_subscriber()

dds::sub::Subscriber rti::sub::find_subscriber ( const dds::domain::DomainParticipant  participant,
const std::string &  subscriber_name 
)

<<extension>> Finds a Subscriber by name

Note
This is a standalone function in the namespace rti::sub
Template Parameters
AnyDataReaderBackInsertIteratorType of the back-inserting iterator passed into this function, whose value_type must be dds::sub::AnyDataReader.
Parameters
participantThe dds::domain::DomainParticipant the Subscribers belong to
subscriber_nameThe name of the Subscriber
Returns
A valid reference if the a subscriber with that name exists or a reference equals to dds::core::null otherwise.

Referenced by find_subscribers().

◆ find_datareaders() [1/2]

template<typename AnyDataReaderBackInsertIterator >
uint32_t rti::sub::find_datareaders ( dds::sub::Subscriber  subscriber,
AnyDataReaderBackInsertIterator  begin 
)

<<extension>> Retrieve all the dds::sub::DataReader created from this dds::sub::Subscriber

Note
This is a standalone function in the namespace rti::sub
Template Parameters
AnyDataReaderBackInsertIteratorType of the back-inserting iterator passed into this function, whose value_type must be dds::sub::AnyDataReader.
Parameters
subscriberThe dds::sub::Subscriber the DataReaders belong to
beginA back-inserting iterator to the position in the destination container to insert the found DataReaders into
Returns
The number of found DataReaders
See also
Looking up DataReaders

References dds::sub::begin(), and find_datareaders().

Referenced by find_datareaders().

◆ find_datareaders() [2/2]

template<typename AnyDataReaderForwardIterator >
uint32_t rti::sub::find_datareaders ( dds::sub::Subscriber  subscriber,
AnyDataReaderForwardIterator  begin,
uint32_t  max_size 
)

<<extension>> Retrieve all the readers created from a subscriber.

Note
This is a standalone function in the namespace rti::sub
Template Parameters
AnyDataReaderForwardIteratorA forward iterator whose value_type is dds::sub::AnyDataReader
Parameters
subscriberThe dds::sub::Subscriber the readers belong to
beginA forward iterator to the position in the destination container where to begin copying the found readers into.
max_sizeThe maximum number of readers to return
Returns
The number of found readers
See also
Looking up DataReaders

References dds::sub::begin(), and find_datareaders().

◆ find_datareader_by_topic_name()

template<typename Reader >
Reader rti::sub::find_datareader_by_topic_name ( dds::sub::Subscriber  subscriber,
const std::string &  topic_name 
)

<<extension>> Retrieves a dds::sub::DataReader with the given topic name within the dds::sub::Subscriber

Note
This is a standalone function in the namespace rti::sub

Use this operation on the built-in dds::sub::Subscriber (Built-in Topics) to access the built-in dds::sub::DataReader entities for the built-in topics.

The built-in dds::sub::DataReader is created when this operation is called on a built-in topic for the first time. The built-in dds::sub::DataReader is deleted automatically when the dds::domain::DomainParticipant is deleted.

To ensure that builtin dds::sub::DataReader entities receive all the discovery traffic, it is suggested that you lookup the builtin dds::sub::DataReader before the dds::domain::DomainParticipant is enabled. Looking up builtin dds::sub::DataReader may implicitly register builtin transports due to creation of dds::sub::DataReader (see Built-in Transport Plugins for details on when a builtin transport is registered). Therefore, if you are want to modify builtin transport properties, do so before using this operation.

Therefore the suggested sequence when looking up builtin DataReaders is:

The returned dds::sub::DataReader may be enabled or disabled.

If more than one dds::sub::DataReader is attached to the dds::sub::Subscriber, this operation may return any one of them.

MT Safety:
UNSAFE. It is not safe to lookup a dds::sub::DataReader in one thread while another thread is simultaneously creating or destroying that dds::sub::DataReader.
Template Parameters
ReaderThe type of the reader. It can be dds::sub::AnyDataReader, or an instantiation of dds::sub::DataReader<T> (if T is not the correct type, this function throws dds::core::InvalidDowncastError)
Parameters
subscriberThe dds::sub::Subscriber that created the DataReader to find
topic_nameTopic name of the DataReader to find
Returns
The DataReader with the given topic name, or dds::core::null if it doesn't exist
See also
Looking up DataReaders

References find_datareader_by_topic_name(), and dds::core::null.

Referenced by find_datareader_by_topic_name().

◆ find_datareader_by_name() [1/2]

template<typename Reader >
Reader rti::sub::find_datareader_by_name ( dds::sub::Subscriber  subscriber,
const std::string &  datareader_name 
)

<<extension>> Retrieves a dds::sub::DataReader with the given name within the dds::sub::Subscriber

Note
This is a standalone function in the namespace rti::sub
Template Parameters
ReaderThe type of the reader. It can be dds::sub::AnyDataReader, or an instantiation of dds::sub::DataReader<T> (if T is not the correct type, this function throws dds::core::InvalidDowncastError)

Every dds::sub::DataReader in the system has an entity name which is configured and stored in the <<extension>> EntityName policy, ENTITY_NAME.

This operation retrieves the dds::sub::DataReader within the dds::sub::Subscriber whose name matches the one specified. If there are several dds::sub::DataReader with the same name within the dds::sub::Subscriber, the operation returns the first matching occurrence.

Parameters
subscriberThe dds::sub::Subscriber that created the DataReader to find
datareader_nameEntity name of the DataReader to find
Returns
The DataReader with the given name, or dds::core::null if it doesn't exist
See also
Looking up DataReaders

References find_datareader_by_name(), and dds::core::null.

Referenced by find_datareader_by_name().

◆ find_datareader_by_topic_description()

template<typename Reader , typename T >
Reader rti::sub::find_datareader_by_topic_description ( const dds::sub::Subscriber subscriber,
const dds::topic::TopicDescription< T > &  topic_description 
)

<<extension>> Retrieves a dds::sub::DataReader with the given TopicDescription within the dds::sub::Subscriber

Note
This is a standalone function in the namespace rti::sub
Template Parameters
ReaderThe type of the reader returned, for example, dds::sub::DataReader<Foo>, or dds::sub::AnyDataReader
TThe topic-type
Parameters
subscriberThe Subscriber to which the DataReader belongs
topic_descriptionThe TopicDescription identifying the DataReader to find
Returns
The found DataReader, or dds::core::null if it doesn't exist

References find_datareader_by_topic_description(), dds::topic::TopicDescription< T >::name(), and dds::core::null.

Referenced by find_datareader_by_topic_description().

◆ find_datareader_by_name() [2/2]

template<typename Reader >
Reader rti::sub::find_datareader_by_name ( dds::domain::DomainParticipant  participant,
const std::string &  datareader_name 
)

<<extension>> Retrieves a dds::sub::DataReader within the dds::domain::DomainParticipant with the given name

Note
This is a standalone function in the namespace rti::sub
Template Parameters
ReaderThe type of the reader. It can be dds::sub::AnyDataReader, or an instantiation of dds::sub::DataReader<T> (if T is not the correct type, this function throws dds::core::InvalidDowncastError)

Every dds::sub::DataReader in the system has an entity name which is configured and stored in the EntityName policy, ENTITY_NAME.

Every dds::sub::Subscriber in the system has an entity name which is also configured and stored in the EntityName policy, ENTITY_NAME.

This operation retrieves a dds::sub::DataReader within a dds::sub::Subscriber given the specified name which encodes both to the dds::sub::DataReader and the dds::sub::Subscriber name.

If there are several dds::sub::DataReader with the same name within the corresponding dds::sub::Subscriber this function returns the first matching occurrence.

The specified name might be given as a fully-qualified entity name or as a plain name.

The fully qualified entity name is a concatenation of the dds::sub::Subscriber to which the dds::sub::DataReader belongs and the entity name of of the dds::sub::DataReader itself, separated by a double colon "::". For example: MySubscriberName::MyDataReaderName

The plain name contains the dds::sub::DataReader name only. In this situation it is implied that the dds::sub::DataReader belongs to the implicit dds::sub::Subscriber so the use of a plain name is equivalent to specifying a fully qualified name with the dds::sub::Subscriber name part being "implicit". For example: the plain name "MyDataReaderName" is equivalent to specifiying the fully qualified name "implicit::MyDataReaderName"

The dds::sub::DataReader is only looked up within the dds::sub::Subscriber specified in the fully qualified name, or within the implicit dds::sub::Subscriber if the name was not fully qualified.

Parameters
participantThe dds::domain::DomainParticipant within which the dds::sub::DataReader exists
datareader_nameEntityName of the DataReader to find
Returns
The first reader with the given name or dds::core::null if it is not found.
See also
rti::sub::find_datareader_by_name(const dds::sub::Subscriber&, const std::string&)

References find_datareader_by_name(), implicit_subscriber(), and dds::core::null.

◆ implicit_subscriber()

dds::sub::Subscriber rti::sub::implicit_subscriber ( const dds::domain::DomainParticipant dp)

<<extension>> Retrieves the implicit dds::sub::Subscriber for the given dds::domain::DomainParticipant.

Note
This is a standalone function in the namespace rti::sub

If an implicit Subscriber does not already exist, this creates one.

The implicit Subscriber is created with default dds::sub::qos::SubscriberQos and no listener. When a DomainParticipant is deleted, if there are no attached dds::sub::DataReader that belong to the implicit Subscriber, the implicit Subscriber will be implicitly deleted.

                \par MT Safety:

UNSAFE. it is not safe to create the implicit subscriber while another thread may be simultaneously calling dds::domain::DomainParticipant::default_subscriber_qos(const dds::sub::qos::SubscriberQos & qos ).

Parameters
dpThe DomainParticipant that the implicit subscriber belongs to.
Returns
The implicit Subscriber

Referenced by find_datareader_by_name().

◆ copy_to_sample()

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.

Example:

std::vector<Sample<Foo> > sample_vector;
std::transform(
std::back_inserter(sample_vector),
rti::sub::copy_to_sample<Foo>);

◆ operator<<()

template<typename T >
std::ostream & operator<< ( std::ostream &  out,
const LoanedSample< T > &  sample 
)

Calls the operator on the data or prints [invalid data].

References dds::sub::Sample< T >::data().

◆ begin() [1/2]

◆ begin() [2/2]

template<typename T >
ValidLoanedSamples< T >::const_iterator begin ( const ValidLoanedSamples< T > &  ls)

◆ end() [1/2]

◆ end() [2/2]

template<typename T >
ValidLoanedSamples< T >::const_iterator end ( const ValidLoanedSamples< T > &  ls)

◆ swap()

template<typename T >
void swap ( ValidLoanedSamples< T > &  ls1,
ValidLoanedSamples< T > &  ls2 
)
throw (
)

◆ valid_data() [1/2]

template<typename T >
ValidLoanedSamples< T > rti::sub::valid_data ( LoanedSamples< T > &&  samples)

<<C++11>> <<extension>> Returns a collection that provides access only to samples with valid data

Template Parameters
TThe 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:

auto valid_samples = rti::sub::valid_data(reader.read());
for (const auto& sample : valid_samples) {
// no need to check sample.info().valid()
std::cout << sample.data() << std::endl;
}
Parameters
samplesThe 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());
Or an 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
Returns
A forward-iterable collection that provides access only to samples with valid data. Note that this collection doesn't provide random access.
Postcondition
samples is invalid cannot be used after this call
See also
rti::sub::valid_data(const SampleIterator<T>&), which applies to an iterator rather to the whole collection
Reading data samples

◆ operator==()

bool rti::sub::operator== ( const SampleInfoImpl &  other) const

Compare two dds::sub::SampleInfo objects for equality.

Referenced by rti::sub::TopicQuerySelection::kind().

◆ valid_data() [2/2]

template<typename T >
ValidSampleIterator< T > rti::sub::valid_data ( const SampleIterator< T > &  sample_iterator)

<<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& ()).

std::vector<KeyedType> data_vector;
std::copy(
std::back_inserter(data_vector));

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.

See also
dds::sub::LoanedSamples
rti::sub::IsValidData
dds::sub::SampleInfo::valid()
rti::sub::valid_data(LoanedSamples<T>&&), which applies to the whole collection instead of an iterator
Reading data samples

◆ create_topic_query_data_from_service_request()

TopicQueryData create_topic_query_data_from_service_request ( const rti::topic::ServiceRequest service_request)

Creates a TopicQueryData from a ServiceRequest.

This operation will extract the content from the request body of the rti::topic::ServiceRequest to create a rti::sub::TopicQueryData object.

The specified rti::topic::ServiceRequest must be a valid sample associated with the service id rti::core::ServiceRequestId_def::TOPIC_QUERY. Otherwise this operation will return false.

This operation can be called within the context of a dds::pub::DataWriterListener::on_service_request_accepted to retrieve the rti::sub::TopicQueryData of a rti::topic::ServiceRequest that has been received with service id rti::core::ServiceRequestId_def::TOPIC_QUERY

Parameters
service_requestThe rti::topic::ServiceRequest that contains the rti::sub::TopicQueryData as part of its request body.
Returns
A rti::sub::TopicQueryData object where the content from the service request is extracted.

◆ find_topic_query()

TopicQuery find_topic_query ( dds::sub::AnyDataReader  datareader,
const rti::core::Guid guid 
)

Looks up a TopicQuery by its GUID.

Parameters
datareaderThe DataReader used to create the TopicQuery
guidThe TopicQuery's GUID
Returns
The TopicQuery if it exists or a dds::core::null reference otherwise.
See also
rti::sub::TopicQuery::guid()

Referenced by rti::sub::TopicQuery::datareader().

◆ unpack() [1/3]

template<typename T >
void rti::sub::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

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:

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.

Referenced by unpack().

◆ unpack() [2/3]

template<typename T >
std::vector< std::shared_ptr< const T > > rti::sub::unpack ( const dds::sub::SharedSamples< T > &  samples)

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

Note
This is a standalone function in the namespace rti::sub

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

References dds::sub::SharedSamples< T, DELEGATE >::length(), and unpack().

◆ unpack() [3/3]

template<typename T >
std::vector< std::shared_ptr< const T > > rti::sub::unpack ( dds::sub::LoanedSamples< T > &&  samples)

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

Note
This is a standalone function in the namespace rti::sub

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

References unpack().