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