1-- Copyright 1994 Grady Booch 2-- Copyright 2003-2014 Simon Wright <simon@pushface.org> 3 4-- This package is free software; you can redistribute it and/or 5-- modify it under terms of the GNU General Public License as 6-- published by the Free Software Foundation; either version 2, or 7-- (at your option) any later version. This package is distributed in 8-- the hope that it will be useful, but WITHOUT ANY WARRANTY; without 9-- even the implied warranty of MERCHANTABILITY or FITNESS FOR A 10-- PARTICULAR PURPOSE. See the GNU General Public License for more 11-- details. You should have received a copy of the GNU General Public 12-- License distributed with this package; see file COPYING. If not, 13-- write to the Free Software Foundation, 59 Temple Place - Suite 14-- 330, Boston, MA 02111-1307, USA. 15 16-- As a special exception, if other files instantiate generics from 17-- this unit, or you link this unit with other files to produce an 18-- executable, this unit does not by itself cause the resulting 19-- executable to be covered by the GNU General Public License. This 20-- exception does not however invalidate any other reasons why the 21-- executable file might be covered by the GNU Public License. 22 23with BC.Support.Unmanaged; 24 25generic 26package BC.Containers.Stacks.Unmanaged is 27 28 pragma Preelaborate; 29 30 type Stack is new Abstract_Stack with private; 31 -- This Stack exhibits unlimited growth and collapsing, limited 32 -- only by available memory. Assignment is "deep". 33 34 function Null_Container return Stack; 35 36 function "=" (Left, Right : in Stack) return Boolean; 37 -- Return True if and only if both stacks have the same depth and 38 -- the same items in the same order; return False otherwise. 39 40 procedure Clear (S : in out Stack); 41 -- Empty the Stack of all items. 42 43 procedure Push (S : in out Stack; Elem : Item); 44 -- Add a copy of the item to the top of the Stack. 45 46 procedure Pop (S : in out Stack); 47 -- Remove the item from the top of the Stack. 48 49 function Depth (S : in Stack) return Natural; 50 -- Returns the number of items in the Stack. 51 52 function Is_Empty (S : in Stack) return Boolean; 53 -- Returns True if and only if no items are in the stack. 54 55 function Top (S : in Stack) return Item; 56 -- Return a copy of the item at the top of the Stack. 57 58 function New_Iterator (For_The_Stack : Stack) return Iterator'Class; 59 -- Return a reset Iterator bound to the specific Stack. 60 61private 62 63 function Item_At (S : Stack; Index : Positive) return Item_Ptr; 64 65 procedure Add (S : in out Stack; Elem : Item); 66 procedure Remove (S : in out Stack; From : Positive); 67 68 package Stack_Nodes 69 is new BC.Support.Unmanaged (Item => Item, 70 Item_Ptr => Item_Ptr); 71 72 type Stack is new Abstract_Stack with record 73 Rep : Stack_Nodes.Unm_Node; 74 end record; 75 76end BC.Containers.Stacks.Unmanaged; 77