www.gusucode.com > ros 工具箱 matlab源码程序 > ros/+robotics/+ros/+msg/+internal/TimeEntity.m

    classdef (Abstract) TimeEntity < robotics.ros.internal.mixin.JavaWrapper & ...
        matlab.mixin.CustomDisplay & matlab.mixin.internal.CompactDisplay & ...
        matlab.mixin.Copyable
    %This class is for internal use only. It may be removed in the future.
    
    %TimeEntity Base class for ROS representation of time and duration.
    %
    %   TimeEntity properties:
    %       Sec  - Second component of time
    %       Nsec - Nanosecond component of time
    %
    %   See also robotics.ros.msg.Time, robotics.ros.msg.Duration.
    
    %   Copyright 2014-2016 The MathWorks, Inc.
    
    properties (Access = {?robotics.ros.msg.internal.TimeEntity, ?matlab.unittest.TestCase})
        %JavaObject - The Java time representation
        JavaObject
        
        %Parser - The parser for time and duration entities
        Parser = robotics.ros.internal.Parsing
    end
    
    properties (Abstract, Dependent)
        %Sec - Second component of time
        Sec
        
        %Nsec - Nanosecond component of time
        Nsec
    end
    
    properties (Constant, Hidden)
        PropertyList = {'Sec', 'Nsec'} % List of non-constant message properties
        ROSPropertyList = {'sec', 'nsec'} % List of non-constant ROS message properties
    end
    
    properties (Abstract, Constant, Access = protected)
        %ClassName - Name of concrete TimeEntity class
        ClassName
    end
    
    methods
        function secs = seconds(obj)
            %SECONDS Scalar number representing the time or duration in seconds
            %   SECS = SECONDS(TIME) calculates the scalar number SECS (in
            %   seconds) that represents the same value as the time object
            %   TIME.
            %
            %   SECS = SECONDS(DURATION) calculates the scalar number SECS (in
            %   seconds) that represents the same value as the duration object
            %   DURATION.
            
            secs = obj.Sec + 1e-9 * obj.Nsec;
        end
    end
    
    methods (Hidden)
        function s = toStruct(obj)
            %toStruct Convert the message object to a struct
            s = obj.saveobj;
        end
        
        function fromStruct(obj, s)
            %fromStruct Reload the object from a struct representation
            obj.reload(s);
        end
    end
    
    methods (Access = {?robotics.ros.Message, ?robotics.ros.msg.internal.TimeEntity})
        function strObj = saveobj(obj)
            %saveobj Implements saving of message to MAT file
            
            % Return an empty element if object array is empty
            if isempty(obj)
                strObj = struct.empty;
                return
            end
            
            strObj.Sec = obj.Sec;
            strObj.Nsec = obj.Nsec;
        end
    end
    
    methods (Access = protected)
        function cpObj = copyElement(obj)
            %copyElement Implements deep copy behavior for time entity
            % Call default copy method for shallow copy
            cpObj = copyElement@matlab.mixin.Copyable(obj);
            
            % Create a new, temporary message object
            cpObj.JavaObject = obj.createNewJavaObject;
            
            % Iterate over all properties and copy them recursively
            cpObj.Sec = obj.Sec;
            cpObj.Nsec = obj.Nsec;
        end
        
        function delete(~)
            %delete Protected delete call to prevent explicit invocations
            %   This will avoid problems due to deleted handle
            %   objects in copying or saving to a MAT file.
        end
    end
    
    % Methods inherited from CustomDisplay
    methods (Access = protected)
        function header = getHeader(obj)
            %getHeader Returns a custom header for ROS time structure
            
            if ~isscalar(obj)
                % For an object array, extract its size
                headerStr = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
                headerStr = ['  ' num2str(size(obj,1)) 'x' num2str(size(obj,2)) ...
                    ' ROS ', headerStr,' array with properties:'];
                header = sprintf('%s\n',headerStr);
            else
                % This is the custom display for scalar objects
                headerStr = matlab.mixin.CustomDisplay.getClassNameForHeader(obj);
                headerStr = ['  ROS ', headerStr,' with properties:'];
                header = sprintf('%s\n',headerStr);
            end
        end
    end
    
    methods (Access = {?robotics.ros.internal.mixin.JavaAccess, ?matlab.unittest.TestCase})
        function javaObj = getJavaObject(obj)
            %getJavaObject Implementation of JavaWrapper interface
            javaObj = obj.JavaObject;
        end
    end
    
    methods (Abstract, Access = protected)
        timeEntity = createNewJavaObject(obj);
        %createNewJavaObject Create a new Java object for the time entity
    end
    
end