classdef SimulinkFunctionVisibility
    % SIMULINKFUNCTIONVISIBILITY
    %
    % Enumeration of different possible Simulink Function visibilities
    % for use by SIL/PIL.

    % Copyright 2021 The MathWorks, Inc.
    enumeration
        Unknown
        ScopedLocal
        ScopedExport
        Global
    end

    methods (Static)
        function ret = fromSerializedString(str)
            % FROMSERIALIZEDSTRING
            %
            %   Get an instance of the enumeration based on the string that
            %   would be serialized in the model reference MF0 artifact.
            %
            switch str
                case 'Unknown'
                    ret = rtw.pil.SimulinkFunctionVisibility.Unknown;
                case 'Scoped Local'
                    ret = rtw.pil.SimulinkFunctionVisibility.ScopedLocal;
                case 'Scoped Export'
                    ret = rtw.pil.SimulinkFunctionVisibility.ScopedExport;
                case 'Global'
                    ret = rtw.pil.SimulinkFunctionVisibility.Global;
                otherwise
                    assert(false, 'Unexpected serialized string "%s" for SimulinkFunctionVisibility', str);
            end
        end
    end

    methods (Access = public)
        function ret = isScoped(obj)
            % Returns true if the enum describes a function that
            % is scoped in any way (i.e., exists within a namespace),
            % independently of the nature of the scope.
            ret = ismember(obj, ...
                [rtw.pil.SimulinkFunctionVisibility.ScopedLocal, ...
                rtw.pil.SimulinkFunctionVisibility.ScopedExport]);
        end

        function ret = isExported(obj)
            % Returns true if the enum describes a function that is either
            % global, or scoped in a way that is definition must be exposed
            % to a parent or peer model.
            ret = ismember(obj, ...
                [rtw.pil.SimulinkFunctionVisibility.Global, ...
                rtw.pil.SimulinkFunctionVisibility.ScopedExport]);
        end
    end
end
