How to generate scoped enums with rtiddsgen

6 posts / 0 new
Last post
Offline
Last seen: 4 years 2 weeks ago
Joined: 10/15/2020
Posts: 3
How to generate scoped enums with rtiddsgen

Hi there

I've been having issues with name conflicts between two different enums that are trying to use the same name. Unfortunately, it does not seem feasible in this case to be able to change either of the names to resolve the conflict. I believe the modern C++ generation using the -language C++11 option is supposed to address this by avoidding name conflicts?

However when I try to use that option, it still seems to have issues with successfullly building a static lib in VS from the generated code. From what I can see it doesn't seem to be using any form of scoped enums. Is there some way to address the issue that I'm missing or would the only possible way of addressing it be to manualy edit the files? Apologies if there is an obvious answer; I still am quite new to using DDS.

Thanks in advance for the help

Dylan

Offline
Last seen: 4 years 2 weeks ago
Joined: 10/15/2020
Posts: 3

I'm not sure if it's relevant, but for further context these are both enums within the same topic.

Offline
Last seen: 1 month 5 days ago
Joined: 04/02/2013
Posts: 196

Hi Dylan,

When you generate code for modern C++, enums are scoped (via dds::core::safe_enum). This approach is changing in the upcoming Connext DDS version -- rtiddsgen will generate "enum class" for language C++11.

Alex

Offline
Last seen: 4 years 3 weeks ago
Joined: 11/20/2018
Posts: 2

Hello Dylan,

I think the Code Generator option you need is "-qualifiedEnumerator". This option uses the fully qualified name for enumerator values including the enum value.

For example, if your IDL would look like this:

enum Color {RED,BLUE};
enum MyColor {RED,BLUE};
 
The generated code for traditional C++ when using the "-qualifiedEnumerator" option will be:
typedef enum Color
{
    Color_RED ,
    Color_BLUE
} Color;
...
typedef enum MyColor
{
    MyColor_RED ,
    MyColor_BLUE
} MyColor;

Which should solve your problems with the colliding names.

Regards,

Miguel

Offline
Last seen: 1 month 5 days ago
Joined: 04/02/2013
Posts: 196

Note that "-qualifiedEnumerator" doesn't apply to -language C++11

Offline
Last seen: 4 years 2 weeks ago
Joined: 10/15/2020
Posts: 3

Perfect! I think the qualified enumerator happens to work better for my purposes but both of these helped address the naming conflicts. Thanks so much!