Interface to Generic Stack Package

GENERIC

  TYPE Element IS PRIVATE;

PACKAGE Stacks_Generic IS
------------------------------------------------------------------------
--| Specification for Generic Stacks Package, Array Implementation.
--| Author: Michael B. Feldman, The George Washington University
--| Last Modified: January 1996
------------------------------------------------------------------------

  -- type definition

  TYPE Stack (Capacity: Positive) IS LIMITED PRIVATE;

  -- exported exceptions

  StackFull  : EXCEPTION;
  StackEmpty : EXCEPTION;

  -- constructors

  PROCEDURE MakeEmpty (S : IN OUT Stack);
  -- Pre:    S is defined
  -- Post:   S is empty

  PROCEDURE Push (S : IN OUT Stack; E : IN Element);
  -- Pre:    S and E are defined
  -- Post:   S is returned with E as the top Element
  -- Raises: StackFull if S already contains Capacity Elements

  PROCEDURE Pop (S : IN OUT Stack);
  -- Pre:    S is defined
  -- Post:   S is returned with the top Element discarded
  -- Raises: StackEmpty if S contains no Elements

  -- selector

  FUNCTION Top (S : IN Stack) RETURN Element;
  -- Pre:    S is defined
  -- Post:   The top Element of S is returned
  -- Raises: StackEmpty if S contains no Elements

  -- inquiry operations

  FUNCTION IsEmpty (S : IN Stack) RETURN Boolean;
  -- Pre:    S is defined
  -- Post:   returns True if S is empty, False otherwise

  FUNCTION IsFull  (S : IN Stack) RETURN Boolean;
  -- Pre:    S is defined
  -- Post:   returns True if S is full, False otherwise

PRIVATE

  TYPE List IS ARRAY (Positive RANGE <>) OF Element;
  TYPE Stack (Capacity: Positive) IS RECORD
    Latest : Natural := 0;
    Store  : List(1..Capacity);
  END RECORD;

END Stacks_Generic;