1
------------------------------------------------------------------------------
3
-- GNATPP COMPONENTS --
5
-- G N A T P P . S T A C S --
11
-- Copyright (C) 2001, ACT Europe --
13
-- GNATPP is free software; you can redistribute it and/or modify it under --
14
-- terms of the GNU General Public License as published by the Free Soft- --
15
-- ware Foundation; either version 2, or (at your option) any later ver- --
16
-- sion. GNATPP is distributed in the hope that it will be useful, but --
17
-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABI- --
18
-- LITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
19
-- License for more details. You should have received a copy of the GNU --
20
-- General Public License distributed with GNAT; see file COPYING. If not, --
21
-- write to the Free Software Foundation, 59 Temple Place - Suite 330, --
24
-- GNATPP is maintained by ACT Europe (http://www.act-europe.fr). --
26
------------------------------------------------------------------------------
30
package body GNATPP.Stacs is
32
package Stack_Table is new Table.Table
33
(Table_Component_Type => Element_Type,
34
Table_Index_Type => Natural,
37
Table_Increment => 100,
38
Table_Name => "Generic Stack");
40
Stack : Stack_Table.Table_Ptr renames Stack_Table.Table;
46
function Is_Empty return Boolean is
48
return Stack_Table.Last = 0;
55
function Pop return Element_Type is
61
Stack_Table.Decrement_Last;
62
return Stack (Stack_Table.Last + 1);
75
Stack_Table.Decrement_Last;
84
procedure Push (Elem : Element_Type) is
86
Stack_Table.Append (Elem);
93
function Size return Natural renames Stack_Table.Last;
99
function Top (Step_Down : Natural := 0) return Element_Type is
102
if Is_Empty or else Step_Down > Stack_Table.Last then
105
return Stack (Stack_Table.Last - Step_Down);