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

...

The Slice compiler generates the following code for this definition:

Code Block
languagematlab
titleMATLAB
classdef TimeOfDay < Ice.Value
    properties
        hour int16
        minute int16
        second int16
        tz char
    end
    methods
        function obj = TimeOfDay(hour, minute, second, tz)
            ...
        end
        function id = ice_id(obj)
            ...
        end
        ...
    end
    methods(Static)
        function id = ice_staticId()
            ...
        end
    end
end

...

Classes implicitly inherit from a common base class, Value, which is mapped to Ice.ValueValue is a very simple base class with just a few methods:

Code Block
languagematlab
titleMATLAB
classdef (Abstract) Value < matlab.mixin.Copyable
    methods
        function ice_preMarshal(obj)
        end
        function ice_postUnmarshal(obj)
        end
        function r = ice_getSlicedData(obj)
            ...
        end
        ...
    end
    methods(Abstract)
        id = ice_id(obj)
    end
    methods(Static)
        function id = ice_staticId()
            id = '::Ice::Object'
        end
    end
end

...

Optional data members use the same mapping as required data members, but an optional data member can also be set to the marker value Ice.Unset to indicate that the member is unset. A well-behaved program must test an optional data member before using its value:

Code Block
languagematlab
titleMATLAB
obj = ...;
if obj.optionalMember ~= Ice.Unset
    fprintf('optionalMember = %s\n', ex.optionalMember);
else
    fprintf('optionalMember is unset\n');
end

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 run time requires a separate marker value so that it can determine whether an optional value is set. An optional value set to an empty array is considered to be set. If you need to distinguish between an unset value and a value set to an empty array, you can do so as follows:

Code Block
languagematlab
titleMATLAB
obj = ...;
if obj.optionalMember == Ice.Unset
    fprintf('optionalMember is unset\n');
elseif isempty(obj.optionalMember)
    fprintf('optionalMember is empty\n');
else
    fprintf('optionalMember = %s\n', ex.optionalMember);
end

...

The Slice compiler produces the following generated code for this definition:

Code Block
languagematlab
titleMATLAB
classdef TimeOfDay < Ice.Value
    properties(Access=protected)
        hour int16
        minute int16
        second int16
        tz char
    end
    ...
end

...

If you wish, you can create your own custom derived class, and tell Ice to create and return these instances instead. For example:

Code Block
languagematlab
titleMATLAB
classdef CustomTimeOfDay < TimeOfDay
    methods
        function format(obj)
            % prints formatted data members
        end
    end
end

You then create and register a value factory for your custom class with your Ice communicator:

Code Block
languagematlab
titleMATLAB
function v = factory(type)
    assert(strcmp(type, TimeOfDay.ice_staticId()));
    v = CustomTimeOfDay();
end
 
communicator = ...;
communicator.getValueFactoryManager().add(@factory, TimeOfDay.ice_staticId());

...