1--  Copyright 1994 Grady Booch
2--  Copyright 2003-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 System.Address_To_Access_Conversions;
24
25package body BC.Containers.Collections.Unmanaged is
26
27   function "=" (Left, Right : in Collection) return Boolean is
28      use Collection_Nodes;
29   begin
30      return Left.Rep = Right.Rep;
31   end "=";
32
33   procedure Clear (C : in out Collection) is
34   begin
35      Collection_Nodes.Clear (C.Rep);
36   end Clear;
37
38   procedure Insert (C : in out Collection; Elem : Item) is
39   begin
40      Collection_Nodes.Insert (C.Rep, Elem);
41   end Insert;
42
43   procedure Insert (C : in out Collection;
44                     Elem : Item;
45                     Before : Positive) is
46   begin
47      Collection_Nodes.Insert (C.Rep, Elem, Before);
48   end Insert;
49
50   procedure Append (C : in out Collection; Elem : Item) is
51   begin
52      Collection_Nodes.Append (C.Rep, Elem);
53   end Append;
54
55   procedure Append (C : in out Collection;
56                     Elem : Item;
57                     After : Positive) is
58   begin
59      Collection_Nodes.Append (C.Rep, Elem, After);
60   end Append;
61
62   procedure Remove (C : in out Collection; At_Index : Positive) is
63   begin
64      Collection_Nodes.Remove (C.Rep, At_Index);
65   end Remove;
66
67   procedure Replace (C : in out Collection;
68                      At_Index : Positive;
69                      Elem : Item) is
70   begin
71      Collection_Nodes.Replace (C.Rep, At_Index, Elem);
72   end Replace;
73
74   function Length (C : Collection) return Natural is
75   begin
76      return Collection_Nodes.Length (C.Rep);
77   end Length;
78
79   function Is_Empty (C : Collection) return Boolean is
80   begin
81      return Collection_Nodes.Length (C.Rep) = 0;
82   end Is_Empty;
83
84   function First (C : Collection) return Item is
85   begin
86      return Collection_Nodes.First (C.Rep);
87   end First;
88
89   function Last (C : Collection) return Item is
90   begin
91      return Collection_Nodes.Last (C.Rep);
92   end Last;
93
94   function Item_At
95     (C : Collection; At_Index : Positive) return Item is
96   begin
97      return Item_At (C, At_Index).all;
98   end Item_At;
99
100   function Location (C : Collection; Elem : Item) return Natural is
101   begin
102      return Collection_Nodes.Location (C.Rep, Elem);
103   end Location;
104
105   package Address_Conversions
106   is new System.Address_To_Access_Conversions (Collection);
107
108   function New_Iterator
109     (For_The_Collection : Collection) return Iterator'Class is
110      Result : Collection_Iterator;
111   begin
112      Result.For_The_Container :=
113        Container_Ptr (Address_Conversions.To_Pointer
114                         (For_The_Collection'Address));
115      Reset (Result);
116      return Result;
117   end New_Iterator;
118
119   function Item_At
120     (C : Collection; Index : Positive) return Item_Ptr is
121   begin
122      return Collection_Nodes.Item_At (C.Rep, Index);
123   end Item_At;
124
125   function Null_Container return Collection is
126      Empty_Container : Collection;
127      pragma Warnings (Off, Empty_Container);
128   begin
129      return Empty_Container;
130   end Null_Container;
131
132end BC.Containers.Collections.Unmanaged;
133