5. MATLAB without IDL

It is possible, but not recommended, to directly create MATLAB classes that represent DDS topics. This approach allows you to quickly start using Vortex DDS, but it has a number of disadvantages:

  • without IDL, you cannot reliably define the topic in other language bindings.

  • not all IDL types are available.

5.1. Creating a MATLAB Topic class

To create a Topic Class without IDL, create a MATLAB class that inherits from Vortex.AbstractType. The class will be interpreted as an IDL struct. Class properties will be interpreted as IDL struct fields. Finally, the class must define a static method getKey which returns a comma separated list of key fields for the topic.

The following shows a simple MATLAB class, ShapeType:

classdef ShapeType < Vortex.AbstractType
    properties
        color     char  % IDL: string color;
        x         int32 % IDL: long x;
        y         int32 % IDL: long y;
        shapesize int32 % IDL: long shapesize;
    end

    methods (Static)
        function keys = getKey
            keys = 'color';
        end
    end
end

The topic class defines four fields, and identifies the color field as the topic key.

You would use the topic class in the same way as one generated by IDLPP. The following example shows the creation of a DDS topic object from a topic class:

% define a Vortex DDS topic called 'Circle'
circleTopic = Vortex.Topic('Circle', ?ShapeType);

With the circleTopic variable, you can then create appropriate Vortex DDS readers and writers.

5.2. Mapping of MATLAB types to IDL types

When using an IDL-less Topic class, the Vortex DDS API for MATLAB makes maps property types to IDL types as follows:

MATLAB Type

IDL Type

logical

boolean

int8

char

uint8

octet

int16

short

uint16

unsigned short

int32

long

uint32

unsigned long

int64

long long

uint64

unsigned long long

single

float

double

double

char

string

class

equivalent IDL struct

enum class

equivalent IDL enum

not type

double

5.3. Creating arrays

When defining a topic class, you can make a field map to an IDL array by initializing it to an array of the appropriate dimensions. The MATLAB API for Vortex DDS recognizes arrays of most types as identifying IDL arrays. The one exception is that arrays of MATLAB char are still interpreted as an IDL string.

The following example shows an topic class that defines arrays:

classdef ArrayTopic < Vortex.AbstractType
    properties
        x = zeros([1 4])        %IDL: double x[4];
        y int32 = zeros([3 4])  %IDL: long y[3][4];
    end
    methods (Static)
        function keys = getKey
            keys = ''; %No Key
        end
    end
end

5.4. Unsupported Types

When creating topics with out IDL, you must accept the following restrictions:

  • IDL sequences cannot be defined.

  • arrays of IDL strings cannot be defined.

  • bounded IDL strings cannot be defined.