2014-10-31 Hristian Kirtchev <kirtchev@adacore.com>
[official-gcc.git] / gcc / ada / a-cfinve.adb
blob793b5c3922f6848c7d0e82c1cd50e306c717da82
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S
6 -- . F O R M A L _ I N D E F I N I T E _ V E C T O R S --
7 -- --
8 -- B o d y --
9 -- --
10 -- Copyright (C) 2014, Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 3, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- --
19 -- As a special exception under Section 7 of GPL version 3, you are granted --
20 -- additional permissions described in the GCC Runtime Library Exception, --
21 -- version 3.1, as published by the Free Software Foundation. --
22 -- --
23 -- You should have received a copy of the GNU General Public License and --
24 -- a copy of the GCC Runtime Library Exception along with this program; --
25 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
26 -- <http://www.gnu.org/licenses/>. --
27 ------------------------------------------------------------------------------
29 package body Ada.Containers.Formal_Indefinite_Vectors is
31 function H (New_Item : Element_Type) return Holder renames To_Holder;
32 function E (Container : Holder) return Element_Type renames Get;
34 ---------
35 -- "=" --
36 ---------
38 function "=" (Left, Right : Vector) return Boolean is
39 (Left.V = Right.V);
41 ------------
42 -- Append --
43 ------------
45 procedure Append (Container : in out Vector; New_Item : Vector) is
46 begin
47 Append (Container.V, New_Item.V);
48 end Append;
50 procedure Append
51 (Container : in out Vector;
52 New_Item : Element_Type)
54 begin
55 Append (Container.V, H (New_Item));
56 end Append;
58 ------------
59 -- Assign --
60 ------------
62 procedure Assign (Target : in out Vector; Source : Vector) is
63 begin
64 Assign (Target.V, Source.V);
65 end Assign;
67 --------------
68 -- Capacity --
69 --------------
71 function Capacity (Container : Vector) return Capacity_Range is
72 (Capacity (Container.V));
74 -----------
75 -- Clear --
76 -----------
78 procedure Clear (Container : in out Vector) is
79 begin
80 Clear (Container.V);
81 end Clear;
83 --------------
84 -- Contains --
85 --------------
87 function Contains
88 (Container : Vector;
89 Item : Element_Type) return Boolean is
90 (Contains (Container.V, H (Item)));
92 ----------
93 -- Copy --
94 ----------
96 function Copy
97 (Source : Vector;
98 Capacity : Capacity_Range := 0) return Vector is
99 (Capacity, V => Copy (Source.V, Capacity));
101 ---------------------
102 -- Current_To_Last --
103 ---------------------
105 function Current_To_Last
106 (Container : Vector;
107 Current : Index_Type) return Vector is
108 begin
109 return (Length (Container), Current_To_Last (Container.V, Current));
110 end Current_To_Last;
112 -----------------
113 -- Delete_Last --
114 -----------------
116 procedure Delete_Last
117 (Container : in out Vector)
119 begin
120 Delete_Last (Container.V);
121 end Delete_Last;
123 -------------
124 -- Element --
125 -------------
127 function Element
128 (Container : Vector;
129 Index : Index_Type) return Element_Type is
130 (E (Element (Container.V, Index)));
132 ----------------
133 -- Find_Index --
134 ----------------
136 function Find_Index
137 (Container : Vector;
138 Item : Element_Type;
139 Index : Index_Type := Index_Type'First) return Extended_Index is
140 (Find_Index (Container.V, H (Item), Index));
142 -------------------
143 -- First_Element --
144 -------------------
146 function First_Element (Container : Vector) return Element_Type is
147 (E (First_Element (Container.V)));
149 -----------------
150 -- First_Index --
151 -----------------
153 function First_Index (Container : Vector) return Index_Type is
154 (First_Index (Container.V));
156 -----------------------
157 -- First_To_Previous --
158 -----------------------
160 function First_To_Previous
161 (Container : Vector;
162 Current : Index_Type) return Vector is
163 begin
164 return (Length (Container), First_To_Previous (Container.V, Current));
165 end First_To_Previous;
167 ---------------------
168 -- Generic_Sorting --
169 ---------------------
171 package body Generic_Sorting is
173 function "<" (X, Y : Holder) return Boolean is (E (X) < E (Y));
174 package Def_Sorting is new Def.Generic_Sorting ("<");
175 use Def_Sorting;
177 ---------------
178 -- Is_Sorted --
179 ---------------
181 function Is_Sorted (Container : Vector) return Boolean is
182 (Is_Sorted (Container.V));
184 ----------
185 -- Sort --
186 ----------
188 procedure Sort (Container : in out Vector) is
189 begin
190 Sort (Container.V);
191 end Sort;
193 end Generic_Sorting;
195 -----------------
196 -- Has_Element --
197 -----------------
199 function Has_Element
200 (Container : Vector; Position : Extended_Index) return Boolean is
201 (Has_Element (Container.V, Position));
203 --------------
204 -- Is_Empty --
205 --------------
207 function Is_Empty (Container : Vector) return Boolean is
208 (Is_Empty (Container.V));
210 ------------------
211 -- Last_Element --
212 ------------------
214 function Last_Element (Container : Vector) return Element_Type is
215 (E (Last_Element (Container.V)));
217 ----------------
218 -- Last_Index --
219 ----------------
221 function Last_Index (Container : Vector) return Extended_Index is
222 (Last_Index (Container.V));
224 ------------
225 -- Length --
226 ------------
228 function Length (Container : Vector) return Capacity_Range is
229 (Length (Container.V));
231 ---------------------
232 -- Replace_Element --
233 ---------------------
235 procedure Replace_Element
236 (Container : in out Vector;
237 Index : Index_Type;
238 New_Item : Element_Type)
240 begin
241 Replace_Element (Container.V, Index, H (New_Item));
242 end Replace_Element;
244 ----------------------
245 -- Reserve_Capacity --
246 ----------------------
248 procedure Reserve_Capacity
249 (Container : in out Vector;
250 Capacity : Capacity_Range)
252 begin
253 Reserve_Capacity (Container.V, Capacity);
254 end Reserve_Capacity;
256 ----------------------
257 -- Reverse_Elements --
258 ----------------------
260 procedure Reverse_Elements (Container : in out Vector) is
261 begin
262 Reverse_Elements (Container.V);
263 end Reverse_Elements;
265 ------------------------
266 -- Reverse_Find_Index --
267 ------------------------
269 function Reverse_Find_Index
270 (Container : Vector;
271 Item : Element_Type;
272 Index : Index_Type := Index_Type'Last) return Extended_Index is
273 (Reverse_Find_Index (Container.V, H (Item), Index));
275 ----------
276 -- Swap --
277 ----------
279 procedure Swap (Container : in out Vector; I, J : Index_Type) is
280 begin
281 Swap (Container.V, I, J);
282 end Swap;
284 ---------------
285 -- To_Vector --
286 ---------------
288 function To_Vector
289 (New_Item : Element_Type;
290 Length : Capacity_Range) return Vector is
291 begin
292 return (Length, To_Vector (H (New_Item), Length));
293 end To_Vector;
295 end Ada.Containers.Formal_Indefinite_Vectors;