%_______________________________________________________________________
%
% classdef shiftStack
%_______________________________________________________________________
%
% Shiftable list of fixed size for the MOBS procedure ("stack")
%_______________________________________________________________________
%
% Methods
%
%  insert | places an element on top of the stack
% regress | shifts the stack upwards popping the uppermost element
%           of the top and filling the gap at the bottom up with the
%           initialization value of the stack
%     top | returns the top element of the stack
%     all | return all elements of the stack
%_______________________________________________________________________
%
classdef shiftStack

  properties
    init;
    stack;
  end

  methods

    function obj = shiftStack(stack)
      if numel(stack) >= 2
        obj.init = stack(1);
        obj.stack = stack;
      else
        error('stack must have at least two elements')
      end
    end

    function obj = insert(obj, value)
      obj.stack = [value obj.stack(1:end-1)];
    end

    function obj = regress(obj)
      obj.stack = [obj.stack(2:end) obj.init];
    end

    function val = top(obj)
      val = obj.stack(1);
    end
    
    function val = all(obj)
      val = obj.stack;
    end

  end
end
