classdef SILPILBuildOptions
    %SILPILBUILDOPTIONS Used by PIL build methods to configure the build
    %process options for the SIL or PIL build

%   Copyright 2020 The MathWorks, Inc.
    
    properties
        ComponentArgs
        XilCompInfo
        LibSuffixFromConfigSet char = '';
        IsPurelyIntegerCode logical = false;
        IsSILAndPWS logical = false;
        ForceDebuggingEnabled logical = false;
        CodeBuildParams cell
    end
    
    methods
        function this = SILPILBuildOptions(componentArgs, xilCompInfo, varargin)
                        
            persistent p
            
            if nargin == 0
                return;
            end
            
            this.ComponentArgs = componentArgs;
            this.XilCompInfo = xilCompInfo;
            
            if isempty(p)
                p = inputParser;
                p.KeepUnmatched = true;
                addParameter(p, 'LibSuffixFromConfigSet', '', @ischar);
                addParameter(p, 'IsPurelyIntegerCode', false, @islogical);
                addParameter(p, 'IsSILAndPWS', false);
                addParameter(p, 'ForceDebuggingEnabled', false);
            end
            
            p.parse(varargin{:});   
            
            this.LibSuffixFromConfigSet = p.Results.LibSuffixFromConfigSet;
            this.IsPurelyIntegerCode = p.Results.IsPurelyIntegerCode;
            this.IsSILAndPWS = p.Results.IsSILAndPWS;
            this.ForceDebuggingEnabled = p.Results.ForceDebuggingEnabled;
            
            % Add unmatched input arguments to do compile params
            unMatchedArgNames = fieldnames(p.Unmatched);
            this.CodeBuildParams = cell(1, 2*length(unMatchedArgNames));
            this.CodeBuildParams(1:2:end) = unMatchedArgNames;
            this.CodeBuildParams(2:2:end) = struct2cell(p.Unmatched);            
        end
        
        function nameValueCell = getArgumentsAsNameValuePairs(this)
            
            nameValueCell = {'LibSuffixFromConfigSet', this.LibSuffixFromConfigSet, ...
                             'IsPurelyIntegerCode', this.IsPurelyIntegerCode, ...
                             'IsSILAndPWS', this.IsSILAndPWS, ...
                             'ForceDebuggingEnabled', this.ForceDebuggingEnabled };
            
            nameValueCell = [nameValueCell this.CodeBuildParams(:)'];
        end
    end
end

