MATLAB Mapping for Parameters and Return Values
In Parameters
An in parameter is mapped to a MATLAB parameter with the same name; its type is the mapped MATLAB type.
For example, a Slice parameter string name is mapped to a MATLAB parameter name with type charand size (1 :). The rules are the same as for Fields.
Out Parameters and Return Values
The MATLAB mapping uses the conventional language mechanism for returning one or more result values.
Consider the following Slice definitions:
struct NumberAndString
{
["matlab:identifier:X"]
int x;
["matlab:identifier:Str"]
string str;
}
sequence<string> StringSeq;
dictionary<long, StringSeq> StringTable;
interface ServerToClient
{
void op1(out int i, out float f, out bool b, out string s);
void op2(out NumberAndString ns,
out StringSeq ss,
out StringTable st);
void op3(out ServerToClient* proxy);
}
The Slice compiler generates the following code:
classdef ServerToClientPrx < Ice.ObjectPrx
methods
function [i, f, b, s] = op1(obj, context)
...
end
function [ns, ss, st] = op2(obj, context)
...
end
function proxy = op3(obj, context)
...
end
function future = op1Async(obj, context)
...
end
function future = op2Async(obj, context)
...
end
function future = op3Async(obj, context)
...
end
end
end
Optional Parameters
Optional parameters use the same mapping as required parameters, with one difference: the parameter accepts Ice.Unset as a valid value.
Consider the following operation:
optional(1) int execute(optional(2) string p, out optional(3) float value);
A client can invoke this operation as shown below:
[i, v] = proxy.execute('--file log.txt');
[i, v] = proxy.execute(Ice.Unset);
if v ~= Ice.Unset
fprintf('value = %f\n', v); % v is set to a value
end
A well-behaved program must always test an optional parameter prior to using its value. Keep in mind that the Ice.Unset marker value has different semantics than an empty array. Since an empty array is a legal value for certain Slice types, the Ice runtime requires a separate marker value so that it can determine whether an optional parameter is set. An optional parameter set to an empty array is considered to be set.
In MATLAB, you can distinguish between an optional proxy parameter set to null (represented by an empty array) and an optional proxy parameter that is not set (it carries the Ice.Unset value). Since other language mappings can’t make this distinction, you should avoid using this feature.