1--  Copyright 1994 Grady Booch
2--  Copyright 1994-1997 David Weller
3--  Copyright 2003-2014 Simon Wright <simon@pushface.org>
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 System.Address_To_Access_Conversions;
25
26package body BC.Containers.Queues.Unmanaged is
27
28   procedure Clear (Q : in out Queue) is
29   begin
30      Queue_Nodes.Clear (Q.Rep);
31   end Clear;
32
33   procedure Append (Q : in out Queue; Elem : Item) is
34   begin
35      Queue_Nodes.Append (Q.Rep, Elem);
36   end Append;
37
38   procedure Pop (Q : in out Queue) is
39   begin
40      Queue_Nodes.Remove (Q.Rep, 1);
41   end Pop;
42
43   procedure Remove (Q : in out Queue; From : Positive) is
44   begin
45      Queue_Nodes.Remove (Q.Rep, From);
46   end Remove;
47
48   function Length (Q : Queue) return Natural is
49   begin
50      return Queue_Nodes.Length (Q.Rep);
51   end Length;
52
53   function Is_Empty (Q : Queue) return Boolean is
54   begin
55      return Queue_Nodes.Length (Q.Rep) = 0;
56   end Is_Empty;
57
58   function Front (Q : Queue) return Item is
59   begin
60      return Queue_Nodes.First (Q.Rep);
61   end Front;
62
63   function Location (Q : Queue; Elem : Item) return Natural is
64   begin
65      return Queue_Nodes.Location (Q.Rep, Elem);
66   end Location;
67
68   function "=" (Left, Right : Queue) return Boolean is
69      use Queue_Nodes;
70   begin
71      return Left.Rep = Right.Rep;
72   end "=";
73
74   package Address_Conversions
75   is new System.Address_To_Access_Conversions (Queue);
76
77   function New_Iterator (For_The_Queue : Queue) return Iterator'Class is
78      Result : Queue_Iterator;
79   begin
80      Result.For_The_Container :=
81        Container_Ptr (Address_Conversions.To_Pointer (For_The_Queue'Address));
82      Reset (Result);
83      return Result;
84   end New_Iterator;
85
86   function Item_At (Q : Queue; Index : Positive) return Item_Ptr is
87   begin
88      return Queue_Nodes.Item_At (Q.Rep, Index);
89   end Item_At;
90
91   function Null_Container return Queue is
92      Empty_Container : Queue;
93      pragma Warnings (Off, Empty_Container);
94   begin
95      return Empty_Container;
96   end Null_Container;
97
98end BC.Containers.Queues.Unmanaged;
99