1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- ADA.CONTAINERS.FORMAL_INDEFINITE_VECTORS --
9 -- Copyright (C) 2014-2015, 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
32 function H
(New_Item
: Element_Type
) return Holder
renames To_Holder
;
33 function E
(Container
: Holder
) return Element_Type
renames Get
;
39 function "=" (Left
, Right
: Vector
) return Boolean is
46 procedure Append
(Container
: in out Vector
; New_Item
: Vector
) is
48 Append
(Container
.V
, New_Item
.V
);
52 (Container
: in out Vector
;
53 New_Item
: Element_Type
)
56 Append
(Container
.V
, H
(New_Item
));
63 procedure Assign
(Target
: in out Vector
; Source
: Vector
) is
65 Assign
(Target
.V
, Source
.V
);
72 function Capacity
(Container
: Vector
) return Capacity_Range
is
73 (Capacity
(Container
.V
));
79 procedure Clear
(Container
: in out Vector
) is
90 Item
: Element_Type
) return Boolean
92 (Contains
(Container
.V
, H
(Item
)));
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
111 Current
: Index_Type
) return Vector
is
113 return (Length
(Container
), Current_To_Last
(Container
.V
, Current
));
120 procedure Delete_Last
121 (Container
: in out Vector
)
124 Delete_Last
(Container
.V
);
133 Index
: Index_Type
) return Element_Type
is
134 (E
(Element
(Container
.V
, Index
)));
143 Index
: Index_Type
:= Index_Type
'First) return Extended_Index
145 (Find_Index
(Container
.V
, H
(Item
), Index
));
151 function First_Element
(Container
: Vector
) return Element_Type
is
152 (E
(First_Element
(Container
.V
)));
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
167 Current
: Index_Type
) return Vector
is
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
("<");
186 function Is_Sorted
(Container
: Vector
) return Boolean is
187 (Is_Sorted
(Container
.V
));
193 procedure Sort
(Container
: in out Vector
) is
206 Position
: Extended_Index
) return Boolean
208 (Has_Element
(Container
.V
, Position
));
214 function Is_Empty
(Container
: Vector
) return Boolean is
215 (Is_Empty
(Container
.V
));
221 function Last_Element
(Container
: Vector
) return Element_Type
is
222 (E
(Last_Element
(Container
.V
)));
228 function Last_Index
(Container
: Vector
) return Extended_Index
is
229 (Last_Index
(Container
.V
));
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
;
245 New_Item
: Element_Type
)
248 Replace_Element
(Container
.V
, Index
, H
(New_Item
));
251 ----------------------
252 -- Reserve_Capacity --
253 ----------------------
255 procedure Reserve_Capacity
256 (Container
: in out Vector
;
257 Capacity
: Capacity_Range
)
260 Reserve_Capacity
(Container
.V
, Capacity
);
261 end Reserve_Capacity
;
263 ----------------------
264 -- Reverse_Elements --
265 ----------------------
267 procedure Reverse_Elements
(Container
: in out Vector
) is
269 Reverse_Elements
(Container
.V
);
270 end Reverse_Elements
;
272 ------------------------
273 -- Reverse_Find_Index --
274 ------------------------
276 function Reverse_Find_Index
279 Index
: Index_Type
:= Index_Type
'Last) return Extended_Index
281 (Reverse_Find_Index
(Container
.V
, H
(Item
), Index
));
287 procedure Swap
(Container
: in out Vector
; I
, J
: Index_Type
) is
289 Swap
(Container
.V
, I
, J
);
297 (New_Item
: Element_Type
;
298 Length
: Capacity_Range
) return Vector
301 return (Length
, To_Vector
(H
(New_Item
), Length
));
304 end Ada
.Containers
.Formal_Indefinite_Vectors
;