get a field of primitive type as a DynamicData instance

2 posts / 0 new
Last post
Offline
Last seen: 1 year 3 months ago
Joined: 03/02/2022
Posts: 1
get a field of primitive type as a DynamicData instance

I'm trying to add the following functionality to my app: with knowledge of a DynamicType, it parses any field at any depth of a DynamicData instance of that type. For example, I have the following idl:

struct Point {

  double x;

  double y;

};

struct Odometry {

  Point point;

};

struct Location {

  Odometry odometry;

};

WIth a DynamicData sample of type Location, I would like to get the value of  sample.odometry, sample.odometry.point or sample.odometry.point.x as requested by the user. I'm able to solve part of the problem using the "value" api of DynamicData.

 

auto data0 = sample.value<DynamicData>("odometry"); 

auto data1 = sample.value<DynamicData>("odometry.point");

 

However, this no longer works when it comes to primitive types:  

auto data0 = sample.value<DynamicData>("odometry.point.x"); //  runtime error

 

It seems that when I reach the deepest level, I can no longer treat the field as a DynamicData. Instead I have to use its "real" type, i.e. int. double or string.  What I want eventually is a function like this

DynamicData getField(const DynamicData& data, const std::vector<Field>& fields);

in which Field is the description of the field wanted by the user. If it's impossible to get a primitive field as a DynamicData, then this function signature becomes infeasible and I would have to write a wrapper class myself. So coming back to the question. how can I get a field of primitive type as a DynamicData instance?

 

Offline
Last seen: 1 year 6 months ago
Joined: 07/08/2021
Posts: 6

Hi,

Good afternoon! 

Is your goal just to retrieve the value of the primitive type? That would be quite trivial, and you will be able to do so as shown in the samples below:

https://community.rti.com/static/documentation/connext-dds/6.1.1/doc/api/connext_dds/api_cpp2/group__DDSXTypesExampleModule.html

Or is there any particular reason you would like to cast the primitive type as a DynamicData instance?

But anyway, I believe you are a customer with a support account and such questions can actually be directed to our support team and they will be best equipped to advise you on the proper API use.

You can contact me at zklim@rti.com to discuss this further as well.

Thanks!