Update ChangeLog and version files for release
[official-gcc.git] / gcc / ada / a-cfinve.adb
blobb520d65f020975be743fcf526e34914e752f718d
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.FORMAL_INDEFINITE_VECTORS --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 2014-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 ------------------------------------------------------------------------------
28 package body Ada.Containers.Formal_Indefinite_Vectors with
29 SPARK_Mode => Off
32 function H (New_Item : Element_Type) return Holder renames To_Holder;
33 function E (Container : Holder) return Element_Type renames Get;
35 ---------
36 -- "=" --
37 ---------
39 function "=" (Left, Right : Vector) return Boolean is
40 (Left.V = Right.V);
42 ------------
43 -- Append --
44 ------------
46 procedure Append (Container : in out Vector; New_Item : Vector) is
47 begin
48 Append (Container.V, New_Item.V);
49 end Append;
51 procedure Append
52 (Container : in out Vector;
53 New_Item : Element_Type)
55 begin
56 Append (Container.V, H (New_Item));
57 end Append;
59 ------------
60 -- Assign --
61 ------------
63 procedure Assign (Target : in out Vector; Source : Vector) is
64 begin
65 Assign (Target.V, Source.V);
66 end Assign;
68 --------------
69 -- Capacity --
70 --------------
72 function Capacity (Container : Vector) return Capacity_Range is
73 (Capacity (Container.V));
75 -----------
76 -- Clear --
77 -----------
79 procedure Clear (Container : in out Vector) is
80 begin
81 Clear (Container.V);
82 end Clear;
84 --------------
85 -- Contains --
86 --------------
88 function Contains
89 (Container : Vector;
90 Item : Element_Type) return Boolean
92 (Contains (Container.V, H (Item)));
94 ----------
95 -- Copy --
96 ----------
98 function Copy
99 (Source : Vector;
100 Capacity : Capacity_Range := 0) return Vector
102 ((if Capacity = 0 then Length (Source) else Capacity),
103 V => Copy (Source.V, Capacity));
105 ---------------------
106 -- Current_To_Last --
107 ---------------------
109 function Current_To_Last
110 (Container : Vector;
111 Current : Index_Type) return Vector is
112 begin
113 return (Length (Container), Current_To_Last (Container.V, Current));
114 end Current_To_Last;
116 -----------------
117 -- Delete_Last --
118 -----------------
120 procedure Delete_Last
121 (Container : in out Vector)
123 begin
124 Delete_Last (Container.V);
125 end Delete_Last;
127 -------------
128 -- Element --
129 -------------
131 function Element
132 (Container : Vector;
133 Index : Index_Type) return Element_Type is
134 (E (Element (Container.V, Index)));
136 ----------------
137 -- Find_Index --
138 ----------------
140 function Find_Index
141 (Container : Vector;
142 Item : Element_Type;
143 Index : Index_Type := Index_Type'First) return Extended_Index
145 (Find_Index (Container.V, H (Item), Index));
147 -------------------
148 -- First_Element --
149 -------------------
151 function First_Element (Container : Vector) return Element_Type is
152 (E (First_Element (Container.V)));
154 -----------------
155 -- First_Index --
156 -----------------
158 function First_Index (Container : Vector) return Index_Type is
159 (First_Index (Container.V));
161 -----------------------
162 -- First_To_Previous --
163 -----------------------
165 function First_To_Previous
166 (Container : Vector;
167 Current : Index_Type) return Vector is
168 begin
169 return (Length (Container), First_To_Previous (Container.V, Current));
170 end First_To_Previous;
172 ---------------------
173 -- Generic_Sorting --
174 ---------------------
176 package body Generic_Sorting with SPARK_Mode => Off is
178 function "<" (X, Y : Holder) return Boolean is (E (X) < E (Y));
179 package Def_Sorting is new Def.Generic_Sorting ("<");
180 use Def_Sorting;
182 ---------------
183 -- Is_Sorted --
184 ---------------
186 function Is_Sorted (Container : Vector) return Boolean is
187 (Is_Sorted (Container.V));
189 ----------
190 -- Sort --
191 ----------
193 procedure Sort (Container : in out Vector) is
194 begin
195 Sort (Container.V);
196 end Sort;
198 end Generic_Sorting;
200 -----------------
201 -- Has_Element --
202 -----------------
204 function Has_Element
205 (Container : Vector;
206 Position : Extended_Index) return Boolean
208 (Has_Element (Container.V, Position));
210 --------------
211 -- Is_Empty --
212 --------------
214 function Is_Empty (Container : Vector) return Boolean is
215 (Is_Empty (Container.V));
217 ------------------
218 -- Last_Element --
219 ------------------
221 function Last_Element (Container : Vector) return Element_Type is
222 (E (Last_Element (Container.V)));
224 ----------------
225 -- Last_Index --
226 ----------------
228 function Last_Index (Container : Vector) return Extended_Index is
229 (Last_Index (Container.V));
231 ------------
232 -- Length --
233 ------------
235 function Length (Container : Vector) return Capacity_Range is
236 (Length (Container.V));
238 ---------------------
239 -- Replace_Element --
240 ---------------------
242 procedure Replace_Element
243 (Container : in out Vector;
244 Index : Index_Type;
245 New_Item : Element_Type)
247 begin
248 Replace_Element (Container.V, Index, H (New_Item));
249 end Replace_Element;
251 ----------------------
252 -- Reserve_Capacity --
253 ----------------------
255 procedure Reserve_Capacity
256 (Container : in out Vector;
257 Capacity : Capacity_Range)
259 begin
260 Reserve_Capacity (Container.V, Capacity);
261 end Reserve_Capacity;
263 ----------------------
264 -- Reverse_Elements --
265 ----------------------
267 procedure Reverse_Elements (Container : in out Vector) is
268 begin
269 Reverse_Elements (Container.V);
270 end Reverse_Elements;
272 ------------------------
273 -- Reverse_Find_Index --
274 ------------------------
276 function Reverse_Find_Index
277 (Container : Vector;
278 Item : Element_Type;
279 Index : Index_Type := Index_Type'Last) return Extended_Index
281 (Reverse_Find_Index (Container.V, H (Item), Index));
283 ----------
284 -- Swap --
285 ----------
287 procedure Swap (Container : in out Vector; I, J : Index_Type) is
288 begin
289 Swap (Container.V, I, J);
290 end Swap;
292 ---------------
293 -- To_Vector --
294 ---------------
296 function To_Vector
297 (New_Item : Element_Type;
298 Length : Capacity_Range) return Vector
300 begin
301 return (Length, To_Vector (H (New_Item), Length));
302 end To_Vector;
304 end Ada.Containers.Formal_Indefinite_Vectors;