Name conflict between XML and Modern C++

7 posts / 0 new
Last post
Offline
Last seen: 3 years 4 days ago
Joined: 05/08/2017
Posts: 5
Name conflict between XML and Modern C++

Hi, I have an IDL we use that looks like:

struct Test {
  string<128> _alias;
};

Which generates modern C++ with:

class NDDSUSERDllExport Test {

    // ...

    std::string& alias() OMG_NOEXCEPT {
        return m_alias_;
    }

    const std::string& alias() const OMG_NOEXCEPT {
        return m_alias_;
    }

    void alias(const std::string& value) {
        m_alias_ = value;
    }
};

Except, the XML rtiddsgen generates looks like:

<struct name= "ComponentCtlParamsT">
  <member name="_alias" stringMaxLength="128" type="string" key="true"/>
</struct>

Which means that using the Python Connector and a code app have a disagreement and won't connect.

I've tried using @id and @hashid, but because the names don't match and we don't have ignore_member_names in our policy, nor would we, as then it'd cause other issues.

What can I do?

Organization:
Keywords:
Offline
Last seen: 2 months 2 weeks ago
Joined: 04/02/2013
Posts: 194

As you can see the Code Generator ignores underscores before an identifier, as the IDL specification requires, but it incorrectly keeps it in the XML file. Can you define your type without the "_"? "string<128> alias;" ?

Offline
Last seen: 2 months 2 weeks ago
Joined: 04/02/2013
Posts: 194

Looking at the way the C++ type is generated, even though the C++ class has "alias" as the member name, the TypeCode that is used for matching with other applications uses "_alias", so in theory Connector and the C++ app should communicate. Can you run the C++ application with warning verbosity to determine exactly why the types don't match?

Offline
Last seen: 3 years 4 days ago
Joined: 05/08/2017
Posts: 5

Using the RTIAdminConsole, it shows as a "Name Mismatch". If I hand-edit the XML rtiddsgen generates to use "alias", it works fine. Examining the DDS Type in the console shows the name as "alias", which makes sense because in the .cxx it has this as well:

static DDS_TypeCode_Member Test_g_tc_members[4]=
 {
                        (char *)"alias",/* Member name */

 

This is using 6.0.1, btw.

Here are the arguments we're passing to rtiddsgen:

rtiddsgen -enableEscapeChar -replace -language C++11 -verbosity 2 -stl -d <outdir> -I <srcDir> <idl>

rtiddsgen -replace -convertToXml -verbosity 2 -d <outdir> -I <srcDir> <idl>

Offline
Last seen: 3 years 4 days ago
Joined: 05/08/2017
Posts: 5

FWIW I've temporarily added a sed step to strip out the first preceeding underscore so the generated XML matches the generated code, and they'll communicate.

Offline
Last seen: 2 months 2 weeks ago
Joined: 04/02/2013
Posts: 194

I didn't realize you were using "-enableEscapeChar". Use that same option in the second call to rtiddsgen.

Offline
Last seen: 3 years 4 days ago
Joined: 05/08/2017
Posts: 5

Well, adding that did fix it, though it feels kind of... backwards that it did so. After staring at the documentation, I get it, but it's not clear why.

-enableEscapeChar: Enables use of the escape character '_' in IDL identifiers. With CORBA this option is always enabled.

Anyhow, thanks!