classdef MLFBResultMergeStrategy < handle
    % Strategy class to handle merging of fields in MLFB Expression and
    % Variable Results 
    
    % TODO: g1890113 - The merge logic of results across multiple
    % simulations is currently spread across
    % SimulinkFixedPoint.ApplicationData.addDataFromSrc and
    % fxptds.putMATLABFunctionBlockDataIntoRunObject. The above mentioned
    % will be used to track work on unifying the logic.
    
    % Copyright 2018 The MathWorks, Inc.
    
    properties
        Result fxptds.MATLABExpressionResult;
    end
    methods
        function obj = MLFBResultMergeStrategy(result)
            % Constructor
            assert(fxptds.isResultValid(result));
            
            obj.Result = result;
        end
        function data = mergeInstrumentationData(obj, data)
            % Merge instrumentation fields for MLFBExpressionResults
            if ~isempty(obj.Result) && ~isempty(data.OverflowOccurred)
                data.OverflowOccurred = data.OverflowOccurred + obj.Result.OverflowWrap;
            end
            if ~isempty(obj.Result) && ~isempty(data.SaturationOccurred)
                data.SaturationOccurred = data.SaturationOccurred + obj.Result.OverflowSaturation; 
            end
        end
    end
end
