Defining const values in IDL file (for a struct)

2 posts / 0 new
Last post
frgo's picture
Last seen: 5 years 11 months ago
Joined: 12/28/2011
Posts: 20
Defining const values in IDL file (for a struct)

Hi all!

I am trying to put a const definition for a struct in my IDL file as follows:

struct Text {   string uuid;   string value;   string encoding;   string langCode; };

const Text TEXT_DE_GREEN = { "3990884B-30EC-44B7-976C-7E6BFAF8D125", "grün", "UTF8", "DE" };

This fails with: 

++ rtiddsgen -verbosity 3 -namespace -replace -sharedLib -notypecode -unboundedSupport -d . -inputIdl sysrme.idl

INFO com.rti.ndds.nddsgen.Main Running rtiddsgen version 2.3.0, please wait ...

ERROR sysrme.idl line 146:45 no viable alternative at input '{'

So, obvious question: How to define values in IDL files for structs? Thx!



Gerardo Pardo's picture
Last seen: 1 month 1 week ago
Joined: 06/02/2010
Posts: 601


Unfortunately IDL does not support initialization of structures or complex types. Only of primitive types. So I do not think there is a way to do this. 

The problem is that this is fairly complicated, specially if you get into nested structures and structures of sequences,etc. Also it is not uniformly supported by the different programming languages so IDL chose to not define this type of initialization syntax.

The closest I can think of would be to define individual constants for each member:

const string Text_uuid = "3990884B-30EC-44B7-976C-7E6BFAF8D125";
const string Text_value = "grün";
const string Text_encoding = "UTF8";
const string Text_langCode = "DE";

And use these constants in your own code to initialize some constant objects.