1--  Copyright 1994 Grady Booch
2--  Copyright 1998-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.Unbounded;
24with System.Storage_Pools;
25
26generic
27   Storage : in out System.Storage_Pools.Root_Storage_Pool'Class;
28package BC.Containers.Rings.Unbounded is
29
30   pragma Preelaborate;
31
32   type Ring is new Abstract_Ring with private;
33
34   function Null_Container return Ring;
35
36   function "=" (Left, Right : in Ring) return Boolean;
37
38   procedure Clear (R : in out Ring);
39   --  Empty the ring of all items. The mark is cleared.
40
41   procedure Insert (R : in out Ring; Elem : Item);
42   --  If the ring was empty, set the ring's mark and top to designate
43   --  this item.
44   --  Otherwise,
45   --    this item becomes the new top;
46   --    the previous top is located one place forward of the new top;
47   --    the mark remains on the previously marked item.
48
49   procedure Pop (R : in out Ring);
50   --  Remove the top item from the ring.
51   --  If the ring is still not empty, the new top is the item that was
52   --  previously one place forward from the top.
53   --  If the removed item was the marked item, the mark now designates
54   --  the new top.
55
56   function Extent (R : Ring) return Natural;
57   --  Return the number of items in the ring.
58
59   function Is_Empty (R : Ring) return Boolean;
60   --  Return True if and only if there are no items in the ring.
61
62   function Top (R : Ring) return Item;
63   --  Return a copy of the item at the top of the ring.
64
65   function New_Iterator (For_The_Ring : Ring) return Iterator'Class;
66   --  Return a reset Iterator bound to the specific Ring.
67
68private
69
70   procedure Add (R : in out Ring; Elem : Item);
71   function Item_At (R : Ring; Index : Positive) return Item_Ptr;
72
73   package Ring_Nodes
74   is new BC.Support.Unbounded (Item => Item,
75                                Item_Ptr => Item_Ptr,
76                                Storage => Storage);
77
78   type Ring is new Abstract_Ring with record
79      Rep : Ring_Nodes.Unb_Node;
80   end record;
81
82end BC.Containers.Rings.Unbounded;
83