Using a Type-Specific DataReader (FooDataReader)

This section doesn't apply to the Modern C++ API, where a DataReader's data type is part of its template definition: DataReader<Foo>.

Using a Subscriber you will create a DataReader associating it with a specific data type, for example ‘Foo’. Note that the Subscriber’s create_datareader() method returns a generic DataReader. When your code is ready to access DDS data samples received for the DataReader, you must use type-specific operations associated with the FooDataReader, such as read() and take().

To cast the generic DataReader returned by create_datareader() into an object of type FooDataReader, you should use the type-safe narrow() method of the FooDataReader class. narrow() will make sure that the generic DataReader passed to it is indeed an object of the FooDataReader class before it makes the cast. Else, it will return NULL. Figure: Simple SubscriberListener shows an example:

Foo_reader = FooDataReader::narrow(reader);

DataReader Operations lists type-specific operations using a FooDataReader. Also listed are generic, non-type specific operations that can be performed using the base class object DDSDataReader (or DDS_DataReader in C). In C, you must pass a pointer to a DDS_DataReader to those generic functions.

© 2018 RTI