CoreDX DDS Modern C++ API
Classes | Public Member Functions | List of all members
dds::sub::DataReader< T > Class Template Reference

The type specific DataReader. More...

Inheritance diagram for dds::sub::DataReader< T >:
Inheritance graph
[legend]
Collaboration diagram for dds::sub::DataReader< T >:
Collaboration graph
[legend]

Classes

class  ManipulatorSelector
 Selector class enabling the streaming API. More...
 
class  Selector
 The Selector class is used by the DataReader to compose read operations. More...
 

Public Member Functions

 DataReader (const dds::sub::Subscriber &sub, const dds::topic::Topic< T > &topic)
 Create a DataReader. More...
 
 DataReader (const dds::sub::Subscriber &sub, const dds::topic::Topic< T > &topic, const dds::sub::qos::DataReaderQos &qos, dds::sub::DataReaderListener< T > *listener=NULL, const dds::core::status::StatusMask &mask=dds::core::status::StatusMask::none())
 Create a DataReader. More...
 
 DataReader (const dds::sub::Subscriber &sub, const dds::topic::ContentFilteredTopic< T > &topic)
 Create a DataReader for a ContentFilteredTopic. More...
 
 DataReader (const dds::sub::Subscriber &sub, const dds::topic::ContentFilteredTopic< T > &topic, const dds::sub::qos::DataReaderQos &qos, dds::sub::DataReaderListener< T > *listener=NULL, const dds::core::status::StatusMask &mask=dds::core::status::StatusMask::none())
 Create a DataReader for a ContentFilteredTopic. More...
 
DataReaderoperator>> (dds::sub::qos::DataReaderQos &qos)
 Gets the DataReaderQos setting for this instance. More...
 
dds::sub::status::DataState default_filter_state ()
 Returns the default read-state (if not changed, it is set to ReaderState::any()).
 
DataReaderdefault_filter_state (const dds::sub::status::DataState &state)
 Set the default state filter for read/take operations. More...
 
DataReaderoperator>> (dds::sub::LoanedSamples< T > &ls)
 This stream operator willl take samples and add them to the LoanedSamples container. More...
 
ManipulatorSelector operator>> (ManipulatorSelector &(manipulator)(ManipulatorSelector &))
 Manipulators are defined externally to make it possible to control whether the streaming operators reads or takes. More...
 
template<typename Functor >
ManipulatorSelector operator>> (Functor f)
 Use this stream operator to control the behavior of the read or take streaming operation. More...
 
LoanedSamples< T > read ()
 Read all samples using the default filter state. More...
 
LoanedSamples< T > take ()
 Take all samples using the default filter state. More...
 
template<typename SamplesFWIterator >
uint32_t read (SamplesFWIterator sfit, uint32_t max_samples)
 Read up to max_samples samples using the default filter state. More...
 
template<typename SamplesFWIterator >
uint32_t take (SamplesFWIterator sfit, uint32_t max_samples)
 Take up to max_samples samples using the default filter state. More...
 
template<typename SamplesBIIterator >
uint32_t read (SamplesBIIterator sbit)
 Read all samples available in the reader cache using the default filter state. More...
 
template<typename SamplesBIIterator >
uint32_t take (SamplesBIIterator sbit)
 Take all samples available in the reader cache samples using the default filter state. More...
 
Selector select ()
 Get a Selector to perform complex data selections, such as per-instance selection, content and status filtering. More...
 
dds::topic::TopicInstance< T > key_value (const dds::core::InstanceHandle &h)
 This operation can be used to retrieve the instance key that corresponds to an instance_handle. More...
 
T & key_value (T &sample, const dds::core::InstanceHandle &h)
 This operation can be used to retrieve the instance key that corresponds to an instance_handle. More...
 
const dds::core::InstanceHandle lookup_instance (const T &key) const
 This operation takes as a parameter an instance and returns a handle that can be used in subsequent operations that accept an instance handle as an argument. More...
 
void listener (Listener *the_listener, const dds::core::status::StatusMask &event_mask)
 Set/Re-set the listener associated with this reader. More...
 
Listenerlistener () const
 Get the listener associated with this reader.
 
- Public Member Functions inherited from dds::sub::AnyDataReader
const dds::sub::Subscribersubscriber () const
 Get the Subscriber that owns this DataReader. More...
 
const dds::topic::TopicDescriptiontopic_description () const
 Get the TopicDescription associated with this DataReader. More...
 
void wait_for_historical_data (const dds::core::Duration &timeout)
 This operation will block the application thread until all “historical” data is received. More...
 
dds::sub::qos::DataReaderQos qos () const
 Gets the DataReaderQos setting for this instance. More...
 
void qos (const dds::sub::qos::DataReaderQos &qos)
 This operation replaces the existing set of QosPolicy settings for a DataReader. More...
 
AnyDataReaderoperator<< (const dds::sub::qos::DataReaderQos &qos)
 This operation replaces the existing set of QosPolicy settings for a DataReader. More...
 
const AnyDataReaderoperator>> (dds::sub::qos::DataReaderQos &qos) const
 Gets the DataReaderQos setting for this instance. More...
 
dds::core::status::LivelinessChangedStatus liveliness_changed_status ()
 This operation obtains the LivelinessChangedStatus object of the DataReader. More...
 
dds::core::status::SampleRejectedStatus sample_rejected_status ()
 This operation obtains the SampleRejectedStatus object of the DataReader. More...
 
dds::core::status::SampleLostStatus sample_lost_status ()
 This operation obtains the SampleLostStatus object of the DataReader. More...
 
dds::core::status::RequestedDeadlineMissedStatus requested_deadline_missed_status ()
 This operation obtains the RequestedDeadlineMissedStatus object of the DataReader. More...
 
dds::core::status::RequestedIncompatibleQosStatus requested_incompatible_qos_status ()
 This operation obtains the RequestedIncompatibleQosStatus object of the DataReader. More...
 
dds::core::status::SubscriptionMatchedStatus subscription_matched_status ()
 This operation obtains the SubscriptionMatchedStatus object of the DataReader. More...
 
- Public Member Functions inherited from dds::core::Entity
void enable ()
 This operation enables the Entity. More...
 
const dds::core::status::StatusMask status_changes ()
 This operation retrieves the list of communication statuses in the Entity that are triggered.That is, the list of statuses whose value has changed since the last time the application read the status. More...
 
const dds::core::InstanceHandle instance_handle () const
 This operation returns the InstanceHandle_t that represents the Entity.
 
void close ()
 This method closes the entity and releases all resources associated with DDS, such as threads, sockets, buffers, etc. More...
 
void retain ()
 Indicates that references to this object may go out of scope but that the application expects to look it up again later. More...
 
- Public Member Functions inherited from dds::core::Reference< DELEGATE >
 Reference (dds::core::null_type &)
 Creates a "null" reference.
 
 Reference (const Reference &ref)
 Creates a reference from another. More...
 
template<typename D >
 Reference (const Reference< D > &ref)
 Enables safe assignment from other reference types. More...
 
 Reference (DELEGATE_T *p)
 The following two constructors create a dds Reference from a vendor specific delegate. More...
 
 ~Reference ()
 Destroys a reference.
 
template<typename R >
bool operator== (const R &ref) const
 Compares two reference objects and returns true if they are equal. More...
 
template<typename R >
bool operator!= (const R &ref) const
 Compares two reference objects and returns true if they are not-equal. More...
 
Referenceoperator= (const null_type)
 Special assignment operators that takes care of assigning null to this reference. More...
 
bool is_nil () const
 Returns true if this reference object is nil, meaning pointing to null.
 
bool operator== (const null_type) const
 Special operator== used to check if this reference object equals the null reference. More...
 
bool operator!= (const null_type nil) const
 Special operator!= used to check if this reference object does not equals the null reference. More...
 
const DELEGATE_REF_T & delegate () const
 Returns a reference to the underlying delegate. More...
 
DELEGATE_REF_T & delegate ()
 Returns a reference to the underlying delegate. More...
 
DELEGATE * operator-> ()
 The operator->() is provided to be able to directly invoke methods on the delegate. More...
 
const DELEGATE * operator-> () const
 The operator->() is provided to be able to directly invoke methods on the delegate. More...
 

Detailed Description

template<typename T>
class dds::sub::DataReader< T >

The type specific DataReader.

Constructor & Destructor Documentation

◆ DataReader() [1/4]

template<typename T , template< typename Q > class DELEGATE>
dds::sub::DataReader< T, DELEGATE >::DataReader ( const dds::sub::Subscriber sub,
const dds::topic::Topic< T > &  topic 
)

Create a DataReader.

The QoS will be the same as "sub.default_datareader_qos()".

Parameters
subthe subscriber owning this DataReader.
topicthe topic associated with this DataReader.

◆ DataReader() [2/4]

template<typename T , template< typename Q > class DELEGATE>
dds::sub::DataReader< T, DELEGATE >::DataReader ( const dds::sub::Subscriber sub,
const dds::topic::Topic< T > &  topic,
const dds::sub::qos::DataReaderQos qos,
dds::sub::DataReaderListener< T > *  listener = NULL,
const dds::core::status::StatusMask mask = dds::core::status::StatusMask::none() 
)

Create a DataReader.

Parameters
subthe subscriber owning this DataReader.
topicthe topic associated with this DataReader.
qosthe QoS settings for this DataReader.
listenerthe listener.
maskthe event mask associated to the DataReader listener.

◆ DataReader() [3/4]

template<typename T , template< typename Q > class DELEGATE>
dds::sub::DataReader< T, DELEGATE >::DataReader ( const dds::sub::Subscriber sub,
const dds::topic::ContentFilteredTopic< T > &  topic 
)

Create a DataReader for a ContentFilteredTopic.

This DataReader will only receive that data that mathes the Filter associated with the ContentFilteredTopic. The QoS will be set to sub.default_datareader_qos().

Parameters
subthe subscriber owning this DataReader.
topicthe content filtered topic.

◆ DataReader() [4/4]

template<typename T , template< typename Q > class DELEGATE>
dds::sub::DataReader< T, DELEGATE >::DataReader ( const dds::sub::Subscriber sub,
const dds::topic::ContentFilteredTopic< T > &  topic,
const dds::sub::qos::DataReaderQos qos,
dds::sub::DataReaderListener< T > *  listener = NULL,
const dds::core::status::StatusMask mask = dds::core::status::StatusMask::none() 
)

Create a DataReader for a ContentFilteredTopic.

This DataReader will only receive that data that mathes the Filter associated with the ContentFilteredTopic.

Parameters
subthe subscriber owning this DataReader.
topicthe content filtered topic.
qosthe QoS settings for this DataReader.
listenerthe listener.
maskthe event mask associated to the DataReader listener.

Member Function Documentation

◆ default_filter_state()

template<typename T , template< typename Q > class DELEGATE>
DataReader< T, DELEGATE > & dds::sub::DataReader< T, DELEGATE >::default_filter_state ( const dds::sub::status::DataState state)

Set the default state filter for read/take operations.

Parameters
statethe state mask that will be used to read/take samples.

◆ key_value() [1/2]

template<typename T , template< typename Q > class DELEGATE>
dds::topic::TopicInstance< T > dds::sub::DataReader< T, DELEGATE >::key_value ( const dds::core::InstanceHandle h)

This operation can be used to retrieve the instance key that corresponds to an instance_handle.

The operation will only fill the fields that form the key inside the key_holder instance. This operation may raise a BadParameter exception if the InstanceHandle does not correspond to an existing data-object known to the DataWriter. If the implementation is not able to check invalid handles, then the result in this situation is unspecified.

◆ key_value() [2/2]

template<typename T , template< typename Q > class DELEGATE>
T & dds::sub::DataReader< T, DELEGATE >::key_value ( T &  sample,
const dds::core::InstanceHandle h 
)

This operation can be used to retrieve the instance key that corresponds to an instance_handle.

The operation will only fill the fields that form the key inside the key_holder instance. This operation may raise a BadParameter exception if the InstanceHandle does not correspond to an existing data-object known to the DataWriter. If the implementation is not able to check invalid handles, then the result in this situation is unspecified.

◆ listener()

template<typename T , template< typename Q > class DELEGATE>
void dds::sub::DataReader< T, DELEGATE >::listener ( Listener the_listener,
const dds::core::status::StatusMask event_mask 
)

Set/Re-set the listener associated with this reader.

Parameters
the_listenerthe listener.
event_maskthe event mask associated with the listener.

◆ lookup_instance()

template<typename T , template< typename Q > class DELEGATE>
const dds::core::InstanceHandle dds::sub::DataReader< T, DELEGATE >::lookup_instance ( const T &  key) const

This operation takes as a parameter an instance and returns a handle that can be used in subsequent operations that accept an instance handle as an argument.

The instance parameter is only used for the purpose of examining the fields that define the key. This operation does not register the instance in question. If the instance has not been previously registered, or if for any other reason the Service is unable to provide an instance handle, the Service will return a TopicInstance whose handle will be set to the HANDLE_NIL value.

◆ operator>>() [1/4]

template<typename T , template< typename Q > class DELEGATE>
DataReader< T, DELEGATE > & dds::sub::DataReader< T, DELEGATE >::operator>> ( dds::sub::qos::DataReaderQos qos)

Gets the DataReaderQos setting for this instance.

Returns
the qos
Exceptions
dds::core::ErrorAn internal error has occurred.
dds::core::NullReferenceErrorThe entity was not properly created and references to dds::core::null.
dds::core::AlreadyClosedErrorThe entity has already been closed.
dds::core::OutOfResourcesErrorThe Data Distribution Service ran out of resources to complete this operation.

◆ operator>>() [2/4]

template<typename T , template< typename Q > class DELEGATE>
DataReader< T, DELEGATE > & dds::sub::DataReader< T, DELEGATE >::operator>> ( dds::sub::LoanedSamples< T > &  ls)

This stream operator willl take samples and add them to the LoanedSamples container.

For example:

dr >> loanedSamples; // this will 'take' the samples

In order to 'read' the samples instead of 'take', use the 'dds::sub::read' stream manipulator. For example:

dr >> dds:sub::read >> loanedSamples;

◆ operator>>() [3/4]

template<typename T , template< typename Q > class DELEGATE>
DataReader< T, DELEGATE >::ManipulatorSelector dds::sub::DataReader< T, DELEGATE >::operator>> ( ManipulatorSelector manipulator)(ManipulatorSelector &)

Manipulators are defined externally to make it possible to control whether the streaming operators reads or takes.

For example:

dr >> dds::sub::read >> loanedSamples;
// or,
dr >> dds::sub::take >> loanedSamples;

Without a 'dds::sub::read' or 'dds::sub::take' manipulator, the default operation is 'take'.

Parameters
manipulatorEither 'read' or 'take'

◆ operator>>() [4/4]

template<typename T , template< typename Q > class DELEGATE>
template<typename Functor >
DataReader< T, DELEGATE >::ManipulatorSelector dds::sub::DataReader< T, DELEGATE >::operator>> ( Functor  f)

Use this stream operator to control the behavior of the read or take streaming operation.

This supports the application of the following defined ManipulatorSelectors:

For example:

// take at most 10 samples into loanedSamples:
dr >> dds::sub::max_samples(10) >> loanedSamples;
// take all 'alive' samples into loanedSamples:

◆ read() [1/3]

template<typename T , template< typename Q > class DELEGATE>
LoanedSamples< T > dds::sub::DataReader< T, DELEGATE >::read ( )

Read all samples using the default filter state.

The memory used for storing the sample may be loaned by the middleware thus allowing zero copy operations. Implementation should strive to make this read implementation exception safe.

◆ read() [2/3]

template<typename T , template< typename Q > class DELEGATE>
template<typename SamplesFWIterator >
uint32_t dds::sub::DataReader< T, DELEGATE >::read ( SamplesFWIterator  sfit,
uint32_t  max_samples 
)

Read up to max_samples samples using the default filter state.

The samples are copied into the application provided container using the forward iterator parameter.

Parameters
sfitsamples forward iterator
max_samplesthe maximum number of samples to read
Returns
the number of read samples.

◆ read() [3/3]

template<typename T , template< typename Q > class DELEGATE>
template<typename SamplesBIIterator >
uint32_t dds::sub::DataReader< T, DELEGATE >::read ( SamplesBIIterator  sbit)

Read all samples available in the reader cache using the default filter state.

The samples are copied into the application provided container using a back-inserting iterator. Notice that as a consequence of using a back-inserting iterator, this operation may allocate memory to resize the underlying container.

Parameters
sbitsamples back-inserting iterator.
Returns
the number of read samples.

◆ select()

template<typename T , template< typename Q > class DELEGATE>
DataReader< T, DELEGATE >::Selector dds::sub::DataReader< T, DELEGATE >::select ( )

Get a Selector to perform complex data selections, such as per-instance selection, content and status filtering.

The selector can be used as follows:

         dr.select()
           .instance(handle)
           .content(query)
           .state(state)
           .take(sbit);
 

This shows how samples can be taken by selecting a specific instance, then filtering by state and content.

◆ take() [1/3]

template<typename T , template< typename Q > class DELEGATE>
LoanedSamples< T > dds::sub::DataReader< T, DELEGATE >::take ( )

Take all samples using the default filter state.

The memory used for storing the sample may be loaned by the middleware thus allowing zero copy operations. Implementation should strive to make this read implementation exception safe.

◆ take() [2/3]

template<typename T , template< typename Q > class DELEGATE>
template<typename SamplesFWIterator >
uint32_t dds::sub::DataReader< T, DELEGATE >::take ( SamplesFWIterator  sfit,
uint32_t  max_samples 
)

Take up to max_samples samples using the default filter state.

The samples are copied into the application provided container using the forward iterator parameter.

Parameters
sfitsamples forward iterator.
max_samplesthe maximum number of samples to take.
Returns
the number of taken samples.

◆ take() [3/3]

template<typename T , template< typename Q > class DELEGATE>
template<typename SamplesBIIterator >
uint32_t dds::sub::DataReader< T, DELEGATE >::take ( SamplesBIIterator  sbit)

Take all samples available in the reader cache samples using the default filter state.

The samples are copied into the application provided container using a back-inserting iterator. Notice that as a consequence of using a back-inserting iterator, this operation may allocate memory to resize the underlying container.

Parameters
sbitsamples back-inserting iterator.
Returns
the number of taken samples.

© 2009-2020 Twin Oaks Computing, Inc
Castle Rock, CO 80104
All rights reserved.