TypeCode of sequences in dynamic data api

6 posts / 0 new
Last post
Offline
Last seen: 6 years 11 months ago
Joined: 04/28/2013
Posts: 38
TypeCode of sequences in dynamic data api

I was wondering if there's a way to get a typecode from a sequence dynamic data object that's empty.

For example, I create a new DynamicData object with DynamicData(TypeCode, DynamicDataProperty_t) but all sequences are created with size 0, and I'd like to add sequence members. The problem is, that I need to know the typecode of the inner members of the sequence, in order to create them.

Is there a way to get that typecode without actually having any members?

 

Offline
Last seen: 3 years 9 months ago
Joined: 01/15/2013
Posts: 94

Hi Michael,

You can always use the methods:

DDS_DynamicData::get_type() 
DDS_DynamicData::get_type_kind()

to access the type information associated with a DynamicData sample.

However, you don't explicitly need to know the type-code of the sequece in order to set its elements. Using the Dynamic Data API for sequences is almost like using it for structured types.

You can do 

 DDS_DynamicData::bind_complex_member() 

with a sequence type, just as you would do with a structured type (e.g. struct).Also take into account that you can do:

 DDS_DynamicData::get_member_info_by_index()

to obtain the member information, which should provide you with the kind of element contained by the sequence

When accessing sequence elements, remember that the members have to be accessed by ID (they don't have names), and that the member IDs index the sequence starting with 1. For example, to access member index 0 in the sequence, you use member ID 1; to access member index 5 in the sequence, you use member ID 6. So if you have a sequence of primitive types, you could call

  DDS_DynamicData::set_(NULL /* no member name */, 6 /* this would set the member in the sequence index 5 */, value /* the primitive type value */);

You could also set arrays of primitive types and sequences of primitive types directly using the convenience methods:

 DDS_DynamicData::set__array() or DDS_DynamicData::set__seq()

If your sequence contained structured types, like structs or unions, then you could bind them normally by using the indexing schema I mentioned above:

 DDS_DynamicData::bind_complex_member(dynamicDataOut /* the reference to the outgoing DynamicData sample to be bound */, NULL /* no member name */, 6 /* to access member index 5 */);

Then you can process every complex member in the sequence separately. It's important to call

 DDS_DynamicData::unbind_complex_member()

every time you finish processing a complex member.

I hope this helps, let me know if you have any more doubts.

Thanks,

Juanlu

Offline
Last seen: 6 years 11 months ago
Joined: 04/28/2013
Posts: 38

Hi Juanlu,

I'm doing all of the above to go over the DynamicData members but I reach a point where I have a dynamic data that:

data.get_type_kind() is TK_SEQUENCE

data.get_type() is null

data.get_member_count() is 0

At this point, I cant call get_member_info_by_index as there are no members (the sequence is empty), yet I'd like to create new members, but I need to know the typecode of the underlying sequence members, but I don't actually have any to bind them and call get_type().

Is there a way to get the typecode without actually having any members to bind?

Thanks,

Michael

Offline
Last seen: 3 years 9 months ago
Joined: 01/15/2013
Posts: 94

Hi Michael,

If you have the type-code of the parent type then you can navigate the type-code as much as you can navigate the DynamicData information. With the parent type-code, method

 DDS_TypeCode::content_type()

will give you the type of the contained elements in the sequence. Have you tried this approach? I don't know if you're traversing the type-code structure as you traverse the DynamicData sample.

Thanks,

Juanlu

Offline
Last seen: 6 years 11 months ago
Joined: 04/28/2013
Posts: 38

Hi Juanlu,

Using the parent type code indeed solved the problem

Thanks a lot!

Michael

Offline
Last seen: 3 years 9 months ago
Joined: 01/15/2013
Posts: 94

No worries! Glad I could help.

Juanlu