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
is
31 function H
(New_Item
: Element_Type
) return Holder
renames To_Holder
;
32 function E
(Container
: Holder
) return Element_Type
renames Get
;
38 function "=" (Left
, Right
: Vector
) return Boolean is
45 procedure Append
(Container
: in out Vector
; New_Item
: Vector
) is
47 Append
(Container
.V
, New_Item
.V
);
51 (Container
: in out Vector
;
52 New_Item
: Element_Type
)
55 Append
(Container
.V
, H
(New_Item
));
62 procedure Assign
(Target
: in out Vector
; Source
: Vector
) is
64 Assign
(Target
.V
, Source
.V
);
71 function Capacity
(Container
: Vector
) return Capacity_Range
is
72 (Capacity
(Container
.V
));
78 procedure Clear
(Container
: in out Vector
) is
89 Item
: Element_Type
) return Boolean is
90 (Contains
(Container
.V
, H
(Item
)));
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
107 Current
: Index_Type
) return Vector
is
109 return (Length
(Container
), Current_To_Last
(Container
.V
, Current
));
116 procedure Delete_Last
117 (Container
: in out Vector
)
120 Delete_Last
(Container
.V
);
129 Index
: Index_Type
) return Element_Type
is
130 (E
(Element
(Container
.V
, Index
)));
139 Index
: Index_Type
:= Index_Type
'First) return Extended_Index
is
140 (Find_Index
(Container
.V
, H
(Item
), Index
));
146 function First_Element
(Container
: Vector
) return Element_Type
is
147 (E
(First_Element
(Container
.V
)));
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
162 Current
: Index_Type
) return Vector
is
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
("<");
181 function Is_Sorted
(Container
: Vector
) return Boolean is
182 (Is_Sorted
(Container
.V
));
188 procedure Sort
(Container
: in out Vector
) is
200 (Container
: Vector
; Position
: Extended_Index
) return Boolean is
201 (Has_Element
(Container
.V
, Position
));
207 function Is_Empty
(Container
: Vector
) return Boolean is
208 (Is_Empty
(Container
.V
));
214 function Last_Element
(Container
: Vector
) return Element_Type
is
215 (E
(Last_Element
(Container
.V
)));
221 function Last_Index
(Container
: Vector
) return Extended_Index
is
222 (Last_Index
(Container
.V
));
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
;
238 New_Item
: Element_Type
)
241 Replace_Element
(Container
.V
, Index
, H
(New_Item
));
244 ----------------------
245 -- Reserve_Capacity --
246 ----------------------
248 procedure Reserve_Capacity
249 (Container
: in out Vector
;
250 Capacity
: Capacity_Range
)
253 Reserve_Capacity
(Container
.V
, Capacity
);
254 end Reserve_Capacity
;
256 ----------------------
257 -- Reverse_Elements --
258 ----------------------
260 procedure Reverse_Elements
(Container
: in out Vector
) is
262 Reverse_Elements
(Container
.V
);
263 end Reverse_Elements
;
265 ------------------------
266 -- Reverse_Find_Index --
267 ------------------------
269 function Reverse_Find_Index
272 Index
: Index_Type
:= Index_Type
'Last) return Extended_Index
is
273 (Reverse_Find_Index
(Container
.V
, H
(Item
), Index
));
279 procedure Swap
(Container
: in out Vector
; I
, J
: Index_Type
) is
281 Swap
(Container
.V
, I
, J
);
289 (New_Item
: Element_Type
;
290 Length
: Capacity_Range
) return Vector
is
292 return (Length
, To_Vector
(H
(New_Item
), Length
));
295 end Ada
.Containers
.Formal_Indefinite_Vectors
;