1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.FORMAL_INDEFINITE_VECTORS --
9 -- Copyright (C) 2014, Free Software Foundation, Inc. --
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. --
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. --
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
31 pragma Annotate (CodePeer, Skip_Analysis);
33 function H (New_Item : Element_Type) return Holder renames To_Holder;
34 function E (Container : Holder) return Element_Type renames Get;
40 function "=" (Left, Right : Vector) return Boolean is
47 procedure Append (Container : in out Vector; New_Item : Vector) is
49 Append (Container.V, New_Item.V);
53 (Container : in out Vector;
54 New_Item : Element_Type)
57 Append (Container.V, H (New_Item));
64 procedure Assign (Target : in out Vector; Source : Vector) is
66 Assign (Target.V, Source.V);
73 function Capacity (Container : Vector) return Capacity_Range is
74 (Capacity (Container.V));
80 procedure Clear (Container : in out Vector) is
91 Item : Element_Type) return Boolean
93 (Contains (Container.V, H (Item)));
101 Capacity : Capacity_Range := 0) return Vector
103 ((if Capacity = 0 then Length (Source) else Capacity),
104 V => Copy (Source.V, Capacity));
106 ---------------------
107 -- Current_To_Last --
108 ---------------------
110 function Current_To_Last
112 Current : Index_Type) return Vector is
114 return (Length (Container), Current_To_Last (Container.V, Current));
121 procedure Delete_Last
122 (Container : in out Vector)
125 Delete_Last (Container.V);
134 Index : Index_Type) return Element_Type is
135 (E (Element (Container.V, Index)));
144 Index : Index_Type := Index_Type'First) return Extended_Index
146 (Find_Index (Container.V, H (Item), Index));
152 function First_Element (Container : Vector) return Element_Type is
153 (E (First_Element (Container.V)));
159 function First_Index (Container : Vector) return Index_Type is
160 (First_Index (Container.V));
162 -----------------------
163 -- First_To_Previous --
164 -----------------------
166 function First_To_Previous
168 Current : Index_Type) return Vector is
170 return (Length (Container), First_To_Previous (Container.V, Current));
171 end First_To_Previous;
173 ---------------------
174 -- Generic_Sorting --
175 ---------------------
177 package body Generic_Sorting is
179 function "<" (X, Y : Holder) return Boolean is (E (X) < E (Y));
180 package Def_Sorting is new Def.Generic_Sorting ("<");
187 function Is_Sorted (Container : Vector) return Boolean is
188 (Is_Sorted (Container.V));
194 procedure Sort (Container : in out Vector) is
207 Position : Extended_Index) return Boolean
209 (Has_Element (Container.V, Position));
215 function Is_Empty (Container : Vector) return Boolean is
216 (Is_Empty (Container.V));
222 function Last_Element (Container : Vector) return Element_Type is
223 (E (Last_Element (Container.V)));
229 function Last_Index (Container : Vector) return Extended_Index is
230 (Last_Index (Container.V));
236 function Length (Container : Vector) return Capacity_Range is
237 (Length (Container.V));
239 ---------------------
240 -- Replace_Element --
241 ---------------------
243 procedure Replace_Element
244 (Container : in out Vector;
246 New_Item : Element_Type)
249 Replace_Element (Container.V, Index, H (New_Item));
252 ----------------------
253 -- Reserve_Capacity --
254 ----------------------
256 procedure Reserve_Capacity
257 (Container : in out Vector;
258 Capacity : Capacity_Range)
261 Reserve_Capacity (Container.V, Capacity);
262 end Reserve_Capacity;
264 ----------------------
265 -- Reverse_Elements --
266 ----------------------
268 procedure Reverse_Elements (Container : in out Vector) is
270 Reverse_Elements (Container.V);
271 end Reverse_Elements;
273 ------------------------
274 -- Reverse_Find_Index --
275 ------------------------
277 function Reverse_Find_Index
280 Index : Index_Type := Index_Type'Last) return Extended_Index
282 (Reverse_Find_Index (Container.V, H (Item), Index));
288 procedure Swap (Container : in out Vector; I, J : Index_Type) is
290 Swap (Container.V, I, J);
298 (New_Item : Element_Type;
299 Length : Capacity_Range) return Vector
302 return (Length, To_Vector (H (New_Item), Length));
305 end Ada.Containers.Formal_Indefinite_Vectors;