Preliminary documentation for Ice for MATLAB. Do not use in production applications. Refer to the space directory for other releases.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

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

Key TypeValue TypeMapped TypeComments
string, enum or numericAnycontainers.MapEnumeration keys must be converted to integers.
structAnyNative struct arraycontainers.Map does not support user-defined key types.
structclassIce.StructArrayHandleMaps to a handle type to support the Ice run time's unmarshaling requirements.

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.

On this page:

Mapping to containers.Map

Consider the definition of our EmployeeMap once more:

Slice
dictionary<long, Employee> EmployeeMap;

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

MATLAB
em = EmployeeMap.new();
 
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:

MATLAB
em = containers.Map('KeyType', 'int64', 'ValueType', 'any');

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

 

Mapping to struct array

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

Consider this example:

Slice
struct ID
{
    string symbol;
    string exchange;
}
 
dictionary<ID, double> Quotes;

We can construct this dictionary in MATLAB as follows:

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

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

Mapping to Ice.StructArrayHandle

A dictionary with a structure 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:

MATLAB
classdef StructArrayHandle < handle
    properties
        array
    end
end

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

Consider this example:

Slice
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:

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

See Also
  • No labels