Setting discriminator in Python for member with multiple discriminators

3 posts / 0 new
Last post
Offline
Last seen: 1 year 10 months ago
Joined: 06/03/2022
Posts: 2
Setting discriminator in Python for member with multiple discriminators

Using RTI Connector for Python.

On the output instance, is it possible to explicitly set a union discriminator?

I have a union with 2 members, where each member is associated with 2 discriminators.  The default/first discriminator is always set on the various set_ calls.

The <types> below is contrived, but illustrates the situation.

Is it possible to set "struct_cd.cd" with the discriminator set to "D" rather than "C"?

 

<?xml version="1.0" encoding="UTF-8"?>
<types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:////opt/rti_connext_dds-6.0.1/bin/../resource/app/app_support/rtiddsgen/schema/rti_dds_topic_types.xsd">
<enum name="EDiscrim">
  <enumerator name="A"/>
  <enumerator name="B"/>
  <enumerator name="C"/>
  <enumerator name="D"/>
</enum>
<struct name= "StructAB">
  <member name="ab" type="int32"/>
</struct>
<struct name= "StructCD">
  <member name="cd" type="float32"/>
</struct>
<union name="MyUnion">
<discriminator type="nonBasic" nonBasicTypeName="EDiscrim"/>
<case>
  <caseDiscriminator value="(A)"/>
<caseDiscriminator value="(B)"/>
<member name="struct_ab" type="nonBasic"  nonBasicTypeName= "StructAB"/>
</case>
<case>
  <caseDiscriminator value="(C)"/>
<caseDiscriminator value="(D)"/>
<member name="struct_cd" type="nonBasic"  nonBasicTypeName= "StructCD"/>
</case>
</union>
</types>
Offline
Last seen: 2 months 1 week ago
Joined: 10/22/2018
Posts: 91

The member in a union is automatically selected when you set it.

See this part of the documentation.

 

Sam

Offline
Last seen: 1 year 10 months ago
Joined: 06/03/2022
Posts: 2

My reply did not get through...

The issue is that there is no apparent way to set the discriminator when multiple are associated with a union member.  It just sets the default.

The Modern C++ API behaves similarly on setter functions, but you can work around it by setting _d and using reference returning member functions to set data members.

In the original example, the discriminator will alway be either "A" or "C".  There is no way to set it to "B" or "D".