www.gusucode.com > ros 工具箱 matlab源码程序 > ros/+robotics/+ros/+msggen/+nav_msgs/GridCells.m

    classdef GridCells < robotics.ros.Message
    %GridCells MATLAB implementation of nav_msgs/GridCells
    %   This class was automatically generated by
    %   robotics.ros.msg.internal.gen.MessageClassGenerator.
    
    %   Copyright 2014-2016 The MathWorks, Inc.
    
    %#ok<*INUSD>
    
    properties (Constant)
        MessageType = 'nav_msgs/GridCells' % The ROS message type
    end
    
    properties (Constant, Hidden)
        MD5Checksum = 'b9e4f5df6d28e272ebde00a3994830f5' % The MD5 Checksum of the message definition
    end
    
    properties (Access = protected)
        JavaMessage % The Java message object
    end
    
    properties (Constant, Access = protected)
        GeometryMsgsPointClass = robotics.ros.msg.internal.MessageFactory.getClassForType('geometry_msgs/Point') % Dispatch to MATLAB class for message type geometry_msgs/Point
        StdMsgsHeaderClass = robotics.ros.msg.internal.MessageFactory.getClassForType('std_msgs/Header') % Dispatch to MATLAB class for message type std_msgs/Header
    end
    
    properties (Dependent)
        Header
        CellWidth
        CellHeight
        Cells
    end
    
    properties (Access = protected)
        Cache = struct('Header', [], 'Cells', []) % The cache for fast data access
    end
    
    properties (Constant, Hidden)
        PropertyList = {'CellHeight', 'CellWidth', 'Cells', 'Header'} % List of non-constant message properties
        ROSPropertyList = {'cell_height', 'cell_width', 'cells', 'header'} % List of non-constant ROS message properties
    end
    
    methods
        function obj = GridCells(msg)
            %GridCells Construct the message object GridCells
            import com.mathworks.toolbox.robotics.ros.message.MessageInfo;
            
            % Support default constructor
            if nargin == 0
                obj.JavaMessage = obj.createNewJavaMessage;
                return;
            end
            
            % Construct appropriate empty array
            if isempty(msg)
                obj = obj.empty(0,1);
                return;
            end
            
            % Make scalar construction fast
            if isscalar(msg)
                % Check for correct input class
                if ~MessageInfo.compareTypes(msg(1), obj.MessageType)
                    error(message('robotics:ros:message:NoTypeMatch', obj.MessageType, ...
                        char(MessageInfo.getType(msg(1))) ));
                end
                obj.JavaMessage = msg(1);
                return;
            end
            
            % Check that this is a vector of scalar messages. Since this
            % is an object array, use arrayfun to verify.
            if ~all(arrayfun(@isscalar, msg))
                error(message('robotics:ros:message:MessageArraySizeError'));
            end
            
            % Check that all messages in the array have the correct type
            if ~all(arrayfun(@(x) MessageInfo.compareTypes(x, obj.MessageType), msg))
                error(message('robotics:ros:message:NoTypeMatchArray', obj.MessageType));
            end
            
            % Construct array of objects if necessary
            objType = class(obj);
            for i = 1:length(msg)
                obj(i,1) = feval(objType, msg(i)); %#ok<AGROW>
            end
        end
        
        function header = get.Header(obj)
            %get.Header Get the value for property Header
            if isempty(obj.Cache.Header)
                obj.Cache.Header = feval(obj.StdMsgsHeaderClass, obj.JavaMessage.getHeader);
            end
            header = obj.Cache.Header;
        end
        
        function set.Header(obj, header)
            %set.Header Set the value for property Header
            validateattributes(header, {obj.StdMsgsHeaderClass}, {'nonempty', 'scalar'}, 'GridCells', 'Header');
            
            obj.JavaMessage.setHeader(header.getJavaObject);
            
            % Update cache if necessary
            if ~isempty(obj.Cache.Header)
                obj.Cache.Header.setJavaObject(header.getJavaObject);
            end
        end
        
        function cellwidth = get.CellWidth(obj)
            %get.CellWidth Get the value for property CellWidth
            cellwidth = single(obj.JavaMessage.getCellWidth);
        end
        
        function set.CellWidth(obj, cellwidth)
            %set.CellWidth Set the value for property CellWidth
            validateattributes(cellwidth, {'numeric'}, {'nonempty', 'scalar'}, 'GridCells', 'CellWidth');
            
            obj.JavaMessage.setCellWidth(cellwidth);
        end
        
        function cellheight = get.CellHeight(obj)
            %get.CellHeight Get the value for property CellHeight
            cellheight = single(obj.JavaMessage.getCellHeight);
        end
        
        function set.CellHeight(obj, cellheight)
            %set.CellHeight Set the value for property CellHeight
            validateattributes(cellheight, {'numeric'}, {'nonempty', 'scalar'}, 'GridCells', 'CellHeight');
            
            obj.JavaMessage.setCellHeight(cellheight);
        end
        
        function cells = get.Cells(obj)
            %get.Cells Get the value for property Cells
            if isempty(obj.Cache.Cells)
                javaArray = obj.JavaMessage.getCells;
                array = obj.readJavaArray(javaArray, obj.GeometryMsgsPointClass);
                obj.Cache.Cells = feval(obj.GeometryMsgsPointClass, array);
            end
            cells = obj.Cache.Cells;
        end
        
        function set.Cells(obj, cells)
            %set.Cells Set the value for property Cells
            if ~isvector(cells) && isempty(cells)
                % Allow empty [] input
                cells = feval([obj.GeometryMsgsPointClass '.empty'], 0, 1);
            end
            
            validateattributes(cells, {obj.GeometryMsgsPointClass}, {'vector'}, 'GridCells', 'Cells');
            
            javaArray = obj.JavaMessage.getCells;
            array = obj.writeJavaArray(cells, javaArray, obj.GeometryMsgsPointClass);
            obj.JavaMessage.setCells(array);
            
            % Update cache if necessary
            if ~isempty(obj.Cache.Cells)
                obj.Cache.Cells = [];
                obj.Cache.Cells = obj.Cells;
            end
        end
    end
    
    methods (Access = protected)
        function resetCache(obj)
            %resetCache Resets any cached properties
            obj.Cache.Header = [];
            obj.Cache.Cells = [];
        end
        
        function cpObj = copyElement(obj)
            %copyElement Implements deep copy behavior for message
            
            % Call default copy method for shallow copy
            cpObj = copyElement@robotics.ros.Message(obj);
            
            % Clear any existing cached properties
            cpObj.resetCache;
            
            % Create a new Java message object
            cpObj.JavaMessage = obj.createNewJavaMessage;
            
            % Iterate over all primitive properties
            cpObj.CellWidth = obj.CellWidth;
            cpObj.CellHeight = obj.CellHeight;
            
            % Recursively copy compound properties
            cpObj.Header = copy(obj.Header);
            cpObj.Cells = copy(obj.Cells);
        end
        
        function reload(obj, strObj)
            %reload Called by loadobj to assign properties
            obj.CellWidth = strObj.CellWidth;
            obj.CellHeight = strObj.CellHeight;
            obj.Header = feval([obj.StdMsgsHeaderClass '.loadobj'], strObj.Header);
            CellsCell = arrayfun(@(x) feval([obj.GeometryMsgsPointClass '.loadobj'], x), strObj.Cells, 'UniformOutput', false);
            obj.Cells = vertcat(CellsCell{:});
        end
    end
    
    methods (Access = ?robotics.ros.Message)
        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.CellWidth = obj.CellWidth;
            strObj.CellHeight = obj.CellHeight;
            strObj.Header = saveobj(obj.Header);
            strObj.Cells = arrayfun(@(x) saveobj(x), obj.Cells);
        end
    end
    
    methods (Static, Access = {?matlab.unittest.TestCase, ?robotics.ros.Message})
        function obj = loadobj(strObj)
            %loadobj Implements loading of message from MAT file
            
            % Return an empty object array if the structure element is not defined
            if isempty(strObj)
                obj = robotics.ros.msggen.nav_msgs.GridCells.empty(0,1);
                return
            end
            
            % Create an empty message object
            obj = robotics.ros.msggen.nav_msgs.GridCells;
            obj.reload(strObj);
        end
    end
end