Setting Default values to the struct variables in IDL file

7 posts / 0 new
Last post
Offline
Last seen: 2 years 9 months ago
Joined: 09/12/2014
Posts: 6
Setting Default values to the struct variables in IDL file

Hi just wondering if there is any way to set default values to the struct variables in IDL file?

Gerardo Pardo's picture
Offline
Last seen: 13 hours 58 min ago
Joined: 06/02/2010
Posts: 598

Hello,

No I am afraid this is not currently possible. However the just approved IDL 4.0 specification added an annotation @default intended to be used for this purpose. So if there is enough interest from the users we could pick this up and offer that feature. As of now this is not planned.

Regards,

Gerardo

Offline
Last seen: 1 month 2 days ago
Joined: 11/01/2021
Posts: 2

Since this was posted > 5 years ago - is there any update on this? - can we do default parameters in 2021? (Using RTI DDS 6.1.0)

Offline
Last seen: 2 hours 2 min ago
Joined: 11/16/2018
Posts: 7

This is supported in Connext 6.   I don't know, however, exactly when it was introduced.  

https://community.rti.com/static/documentation/connext-dds/6.1.0/doc/manuals/connext_dds_professional/extensible_types_guide/index.htm#extensible_types/DefaultValue.htm#[email protected]_annotation%3FTocPath%3D3.%2520Type%2520System%2520Enhancements%7C3.3%2520Default%2520Value%7C3.3.1%2520%2540default%2520annotation%7C_____0

Regards,

Bob

Offline
Last seen: 1 month 2 days ago
Joined: 11/01/2021
Posts: 2

ah thanks bobg - I had seen this feature, I think in my head I was expecting there to also be constructors that have default parameters as well so if you add a new parameter to a topic you don't need to update all the code that constructs that topic data... I Assume this is not available?

Offline
Last seen: 2 hours 2 min ago
Joined: 11/16/2018
Posts: 7

I don't think that's available.   It's a feature implemented within IDL which, of course, isn't really realized until you update/generate new support functions with rtiddsgen.

 

 

Howard's picture
Offline
Last seen: 21 hours 9 min ago
Joined: 11/29/2012
Posts: 285

Hmm, not sure what is meant by "adding a new parameter to a topic".  If you mean you modify the data type definition (used by a Topic) by adding/removing a member of the data type (which is usually done by modifying the IDL file containing your type definition), then as Bob wrote, you have to update the type support/plugin code that is generated using rtiddsgen on your idl file.

That's an independent concept than using @default annotations to provide default values for members of a datatype.

Using "@default" annotations, you can now define what the default values of members of a datatype are initialized to via the IDL definition file...and since adding/changing annotations in an IDl file is fundamentally changing a datatype definition, you have to regenerate the type source files using rtiddsgen as previously stated.

But, by doing so, depending on the programming language used, and if you use the "-constructor" argument for "-language C++", then the constructor for the datatype class...or using the <foo>TypeSupport::create_data() function, the object constructed/returned should have the members initialized with their specified default values.