]>
Commit | Line | Data |
---|---|---|
c59936c4 | 1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT LIBRARY COMPONENTS -- | |
4 | -- -- | |
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 -- | |
7 | -- -- | |
8 | -- B o d y -- | |
9 | -- -- | |
10 | -- Copyright (C) 2014, Free Software Foundation, Inc. -- | |
11 | -- -- | |
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. -- | |
18 | -- -- | |
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. -- | |
22 | -- -- | |
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 | ------------------------------------------------------------------------------ | |
28 | ||
987bbd0d | 29 | package body Ada.Containers.Formal_Indefinite_Vectors with |
30 | SPARK_Mode => Off | |
31 | is | |
2be1f7d7 | 32 | pragma Annotate (CodePeer, Skip_Analysis); |
c59936c4 | 33 | |
34 | function H (New_Item : Element_Type) return Holder renames To_Holder; | |
35 | function E (Container : Holder) return Element_Type renames Get; | |
36 | ||
37 | --------- | |
38 | -- "=" -- | |
39 | --------- | |
40 | ||
41 | function "=" (Left, Right : Vector) return Boolean is | |
42 | (Left.V = Right.V); | |
43 | ||
44 | ------------ | |
45 | -- Append -- | |
46 | ------------ | |
47 | ||
48 | procedure Append (Container : in out Vector; New_Item : Vector) is | |
49 | begin | |
50 | Append (Container.V, New_Item.V); | |
51 | end Append; | |
52 | ||
53 | procedure Append | |
54 | (Container : in out Vector; | |
55 | New_Item : Element_Type) | |
56 | is | |
57 | begin | |
58 | Append (Container.V, H (New_Item)); | |
59 | end Append; | |
60 | ||
61 | ------------ | |
62 | -- Assign -- | |
63 | ------------ | |
64 | ||
65 | procedure Assign (Target : in out Vector; Source : Vector) is | |
66 | begin | |
67 | Assign (Target.V, Source.V); | |
68 | end Assign; | |
69 | ||
70 | -------------- | |
71 | -- Capacity -- | |
72 | -------------- | |
73 | ||
74 | function Capacity (Container : Vector) return Capacity_Range is | |
75 | (Capacity (Container.V)); | |
76 | ||
77 | ----------- | |
78 | -- Clear -- | |
79 | ----------- | |
80 | ||
81 | procedure Clear (Container : in out Vector) is | |
82 | begin | |
83 | Clear (Container.V); | |
84 | end Clear; | |
85 | ||
86 | -------------- | |
87 | -- Contains -- | |
88 | -------------- | |
89 | ||
90 | function Contains | |
91 | (Container : Vector; | |
92 | Item : Element_Type) return Boolean is | |
93 | (Contains (Container.V, H (Item))); | |
94 | ||
95 | ---------- | |
96 | -- Copy -- | |
97 | ---------- | |
98 | ||
99 | function Copy | |
100 | (Source : Vector; | |
101 | Capacity : Capacity_Range := 0) return Vector is | |
102 | (Capacity, V => Copy (Source.V, Capacity)); | |
103 | ||
104 | --------------------- | |
105 | -- Current_To_Last -- | |
106 | --------------------- | |
107 | ||
108 | function Current_To_Last | |
109 | (Container : Vector; | |
110 | Current : Index_Type) return Vector is | |
111 | begin | |
112 | return (Length (Container), Current_To_Last (Container.V, Current)); | |
113 | end Current_To_Last; | |
114 | ||
115 | ----------------- | |
116 | -- Delete_Last -- | |
117 | ----------------- | |
118 | ||
119 | procedure Delete_Last | |
120 | (Container : in out Vector) | |
121 | is | |
122 | begin | |
123 | Delete_Last (Container.V); | |
124 | end Delete_Last; | |
125 | ||
126 | ------------- | |
127 | -- Element -- | |
128 | ------------- | |
129 | ||
130 | function Element | |
131 | (Container : Vector; | |
132 | Index : Index_Type) return Element_Type is | |
133 | (E (Element (Container.V, Index))); | |
134 | ||
135 | ---------------- | |
136 | -- Find_Index -- | |
137 | ---------------- | |
138 | ||
139 | function Find_Index | |
140 | (Container : Vector; | |
141 | Item : Element_Type; | |
142 | Index : Index_Type := Index_Type'First) return Extended_Index is | |
143 | (Find_Index (Container.V, H (Item), Index)); | |
144 | ||
145 | ------------------- | |
146 | -- First_Element -- | |
147 | ------------------- | |
148 | ||
149 | function First_Element (Container : Vector) return Element_Type is | |
150 | (E (First_Element (Container.V))); | |
151 | ||
152 | ----------------- | |
153 | -- First_Index -- | |
154 | ----------------- | |
155 | ||
156 | function First_Index (Container : Vector) return Index_Type is | |
157 | (First_Index (Container.V)); | |
158 | ||
159 | ----------------------- | |
160 | -- First_To_Previous -- | |
161 | ----------------------- | |
162 | ||
163 | function First_To_Previous | |
164 | (Container : Vector; | |
165 | Current : Index_Type) return Vector is | |
166 | begin | |
167 | return (Length (Container), First_To_Previous (Container.V, Current)); | |
168 | end First_To_Previous; | |
169 | ||
170 | --------------------- | |
171 | -- Generic_Sorting -- | |
172 | --------------------- | |
173 | ||
174 | package body Generic_Sorting is | |
175 | ||
176 | function "<" (X, Y : Holder) return Boolean is (E (X) < E (Y)); | |
177 | package Def_Sorting is new Def.Generic_Sorting ("<"); | |
178 | use Def_Sorting; | |
179 | ||
180 | --------------- | |
181 | -- Is_Sorted -- | |
182 | --------------- | |
183 | ||
184 | function Is_Sorted (Container : Vector) return Boolean is | |
185 | (Is_Sorted (Container.V)); | |
186 | ||
187 | ---------- | |
188 | -- Sort -- | |
189 | ---------- | |
190 | ||
191 | procedure Sort (Container : in out Vector) is | |
192 | begin | |
193 | Sort (Container.V); | |
194 | end Sort; | |
195 | ||
196 | end Generic_Sorting; | |
197 | ||
198 | ----------------- | |
199 | -- Has_Element -- | |
200 | ----------------- | |
201 | ||
202 | function Has_Element | |
203 | (Container : Vector; Position : Extended_Index) return Boolean is | |
204 | (Has_Element (Container.V, Position)); | |
205 | ||
206 | -------------- | |
207 | -- Is_Empty -- | |
208 | -------------- | |
209 | ||
210 | function Is_Empty (Container : Vector) return Boolean is | |
211 | (Is_Empty (Container.V)); | |
212 | ||
213 | ------------------ | |
214 | -- Last_Element -- | |
215 | ------------------ | |
216 | ||
217 | function Last_Element (Container : Vector) return Element_Type is | |
218 | (E (Last_Element (Container.V))); | |
219 | ||
220 | ---------------- | |
221 | -- Last_Index -- | |
222 | ---------------- | |
223 | ||
224 | function Last_Index (Container : Vector) return Extended_Index is | |
225 | (Last_Index (Container.V)); | |
226 | ||
227 | ------------ | |
228 | -- Length -- | |
229 | ------------ | |
230 | ||
231 | function Length (Container : Vector) return Capacity_Range is | |
232 | (Length (Container.V)); | |
233 | ||
234 | --------------------- | |
235 | -- Replace_Element -- | |
236 | --------------------- | |
237 | ||
238 | procedure Replace_Element | |
239 | (Container : in out Vector; | |
240 | Index : Index_Type; | |
241 | New_Item : Element_Type) | |
242 | is | |
243 | begin | |
244 | Replace_Element (Container.V, Index, H (New_Item)); | |
245 | end Replace_Element; | |
246 | ||
247 | ---------------------- | |
248 | -- Reserve_Capacity -- | |
249 | ---------------------- | |
250 | ||
251 | procedure Reserve_Capacity | |
252 | (Container : in out Vector; | |
253 | Capacity : Capacity_Range) | |
254 | is | |
255 | begin | |
256 | Reserve_Capacity (Container.V, Capacity); | |
257 | end Reserve_Capacity; | |
258 | ||
259 | ---------------------- | |
260 | -- Reverse_Elements -- | |
261 | ---------------------- | |
262 | ||
263 | procedure Reverse_Elements (Container : in out Vector) is | |
264 | begin | |
265 | Reverse_Elements (Container.V); | |
266 | end Reverse_Elements; | |
267 | ||
268 | ------------------------ | |
269 | -- Reverse_Find_Index -- | |
270 | ------------------------ | |
271 | ||
272 | function Reverse_Find_Index | |
273 | (Container : Vector; | |
274 | Item : Element_Type; | |
275 | Index : Index_Type := Index_Type'Last) return Extended_Index is | |
276 | (Reverse_Find_Index (Container.V, H (Item), Index)); | |
277 | ||
278 | ---------- | |
279 | -- Swap -- | |
280 | ---------- | |
281 | ||
282 | procedure Swap (Container : in out Vector; I, J : Index_Type) is | |
283 | begin | |
284 | Swap (Container.V, I, J); | |
285 | end Swap; | |
286 | ||
287 | --------------- | |
288 | -- To_Vector -- | |
289 | --------------- | |
290 | ||
291 | function To_Vector | |
292 | (New_Item : Element_Type; | |
293 | Length : Capacity_Range) return Vector is | |
294 | begin | |
295 | return (Length, To_Vector (H (New_Item), Length)); | |
296 | end To_Vector; | |
297 | ||
298 | end Ada.Containers.Formal_Indefinite_Vectors; |