classdef (Hidden = true) Rule < handle

    % Copyright 2012-2020 The MathWorks, Inc.
    
    properties
        Description = '';
        InitStatus  = '';
        FullCommand = '';
        ToolCommand = '';
        ToolFlags   = '';
        LinkObjs    = '';
        EndStatus   = '';
        IsMain      = false;
    end
    
    methods
        % -----------------------------------------------------------------
        % Constructor
        % -----------------------------------------------------------------
        function h = Rule(aDescription)
            if nargin>=1
                h.Description = aDescription;
            end
        end
        
        % -----------------------------------------------------------------
        % GET/SET METHODS
        % -----------------------------------------------------------------
        function set.Description(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'Description', class(h), 'string'))
            end
            h.Description = value;
        end
        
        function set.InitStatus(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'InitStatus', class(h), 'string'))
            end
            h.InitStatus = value;
        end
        
        function set.EndStatus(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'EndStatus', class(h), 'string'))
            end
            h.EndStatus = value;
        end
        
        function set.FullCommand(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'FullCommand', class(h), 'string'))
            end
            h.FullCommand = value;
        end
        
        function set.ToolCommand(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'ToolCommand', class(h), 'string'))
            end
            h.ToolCommand = value;
        end
        
        function set.ToolFlags(h, value)
            if ~isempty(value) && ~ischar(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'ToolFlags', class(h), 'string'))
            end
            h.ToolFlags = value;
        end
        
        function set.LinkObjs(h, value)
            if ~isempty(value) && ~ischar(value) && ~iscell(value) %% ~iscellstr(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'LinkObjs', class(h), 'string'))
            end
            h.LinkObjs = value;
        end
        
        function set.IsMain(h, value)
            if ~islogical(value)
                error(message('CoderFoundation:utility:InvalidProperty', ...
                    'IsMain', class(h), 'logical'))
            end
            h.IsMain  = value;
        end
        
    end % public methods
    
    methods(Hidden)
        
        % -----------------------------------------------------------------
        % Clone contents of another object (copy values only, not handles)
        % -----------------------------------------------------------------
        function clone(h, aRule)
            h.copyValues(aRule);
        end
        
        % -----------------------------------------------------------------
        % Check if the object is empty
        % -----------------------------------------------------------------
        function yes = isempty(h)
            yes = isempty(h.FullCommand) && isempty(h.InitStatus) ...
                && isempty(h.EndStatus);
        end
                
        % -----------------------------------------------------------------
        % Check if the contents are equal
        % -----------------------------------------------------------------
        function out = isEqualTo(h, src)            
            out = isequal(h, src);
        end
        
        % -----------------------------------------------------------------
        % Internal-only access to private/public properties
        % -----------------------------------------------------------------
        function out = getProp(h, prop)
            out = h.(prop);
        end
        
    end
    
    methods(Access = protected)
        
        function copyValues(h, aRule)
            if ~strcmp(class(h), class(aRule))
                error(message('coder_compile:toolchain:CannotCloneClassMismatch', ...
                    class(aRule), class(h)));
            end
            h.Description   = aRule.Description;
            h.InitStatus    = aRule.InitStatus;
            h.FullCommand   = aRule.FullCommand;
            h.ToolCommand   = aRule.ToolCommand;
            h.ToolFlags     = aRule.ToolFlags;
            h.LinkObjs      = aRule.LinkObjs;
            h.EndStatus     = aRule.EndStatus;
            h.IsMain        = aRule.IsMain;
        end
    end
    
end

% LocalWords:  toolchain
