<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=135637837074656&amp;ev=PageView&amp;noscript=1">

Code Generator: Experiment with New Features

September 2, 2015 by
|

In previous posts we explained how RTI’s new code generator saves you time with faster code generation. It’s now the default code generator in RTI Connext DDS 5.2.0, and it includes a number of other new features we think you will like.

Did you know that our new code generator is much better at detecting syntax errors?

For instance, the code generator will tell you if you forgot to define a type, showing better error messages. And this is just one example.

Do you want to generate only the type files and your project files without overwriting your publisher/subscriber files?

Try the autoGenFiles option.

Do you want even more control over which files you generate?

The new create and update <typefiles | examplefiles | makefiles> options are your solution.

Are you compiling dynamically?

Generate your project files using the shareLib option. It will link your application with RTI’s core dynamic libraries.

Do you want to share private IDLs without showing their actual content?

Try the new obfuscate option.

Are you using unbounded sequences?

Try the unboundedSupport option. Read this blog post to learn more about this new feature.

It’s all easier than ever with the Apache Velocity (VLT) templates. You can check the predefined set of variables available in RTI_rtiddsgen_template_variables.xlsx, located in the Code Generator documentation folder.

As a simple example, imagine you want to generate a new method that prints whether each member of a type is an array or a sequence. It could also print the corresponding dimensions or size. For example, consider this type:

module Mymodule{
    struct MyStruct{
        long longMember;
        long arrayMember [2][100];
        sequence sequenceMember;
        sequence arrayOfSequenceMember[28];
    };
};

Our desired print function would be something like this:

void MyModule_MyStruct_specialPrint(){
    printf(" longMember \n");
    printf(" arrayMember is an array [2, 100] \n ");
    printf(" sequenceMember is a sequence <2> \n");
    printf(" arrayOfSequenceMember is an array [28] is a sequence <5> ");
}

Implementing this is straightforward. You would just need to create a few macros in the code generator templates to generate the above code. We start with the main method, which would be something like this:

void ${node.nativeFQName}_specialPrint(){
    #specialPrint ($node)
}

This method calls to specialPrint macro. That macro iterates within the struct members and print whether they are an array or a sequence

#macro (specialPrint $node)
#*--*##foreach($member in $node.memberFieldMapList)
print("$member.name #isAnArray($member) #isASeq($member) \n");
#*--*##end

We just need to define two auxiliary macros to check each case.

#macro (isAnArray $member)
#if($member.dimensionList) is an array $member.dimensionList #end
#end
#macro (isASeq $member)
#if($member.seqSize) is a sequence &lt;$member.seqSize&gt; #end
#end

If you need more information about supported and new features available in Code Generator, check out the Getting Started Guide or the online documentation.

you might also be interested in

Let Us Know What You Thought of the Article.

Leave a Comment Below.

Latest Resource

Resource-ebook
Download Now

Subscribe to Email Updates