Given the following IDL:
typedef sequence<int> z_type;
typedef sequence<z_type> y_type;
typedef sequence<y_type> x_type;
How does one initialise the size of each dimension to store the equivalent of a 3D array, eg [3][4][5].
How does one access cells within the sequence, i.e. x = fooSeq[1][1][1]?
Regards John
Hi John,
Any programming language of choice? I'll provide answers with the C API, as any other language will be just easier and more comfortable.
This page shows the reference API for generated sequences. The
FooSeq_ensure_length()
method will set the sequence's length to your length of choice. It will resize the sequence if necessary to hold enough samples. Once you do that for the outer sequence, you can do the same for the inner sequences. To get a reference to the i-th member in the sequence you can use theFooSeq_get_reference()
method. Snippet of C code, showing the initialisation and then the access.Thanks for the response Juan.
I forgot to mention I'm wrting C++ code and using the ndds_cpp.h file.
Prior to receiving your response I modified my IDL code to introduce intermediate structures as illustrated below. However from your response I guess I just start with the outermost sequence and allocate storage as we travel to the innermost sequence.
I'm also curious about the need for DDS_SEQUENCE_INITIALIZER. Can I assume it is not required for C++?
Hi John,
Yes, you don't need the DDS_SEQUENCE_INITIALIZER constant for the C++ language (or any other than C). The pattern you mention is the correct one, allocate sequence memory from the outermost sequence to the innermost one.
Thanks,
Juanlu
may be related. i want to define a 2 dimensional dynamic sequence in my IDL, of type <string[1024], EnumerationType>
i can get through the rtiddsgen but i get compile errors in the generated code. i'm using .NET
Jay,
could you post the idl and the errors you get so we can try to reproduce it?
Cheers,
Gianpiero