How do I use keys when using a union?
In general, rtiddsgen only recognizes keys in the outermost structure. To consider the keys in embedded structures, the outer member needs to be a key as well.
In the example below, rtiddsgen will not recognize mykey
as a key for union A
, struct B
, or struct C
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | struct D { long mykey; //@key long other; }; struct B { D d; }; struct C { D d; }; union A switch ( long ) { case 0: struct B b; case 1: struct C c; }; |
You can choose to leave B
and C
as unkeyed types or mark their member d
as a key. In that case, mykey
will be the key.
However, as per the DDS-XTypes standard, unions don't support keys. You can define a new struct that contains A
and move mykey
there. For example:
1 2 3 4 | struct MyType { long mykey; //@key A a; }; |
If you must also keep mykey
in D
, then your application will have to assign MyType.mykey
to a.b.d.mykey
or a.c.d.mykey
(depending on the key discriminator of a
).