function self = push(self, object)
%PUSH put new object in queue 
%   queue = push(queue,object)
%
% $Id$

% if empty object, no action
% --------------------------
if isempty(object)
  return
end

% if new entrie is equal to last entry, no action
% use short circuit operator, second expression (isequal) isn't evaluate 
% if first expression (isempty) is true
% -----------------------------------------------
if ~self.index || isempty(self.buffer) || ~isequal(object, self.buffer{self.index})

  % increment internal index
  % ------------------------
  self.index = self.index+1;
 
  % store new object at index
  % -------------------------
  self.buffer{self.index} = object;
  
  % test if index reach end of buffer
  % --------------------------------
  if self.index <= self.size
    
    % reset all data stored in buffer after index
    % -------------------------------------------
    self.buffer(self.index+1:end) = [];
    
    % reset size
    % ----------
    self.size = self.index;
    
  else
    % increment size
    % --------------
    self.size = self.size +1;
  end
  
  % if an object was previously prepare in data with undo or redo, reset it
  % -----------------------------------------------------------------------
  if ~isempty(self.data)
    self.data = {};
  end
  
else
  return
end