Unions and filters

3 posts / 0 new
Last post
Offline
Last seen: 2 years 9 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,

Andreas

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

Hi Andreas,

Are you talking about something like this?

 enum my_enum {
 BLUE,
 GREEN,
 YELLOW,
 RED      
};


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");
        subscriber_shutdown(participant);
        return -1;
    }

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

Thanks,

Juanjo Martin

Offline
Last seen: 2 years 9 months ago
Joined: 09/17/2015
Posts: 53

Great, that was easy. Thank you!