how to set and get value of optional members?

4 posts / 0 new
Last post
Offline
Last seen: 2 days 11 hours ago
Joined: 01/13/2016
Posts: 58
how to set and get value of optional members?

Hi, everyone

I have a idl defined like this:

struct StdEntity

{

    boolean valid; //@Optional

    char id[20];

    long type[100]; //@Optional

    double val[1500]; 

};

the member valid and val does not transfer every time, so i want known that how to set and get value for these optional members.

thanks for any help

Keywords:
Offline
Last seen: 2 days 11 hours ago
Joined: 01/13/2016
Posts: 58

My program is developed using C++ language, and dds version 5.2.3.

Howard's picture
Offline
Last seen: 5 days 20 hours ago
Joined: 11/29/2012
Posts: 618

Are you using Modern C++ (aka C++03/C++11) or the Traditional C++ API (aka C++98)?

If using the Traditional C++ API, the IDL definition fundamentally maps into a class with publically accessible members of the type described in the IDL.  @optional members are mapped to pointers of the same type

e.g.

long type[100]; //@optional

is mapped to

long *type[100];

 

set the pointer to NULL to not send data for the array.  When received, you test to see if the pointer is NULL, if so, then it wasn't sent.  You can just check the header file that defines the data type for this.

 

If using Modern C++, then the type gets encasulated into a dds::optional object.  See the documentation here:

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

 

 

 

Offline
Last seen: 2 days 11 hours ago
Joined: 01/13/2016
Posts: 58

thanks, i got it,its turely a pointer.