Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space IceMaster and version 3.7.1

Znav
nextMATLAB Mapping for Constants
prevMATLAB Mapping for Sequences

There are three different two mappings for a Slice dictionary, depending on its key and value type:

Maps to a handle type to support the Ice run time's unmarshaling requirements
Key TypeValue TypeMapped TypeComments
stringIntegral type (short, int, long), bool, byte, enum or numeric, stringAnycontainers.MapEnumeration keys must be converted to integers.
structAnyNative struct structure arraycontainers.Map does not support user-defined key types.structclassIce.StructArrayHandle.

The mapping generates a class with the same name as the dictionary. This class provides one useful function for applications: a new function that returns an empty instance of the mapped type.

...

Since the key is a primitive type, EmployeeMap maps to containers.Map. We can use it as shown below:

Code Block
languagematlab
titleMATLAB
em = EmployeeMapcontainers.new(Map('KeyType', 'int64', 'ValueType', 'any');
 
e = Employee();
e.number = 31;
e.firstName = 'James';
e.lastName = 'Gosling';
 
em(e.number) = e;

The new function is especially useful for dictionaries that map to containers.Map because this class must be constructed with the appropriate key and value types. For example, instead of calling EmployeeMap.new, we can manually construct containers.Map as follows:

Code Block
titleMATLAB
em = containers.Map('KeyType', 'int64', 'ValueType', 'any');

We recommend using the new function to reduce the possibility of run-time errors.

 

Ztop

The value for KeyType and ValueType depends on the corresponding Slice type as shown in the following table:

Slice TypeCorresponding KeyTypeCorresponding ValueType
boolint32logical
byteint32uint8
shortint32int16
intint32int32
longint64int64
enumint32any
stringcharchar
float single
double double
any other type any


Ztop

Mapping to Structure Array

...

A dictionary with a structure key type maps to a native MATLAB struct structure array. This mapping sacrifices some functionality, most notably the efficient indexing provided by containers.Map, but it's a straightforward mapping that utilizes a the native MATLAB type that developers are likely to be familiar withstructure type.

Consider this example:

Code Block
languageslice
titleSlice
struct ID
{
    string symbol;
    string exchange;
}
 
dictionary<ID, double> Quotes;

We can construct this dictionary in MATLAB as follows:

Code Block
languagematlab
titleMATLAB
quotes = []; % Or call Quotes.new()
quotes(1).key = ID('CVX', 'NYSE');
quotes(1).value = 100.00;

Each element of the struct structure array must have key and value fields whose types are compatible with those of correspond to the mapped types for the Slice dictionary's key and value.

Ztop

Mapping to Ice.StructArrayHandle

A An empty dictionary with a struct key type is mapped to an empty structure array with fields named key type and a class value type maps to Ice.StructArrayHandle. As its name implies, this simple class derives from handle and has a single member that is a struct array:

Code Block
titleMATLAB
classdef StructArrayHandle < handle
    properties
        array
    end
end

You will use the array member as described above for the struct array mapping.

Consider this example:

Code Block
languageslice
titleSlice
struct ID
{
    string symbol;
    string exchange;
}
 
class Quote
{
    double price;
    string currency;
}
 
dictionary<ID, Quote> Quotes;

We can construct this dictionary in MATLAB as follows:

Code Block
titleMATLAB
quotes = Quotes.new();
quotes.array(1).key = ID('CVX', 'NYSE');
quotes.array(1).value = Quote(100.00, 'US');

Ztop

See Also

Ztop

See Also

Znav
nextMATLAB Mapping for Constants
prevMATLAB Mapping for Sequences

...