In IDL, the module keyword is used to create namespaces for the declaration of types defined within the file.
Here is an example IDL definition:
module PackageName { struct Foo { long field; }; };
The name of the module is concatenated to the name of the structure to create the namespace. The resulting code looks like this:
typedef struct PackageName_Foo { DDS_Long field; } PackageName_Foo;
In the Traditional C++ API, when using the -namespace command-line option, RTI Code Generator generates a namespace, such as the following:
namespace PackageName{ class Foo { public: DDS_Long field; } }
Without the -namespace option, the mapping adds the module to the name of the class:
class PackageName_Foo { public: DDS_Long field; }
In the Modern C++ API, namespaces are always used.
Independently of the usage of the -namespace command-line option, RTI Code Generator generates a namespace, such as the following:
namespace PackageName{ public ref struct Foo: public DDS::ICopyable<Foo^> { public: System::Int32 field; }; }
A Foo.java file will be created in a directory called PackageName to use the equivalent concept as defined by Java. The file PackageName/Foo.java will contain a declaration of Foo class:
package PackageName; public class Foo { public int field; };
In a more complex example, consider the following IDL definition:
module PackageName { struct Bar { long field; }; struct Foo { Bar barField; }; };
When RTI Code Generator generates code for the above definition, it will resolve the Bar type to be within the scope of the PackageName module and automatically generate fully qualified type names.
typedef struct PackageName_Bar { DDS_Long field; } PackageName_Bar; typedef struct PackageName_Foo { PackageName_Bar barField; } PackageName_Foo;
With -namespace:
namespace PackageName { class Bar { public: DDS_Long field; }; class Foo { public: PackageName::Bar barField; }; };
Without -namespace:
class PackageName_Bar { public: DDS_Long field; }; class PackageName_Foo { public: PackageName_Bar barField; };
namespace PackageName{ public ref struct Bar: public DDS::ICopyable<Bar^> { public: System::Int32 field; }; public ref struct Foo: public DDS::ICopyable<Foo^> { public: PackageName::Bar^ barField; }; };
PackageName/Bar.java and PackageName/Foo.java would be created with the following code, respectively:
package PackageName; public class Bar { public int field; }; package PackageName; public class Foo { public PackageName.Bar barField = PackageName.Bar.create(); };
© 2015 RTI