1--  Copyright 1994 Grady Booch
2--  Copyright 1994-1997 David Weller
3--  Copyright 2003-2014 Simon Wright <simon@pushface.org>
4--  Copyright 2005 Martin Krischik
5
6--  This package is free software; you can redistribute it and/or
7--  modify it under terms of the GNU General Public License as
8--  published by the Free Software Foundation; either version 2, or
9--  (at your option) any later version. This package is distributed in
10--  the hope that it will be useful, but WITHOUT ANY WARRANTY; without
11--  even the implied warranty of MERCHANTABILITY or FITNESS FOR A
12--  PARTICULAR PURPOSE. See the GNU General Public License for more
13--  details. You should have received a copy of the GNU General Public
14--  License distributed with this package; see file COPYING.  If not,
15--  write to the Free Software Foundation, 59 Temple Place - Suite
16--  330, Boston, MA 02111-1307, USA.
17
18--  As a special exception, if other files instantiate generics from
19--  this unit, or you link this unit with other files to produce an
20--  executable, this unit does not by itself cause the resulting
21--  executable to be covered by the GNU General Public License.  This
22--  exception does not however invalidate any other reasons why the
23--  executable file might be covered by the GNU Public License.
24
25with BC.Support.Indefinite_Unmanaged;
26
27generic
28package BC.Indefinite_Unmanaged_Containers.Queues is
29
30   pragma Preelaborate;
31
32   type Queue is new Container with private;
33   --  This Queue exhibits unlimited growth and collapsing, limited
34   --  only by available memory.  Assignment is "deep".
35
36   function Null_Container return Queue;
37
38   procedure Clear (Q : in out Queue);
39   --  Empty the queue of all items.
40
41   procedure Append (Q : in out Queue; Elem : Item);
42   --  Add the item to the back of the queue; the item itself is
43   --  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   generic
61      with procedure Process (Elem : in out Item);
62   procedure Process_Front (Q : in out Queue'Class);
63   --  Allows modification of the item at the front of the queue.
64
65   function Location (Q : in Queue; Elem : Item) return Natural;
66   --  Return the first index at which the item is found; return 0 if
67   --  the item does not exist in the queue.
68
69   function "=" (Left, Right : in Queue) return Boolean;
70   --  Return True if and only if both queues have the same length and
71   --  the same items in the same order; return False otherwise.
72
73   function New_Iterator (For_The_Queue : Queue) return Iterator'Class;
74   --  Return a reset Iterator bound to the specific Queue.
75
76private
77
78   package Queue_Nodes
79   is new BC.Support.Indefinite_Unmanaged (Item => Item,
80                                           Item_Ptr => Item_Ptr);
81
82   type Queue is new Container with record
83      Rep : Queue_Nodes.Unm_Node;
84   end record;
85
86   function Item_At (Q : Queue; Index : Positive) return Item_Ptr;
87
88   type Queue_Iterator is new Iterator with record
89      Index : Natural;
90   end record;
91
92   --  Overriding primitive supbrograms of the concrete actual Iterator.
93
94   procedure Reset (It : in out Queue_Iterator);
95
96   procedure Next (It : in out Queue_Iterator);
97
98   function Is_Done (It : Queue_Iterator) return Boolean;
99
100   function Current_Item (It : Queue_Iterator) return Item;
101
102   function Current_Item_Ptr (It : Queue_Iterator) return Item_Ptr;
103
104   procedure Delete_Item_At (It : in out Queue_Iterator);
105
106end BC.Indefinite_Unmanaged_Containers.Queues;
107