getting members of nested structure data

8 posts / 0 new
Last post
Offline
Last seen: 8 years 1 week ago
Joined: 08/17/2011
Posts: 7
getting members of nested structure data

Hello;

is there any way DDS:DynamicData::print()'s output to write on a file ?

If no, how can i get nested structured members ?

Best regardes ...

rose's picture
Offline
Last seen: 1 week 2 days ago
Joined: 08/22/2011
Posts: 146

Hello Oruc,

 

I do not know if you can change the print to redirect to a file.  However, if you want/need to access the nested structures within a DynamicData object, there are two ways to access a these nested types:

 

1. get_complex_member: 

This copies the nested DynamicData structure into the DynamicData structure passed in.  If you use this, setting the field values of the copy will not affect the original object.

 

2. bind_complex_member/unbind_complex_member: 

This allows you to bind a DynamicData type to a complex member field of the outer DynamicData type, without copying the object (which makes this more efficient).  This is required if you are going to modify the value of the original field.  this will fail if the DynamicData type passed in is already bound to a type.

 

Thank you,

Rose

Offline
Last seen: 8 years 1 week ago
Joined: 08/17/2011
Posts: 7

Hello Rose,

thank you for your reply but I have already tried this options. I will give you an example bellow to make you understand on this isue.

 

myStruct is like this :

struct nested {

long a;

wstring b ;

.

.

.

 

};

 

typedef sequence<nested,10> nestedlist;

 

struct mystruct{

long no;

nestedlist list;

};

 

I can access nested structre if sequence didn't use .

Now, do you have an idea how to access sequence's elemans?

 

 

Thank you,

         Oruc,

 

rose's picture
Offline
Last seen: 1 week 2 days ago
Joined: 08/22/2011
Posts: 146

Hello Oruc,

 

I have done something similar to you, but without typedef'ing the sequence.  I first bind to the sequence itself, and call get_info.  This gives me the length of the sequence, so I can iterate over it.

 

Now you can bind to the individual elements in the sequence by their ID numbers.  The important thing to note is that when you bind the element in the sequence, the ID is 1-based.  

 

Does this still work when the sequence is typedef'd?

 

Thank you,

Rose

 

struct nested { … };

struct mystruct {

Sequence<nested> nestedSeq;

};

 

 

       // Create DynamicData types for mystruct_dynamic_data, nested_sequence, and nested_struct.

       // For nested_sequence & nested_struct, pass in NULL to constructors to leave them unbound 

DDS_DynamicData mystruct_dynamic_data(mystructTypeCode, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

DDS_DynamicData nested_sequence(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

DDS_DynamicData nested_struct(NULL, DDS_DYNAMIC_DATA_PROPERTY_DEFAULT);

 
       
         // Use this to get the length of the sequence

DDS_DynamicDataInfo nested_sequence_info;

 

// Bind the nested_sequence DynamicData to the nested sequence within the mystruct_dynamic_data

mystruct_dynamic_data.bind_complex_member(nested_sequence, "nestedSeq”,

DDS_DYNAMIC_DATA_MEMBER_ID_UNSPECIFIED);

 

// Get the length of the sequence

nested_sequence.get_info(nested_sequence_info);

// Bind the nested_struct to each entry in the sequence using the 1-based member ID

for (int j = 0; j < nested_sequence_info.member_count; j++) {

nested_sequence.bind_complex_member(nested_struct, NULL, j+1);

// Access the fields of the structure in the sequence...

}

Offline
Last seen: 8 years 1 week ago
Joined: 08/17/2011
Posts: 7

thank you so much. i am going to try that as soon as posible and make you know what if it is okey

regards..

Offline
Last seen: 8 years 1 week ago
Joined: 08/17/2011
Posts: 7

Hello Rose ,

i checked your suggestion but there is an difference between c#API and what you use. the bind_complex_member ()

 methot is not using as your usage on c # . on C#API the function like this;
 bind_complex_member (DynamicData^ value_out, System::String^ member_name, System::Int32 member_id)
(http://community.rti.com/docs/html/api_dotnet/classDDS_1_1DynamicData.html you can check it from here)

so  i need to give member_name  and member_id as parameter . what is sequence's members name.? I donT thing they have a name so I connot get bind comlex member.  do you have an idea what can I do to get bind complex member ?

thanks ,

Best Regardes,

Oruc

rose's picture
Offline
Last seen: 1 week 2 days ago
Joined: 08/22/2011
Posts: 146

Hello Oruc,

 

I think the API is very similar -- the C++ API also takes a name, and for the sequence you pass in null to look up the member by ID.  Does that work?

 

Thank you,

Rose

Offline
Last seen: 8 years 1 week ago
Joined: 08/17/2011
Posts: 7

thank you,

this problem is solved .