Vector idl type

5 posts / 0 new
Last post
Offline
Last seen: 11 years 11 months ago
Joined: 01/04/2013
Posts: 2
Vector idl type

Hello!

I need to use a data structure with an array of variable dimension, (like a vector) in c++, defining it into my idl file. I've read the DDS guide and i've seen several types but i cannot find a solution to my problem.

Anyone can tell me if is possibile to create dynamica array??


Thanks a lot.

Gerardo Pardo's picture
Offline
Last seen: 1 week 1 day ago
Joined: 06/02/2010
Posts: 602

What you are looking for is called a "sequence" in IDL. It can have elements of any kind including primitive types and other structured types. For example:

struct Coordinate {
    float x;
    float y;
};

const long MAX_VERTICES = 32;
typedef  sequence<Coordinate, MAX_VERTICES> Poligon;

const long LABEL_MAX_LEN=128;
typedef string<LABEL_MAX_LEN> Label;

const long MAX_LONGS=1014;
const long MAX_POLIGONS = 100;
const long MAX_COORDINATES=1024;
const long MAX_LABELS=64;

struct StructWithSequences {
    sequence<long, MAX_LONGS>  longs;
    sequence<Coordinate, MAX_COORDINATES> coordinates;
    sequence<Poligon, MAX_POLIGONS> poligons;
    sequence<Label, MAX_LABELS> labels;
};
Gerardo
Offline
Last seen: 11 years 11 months ago
Joined: 01/04/2013
Posts: 2

Hi Gerardo Pardo, thanks for the useful reply! Now i can create a dynamic array!

Offline
Last seen: 11 years 4 weeks ago
Joined: 09/17/2013
Posts: 10

Hi guys,

I am kind of newbie in this DDS. What I am trying to do exactly what Gerardo has posted above, but it doesn't work for me. In detail, I shortened the IDL struct to be:

const long LABEL_MAX_LEN=128;
typedef string<LABEL_MAX_LEN> Label;

const long MAX_LABELS=64;

struct StructWithSequences {
    Label smaple_test;
    sequence<Label, MAX_LABELS> labels;
};

Just before to publish I can see that the labels array is filled with string values. In the QoS profile I have it set up to be TRANSIENT_DURABILITY_QOS. After I publish I can see that the sample_test variable is exactly what I published, but the labels array consists of 64 null values. So, all my string values disappeared somewhere on the way and they turned into null values. Again, pay attention on the fact that it is exactly the topic data that I published since the sample_test value is the one that I published, only the array values turn into nulls.

I appreciate any help, any comments.

Thanks in advance.

 

Gerardo Pardo's picture
Offline
Last seen: 1 week 1 day ago
Joined: 06/02/2010
Posts: 602

Hi,

My suspicion would be that you are not setting the maximum value or the length of the sequence correctly...  Which language are you using?

This DDS Sequences HOWTO may help:   http://community.rti.com/content/forum-topic/howto-use-omg-dds-sequences-c-rti-connext-dds  it explains in detail how to use sequences.

Gerardo