fixing pr42337
[official-gcc.git] / gcc / ada / a-convec.ads
blob4b709659978c5c26937c32ea9b0e087114ca46a9
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . V E C T O R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2008, Free Software Foundation, Inc. --
10 -- --
11 -- This specification is derived from the Ada Reference Manual for use with --
12 -- GNAT. The copyright notice above, and the license provisions that follow --
13 -- apply solely to the contents of the part following the private keyword. --
14 -- --
15 -- GNAT is free software; you can redistribute it and/or modify it under --
16 -- terms of the GNU General Public License as published by the Free Soft- --
17 -- ware Foundation; either version 3, or (at your option) any later ver- --
18 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
19 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
20 -- or FITNESS FOR A PARTICULAR PURPOSE. --
21 -- --
22 -- As a special exception under Section 7 of GPL version 3, you are granted --
23 -- additional permissions described in the GCC Runtime Library Exception, --
24 -- version 3.1, as published by the Free Software Foundation. --
25 -- --
26 -- You should have received a copy of the GNU General Public License and --
27 -- a copy of the GCC Runtime Library Exception along with this program; --
28 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
29 -- <http://www.gnu.org/licenses/>. --
30 -- --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 private with Ada.Finalization;
35 private with Ada.Streams;
37 generic
38 type Index_Type is range <>;
39 type Element_Type is private;
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
43 package Ada.Containers.Vectors is
44 pragma Preelaborate;
45 pragma Remote_Types;
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
49 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
51 No_Index : constant Extended_Index := Extended_Index'First;
53 type Vector is tagged private;
54 pragma Preelaborable_Initialization (Vector);
56 type Cursor is private;
57 pragma Preelaborable_Initialization (Cursor);
59 Empty_Vector : constant Vector;
61 No_Element : constant Cursor;
63 overriding function "=" (Left, Right : Vector) return Boolean;
65 function To_Vector (Length : Count_Type) return Vector;
67 function To_Vector
68 (New_Item : Element_Type;
69 Length : Count_Type) return Vector;
71 function "&" (Left, Right : Vector) return Vector;
73 function "&" (Left : Vector; Right : Element_Type) return Vector;
75 function "&" (Left : Element_Type; Right : Vector) return Vector;
77 function "&" (Left, Right : Element_Type) return Vector;
79 function Capacity (Container : Vector) return Count_Type;
81 procedure Reserve_Capacity
82 (Container : in out Vector;
83 Capacity : Count_Type);
85 function Length (Container : Vector) return Count_Type;
87 procedure Set_Length
88 (Container : in out Vector;
89 Length : Count_Type);
91 function Is_Empty (Container : Vector) return Boolean;
93 procedure Clear (Container : in out Vector);
95 function To_Cursor
96 (Container : Vector;
97 Index : Extended_Index) return Cursor;
99 function To_Index (Position : Cursor) return Extended_Index;
101 function Element
102 (Container : Vector;
103 Index : Index_Type) return Element_Type;
105 function Element (Position : Cursor) return Element_Type;
107 procedure Replace_Element
108 (Container : in out Vector;
109 Index : Index_Type;
110 New_Item : Element_Type);
112 procedure Replace_Element
113 (Container : in out Vector;
114 Position : Cursor;
115 New_Item : Element_Type);
117 procedure Query_Element
118 (Container : Vector;
119 Index : Index_Type;
120 Process : not null access procedure (Element : Element_Type));
122 procedure Query_Element
123 (Position : Cursor;
124 Process : not null access procedure (Element : Element_Type));
126 procedure Update_Element
127 (Container : in out Vector;
128 Index : Index_Type;
129 Process : not null access procedure (Element : in out Element_Type));
131 procedure Update_Element
132 (Container : in out Vector;
133 Position : Cursor;
134 Process : not null access procedure (Element : in out Element_Type));
136 procedure Move (Target : in out Vector; Source : in out Vector);
138 procedure Insert
139 (Container : in out Vector;
140 Before : Extended_Index;
141 New_Item : Vector);
143 procedure Insert
144 (Container : in out Vector;
145 Before : Cursor;
146 New_Item : Vector);
148 procedure Insert
149 (Container : in out Vector;
150 Before : Cursor;
151 New_Item : Vector;
152 Position : out Cursor);
154 procedure Insert
155 (Container : in out Vector;
156 Before : Extended_Index;
157 New_Item : Element_Type;
158 Count : Count_Type := 1);
160 procedure Insert
161 (Container : in out Vector;
162 Before : Cursor;
163 New_Item : Element_Type;
164 Count : Count_Type := 1);
166 procedure Insert
167 (Container : in out Vector;
168 Before : Cursor;
169 New_Item : Element_Type;
170 Position : out Cursor;
171 Count : Count_Type := 1);
173 procedure Insert
174 (Container : in out Vector;
175 Before : Extended_Index;
176 Count : Count_Type := 1);
178 procedure Insert
179 (Container : in out Vector;
180 Before : Cursor;
181 Position : out Cursor;
182 Count : Count_Type := 1);
184 procedure Prepend
185 (Container : in out Vector;
186 New_Item : Vector);
188 procedure Prepend
189 (Container : in out Vector;
190 New_Item : Element_Type;
191 Count : Count_Type := 1);
193 procedure Append
194 (Container : in out Vector;
195 New_Item : Vector);
197 procedure Append
198 (Container : in out Vector;
199 New_Item : Element_Type;
200 Count : Count_Type := 1);
202 procedure Insert_Space
203 (Container : in out Vector;
204 Before : Extended_Index;
205 Count : Count_Type := 1);
207 procedure Insert_Space
208 (Container : in out Vector;
209 Before : Cursor;
210 Position : out Cursor;
211 Count : Count_Type := 1);
213 procedure Delete
214 (Container : in out Vector;
215 Index : Extended_Index;
216 Count : Count_Type := 1);
218 procedure Delete
219 (Container : in out Vector;
220 Position : in out Cursor;
221 Count : Count_Type := 1);
223 procedure Delete_First
224 (Container : in out Vector;
225 Count : Count_Type := 1);
227 procedure Delete_Last
228 (Container : in out Vector;
229 Count : Count_Type := 1);
231 procedure Reverse_Elements (Container : in out Vector);
233 procedure Swap (Container : in out Vector; I, J : Index_Type);
235 procedure Swap (Container : in out Vector; I, J : Cursor);
237 function First_Index (Container : Vector) return Index_Type;
239 function First (Container : Vector) return Cursor;
241 function First_Element (Container : Vector) return Element_Type;
243 function Last_Index (Container : Vector) return Extended_Index;
245 function Last (Container : Vector) return Cursor;
247 function Last_Element (Container : Vector) return Element_Type;
249 function Next (Position : Cursor) return Cursor;
251 procedure Next (Position : in out Cursor);
253 function Previous (Position : Cursor) return Cursor;
255 procedure Previous (Position : in out Cursor);
257 function Find_Index
258 (Container : Vector;
259 Item : Element_Type;
260 Index : Index_Type := Index_Type'First) return Extended_Index;
262 function Find
263 (Container : Vector;
264 Item : Element_Type;
265 Position : Cursor := No_Element) return Cursor;
267 function Reverse_Find_Index
268 (Container : Vector;
269 Item : Element_Type;
270 Index : Index_Type := Index_Type'Last) return Extended_Index;
272 function Reverse_Find
273 (Container : Vector;
274 Item : Element_Type;
275 Position : Cursor := No_Element) return Cursor;
277 function Contains
278 (Container : Vector;
279 Item : Element_Type) return Boolean;
281 function Has_Element (Position : Cursor) return Boolean;
283 procedure Iterate
284 (Container : Vector;
285 Process : not null access procedure (Position : Cursor));
287 procedure Reverse_Iterate
288 (Container : Vector;
289 Process : not null access procedure (Position : Cursor));
291 generic
292 with function "<" (Left, Right : Element_Type) return Boolean is <>;
293 package Generic_Sorting is
295 function Is_Sorted (Container : Vector) return Boolean;
297 procedure Sort (Container : in out Vector);
299 procedure Merge (Target : in out Vector; Source : in out Vector);
301 end Generic_Sorting;
303 private
305 pragma Inline (First_Index);
306 pragma Inline (Last_Index);
307 pragma Inline (Element);
308 pragma Inline (First_Element);
309 pragma Inline (Last_Element);
310 pragma Inline (Query_Element);
311 pragma Inline (Update_Element);
312 pragma Inline (Replace_Element);
313 pragma Inline (Is_Empty);
314 pragma Inline (Contains);
315 pragma Inline (Next);
316 pragma Inline (Previous);
318 type Elements_Array is array (Index_Type range <>) of Element_Type;
319 function "=" (L, R : Elements_Array) return Boolean is abstract;
321 type Elements_Type (Last : Index_Type) is limited record
322 EA : Elements_Array (Index_Type'First .. Last);
323 end record;
325 type Elements_Access is access Elements_Type;
327 use Ada.Finalization;
329 type Vector is new Controlled with record
330 Elements : Elements_Access;
331 Last : Extended_Index := No_Index;
332 Busy : Natural := 0;
333 Lock : Natural := 0;
334 end record;
336 overriding
337 procedure Adjust (Container : in out Vector);
339 overriding
340 procedure Finalize (Container : in out Vector);
342 use Ada.Streams;
344 procedure Write
345 (Stream : not null access Root_Stream_Type'Class;
346 Container : Vector);
348 for Vector'Write use Write;
350 procedure Read
351 (Stream : not null access Root_Stream_Type'Class;
352 Container : out Vector);
354 for Vector'Read use Read;
356 type Vector_Access is access constant Vector;
357 for Vector_Access'Storage_Size use 0;
359 type Cursor is record
360 Container : Vector_Access;
361 Index : Index_Type := Index_Type'First;
362 end record;
364 procedure Write
365 (Stream : not null access Root_Stream_Type'Class;
366 Position : Cursor);
368 for Cursor'Write use Write;
370 procedure Read
371 (Stream : not null access Root_Stream_Type'Class;
372 Position : out Cursor);
374 for Cursor'Read use Read;
376 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
378 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
380 end Ada.Containers.Vectors;