1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
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 --
10 -- Copyright (C) 2014, Free Software Foundation, Inc. --
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. --
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. --
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 with
32 pragma Annotate (CodePeer, Skip_Analysis);
34 function H (New_Item : Element_Type) return Holder renames To_Holder;
35 function E (Container : Holder) return Element_Type renames Get;
41 function "=" (Left, Right : Vector) return Boolean is
48 procedure Append (Container : in out Vector; New_Item : Vector) is
50 Append (Container.V, New_Item.V);
54 (Container : in out Vector;
55 New_Item : Element_Type)
58 Append (Container.V, H (New_Item));
65 procedure Assign (Target : in out Vector; Source : Vector) is
67 Assign (Target.V, Source.V);
74 function Capacity (Container : Vector) return Capacity_Range is
75 (Capacity (Container.V));
81 procedure Clear (Container : in out Vector) is
92 Item : Element_Type) return Boolean is
93 (Contains (Container.V, H (Item)));
101 Capacity : Capacity_Range := 0) return Vector is
102 (Capacity, V => Copy (Source.V, Capacity));
104 ---------------------
105 -- Current_To_Last --
106 ---------------------
108 function Current_To_Last
110 Current : Index_Type) return Vector is
112 return (Length (Container), Current_To_Last (Container.V, Current));
119 procedure Delete_Last
120 (Container : in out Vector)
123 Delete_Last (Container.V);
132 Index : Index_Type) return Element_Type is
133 (E (Element (Container.V, Index)));
142 Index : Index_Type := Index_Type'First) return Extended_Index is
143 (Find_Index (Container.V, H (Item), Index));
149 function First_Element (Container : Vector) return Element_Type is
150 (E (First_Element (Container.V)));
156 function First_Index (Container : Vector) return Index_Type is
157 (First_Index (Container.V));
159 -----------------------
160 -- First_To_Previous --
161 -----------------------
163 function First_To_Previous
165 Current : Index_Type) return Vector is
167 return (Length (Container), First_To_Previous (Container.V, Current));
168 end First_To_Previous;
170 ---------------------
171 -- Generic_Sorting --
172 ---------------------
174 package body Generic_Sorting is
176 function "<" (X, Y : Holder) return Boolean is (E (X) < E (Y));
177 package Def_Sorting is new Def.Generic_Sorting ("<");
184 function Is_Sorted (Container : Vector) return Boolean is
185 (Is_Sorted (Container.V));
191 procedure Sort (Container : in out Vector) is
203 (Container : Vector; Position : Extended_Index) return Boolean is
204 (Has_Element (Container.V, Position));
210 function Is_Empty (Container : Vector) return Boolean is
211 (Is_Empty (Container.V));
217 function Last_Element (Container : Vector) return Element_Type is
218 (E (Last_Element (Container.V)));
224 function Last_Index (Container : Vector) return Extended_Index is
225 (Last_Index (Container.V));
231 function Length (Container : Vector) return Capacity_Range is
232 (Length (Container.V));
234 ---------------------
235 -- Replace_Element --
236 ---------------------
238 procedure Replace_Element
239 (Container : in out Vector;
241 New_Item : Element_Type)
244 Replace_Element (Container.V, Index, H (New_Item));
247 ----------------------
248 -- Reserve_Capacity --
249 ----------------------
251 procedure Reserve_Capacity
252 (Container : in out Vector;
253 Capacity : Capacity_Range)
256 Reserve_Capacity (Container.V, Capacity);
257 end Reserve_Capacity;
259 ----------------------
260 -- Reverse_Elements --
261 ----------------------
263 procedure Reverse_Elements (Container : in out Vector) is
265 Reverse_Elements (Container.V);
266 end Reverse_Elements;
268 ------------------------
269 -- Reverse_Find_Index --
270 ------------------------
272 function Reverse_Find_Index
275 Index : Index_Type := Index_Type'Last) return Extended_Index is
276 (Reverse_Find_Index (Container.V, H (Item), Index));
282 procedure Swap (Container : in out Vector; I, J : Index_Type) is
284 Swap (Container.V, I, J);
292 (New_Item : Element_Type;
293 Length : Capacity_Range) return Vector is
295 return (Length, To_Vector (H (New_Item), Length));
298 end Ada.Containers.Formal_Indefinite_Vectors;