Unions and filters

3 posts / 0 new
Last post
Last seen: 6 years 8 months ago
Joined: 09/17/2015
Posts: 53
Unions and filters

Hello all,

How can I filter unions based on the data embedded?

I mean there is an enum integrated in the union telling me which data is stored. This enum I can access in C++.

But how do I create for example a content filtered topic based on this internal enum?

Best regards,


Juanjo Martin's picture
Last seen: 1 year 11 months ago
Joined: 07/23/2012
Posts: 48

Hi Andreas,

Are you talking about something like this?

 enum my_enum {

union my_union switch(my_enum) {

case BLUE  : long blue_value;

case GREEN  : long green_value;

case YELLOW  : long yellow_value;

case RED  : long  red_value;	

	default : long nothing;


If this is your case, I was able to create a CFT based on the example provided in the community. Just try this:

    DDS_StringSeq parameters(1);
    const char* param_list[] = {"1"};
    parameters.from_array(param_list, 1);
    DDSContentFilteredTopic *cft = NULL;
    cft = participant->create_contentfilteredtopic(
        "ContentFilteredTopic", topic, "(_d = %0)", parameters);
    if (cft == NULL) {
        printf("create_contentfilteredtopic error\n");
        return -1;

Note that _d refers to the discriminator, which in this case is the enum value (that can be filtered as an int).


Juanjo Martin

Last seen: 6 years 8 months ago
Joined: 09/17/2015
Posts: 53

Great, that was easy. Thank you!