classdef RangeExtractionInterface < handle
    %% RANGEEXTRACTIONINTERFACE class
    % This class is an interface to extract ranges from a data type group. 
    % The interface has a queue of strategies to pick out specific ranges
    % from a group. 
    
    % Copyright 2018 The MathWorks, Inc.
    
    properties(SetAccess = private)
        strategies = fxptds.RangeAggregation.RangeExtractionStrategy.empty;
    end
    
    methods
        function addStrategy(this, strategy)
            % add strategies from the call site
            this.strategies(end+1,1) = strategy; 
        end
        
        function finalRange = getRanges(this, group)
            % get the final range from all the strategies
            allRanges = cell(numel(this.strategies), 1);
            for sIndex = 1:numel(this.strategies)
                allRanges{sIndex} = this.strategies(sIndex).extractRange(group);
            end
            
            % allRanges may have some cells that are empty; cell2mat will
            % remove the empty cells automatically
            [rangeMin, rangeMax] = SimulinkFixedPoint.extractMinMax(cell2mat(allRanges));
            finalRange = [rangeMin, rangeMax];
            
        end
        
    end
end

