API Reference

type Context_Data

  
   package Implementation is new Stack_Unbounded_Unprotected  
      (Element => Element, Assign => Assign);  
  
   type Context_Data is tagged null record;  

type Action_Ptr is access procedure

   type Action_Ptr is access procedure (Item     : in out Element;   
                                        Context  : in out Context_Data'Class;  
                                        Continue : out Boolean);  

We can't have a generic protected subprogram, so we use this type to implement Iterate. This means that the actual procedure passed to Iterate must be declared at the library level to pass accessibility checks.

procedure Clear;

      procedure Clear;   

Makes the stack empty.

Time: O(N).

procedure Push

      procedure Push (Item : in Element); -- raise Storage_Exhausted.   

Adds Item to the top of the stack.

Raises Storage_Exhausted if there is insufficient storage for the Element.

The stack is unchanged if Storage_Exhausted is raised.

Time: O(1).

procedure Pop

      procedure Pop (Item : in out Element); -- raise Empty.   

Removes the top Element from the stack and puts it in Item. Raises Empty if the stack has no elements.

The stack is unchanged if Empty is raised.

Contents of Item are undefined if Empty is raised.

Time: O(1).

Precondition: not Is_Empty raises Empty if violated.

function Is_Empty

      function Is_Empty return Boolean;   

Returns True if the stack is empty; False otherwise.

function Length

      function Length return Natural;   

Returns the number of Elements in the stack.

function Peek

      function Peek return Element;   

Returns the Element at the top of the stack without altering the stack. Raises Empty if the stack is empty.

Time: O(1).

procedure Iterate

      procedure Iterate   
         (Action : in Action_Ptr; Context : in out Context_Data'Class);  

Applies Action to each Element in the stack in turn, from top to bottom.

Iterate returns immediately if Action sets Continue to False.