PR testsuite/44195
[official-gcc.git] / gcc / ada / a-coinve.ads
blob187c42034663ef2ac6cebb94d2da9a56026cd824
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . I N D E F I N I T E _ 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.Indefinite_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 Prepend
174 (Container : in out Vector;
175 New_Item : Vector);
177 procedure Prepend
178 (Container : in out Vector;
179 New_Item : Element_Type;
180 Count : Count_Type := 1);
182 procedure Append
183 (Container : in out Vector;
184 New_Item : Vector);
186 procedure Append
187 (Container : in out Vector;
188 New_Item : Element_Type;
189 Count : Count_Type := 1);
191 procedure Insert_Space
192 (Container : in out Vector;
193 Before : Extended_Index;
194 Count : Count_Type := 1);
196 procedure Insert_Space
197 (Container : in out Vector;
198 Before : Cursor;
199 Position : out Cursor;
200 Count : Count_Type := 1);
202 procedure Delete
203 (Container : in out Vector;
204 Index : Extended_Index;
205 Count : Count_Type := 1);
207 procedure Delete
208 (Container : in out Vector;
209 Position : in out Cursor;
210 Count : Count_Type := 1);
212 procedure Delete_First
213 (Container : in out Vector;
214 Count : Count_Type := 1);
216 procedure Delete_Last
217 (Container : in out Vector;
218 Count : Count_Type := 1);
220 procedure Reverse_Elements (Container : in out Vector);
222 procedure Swap (Container : in out Vector; I, J : Index_Type);
224 procedure Swap (Container : in out Vector; I, J : Cursor);
226 function First_Index (Container : Vector) return Index_Type;
228 function First (Container : Vector) return Cursor;
230 function First_Element (Container : Vector) return Element_Type;
232 function Last_Index (Container : Vector) return Extended_Index;
234 function Last (Container : Vector) return Cursor;
236 function Last_Element (Container : Vector) return Element_Type;
238 function Next (Position : Cursor) return Cursor;
240 procedure Next (Position : in out Cursor);
242 function Previous (Position : Cursor) return Cursor;
244 procedure Previous (Position : in out Cursor);
246 function Find_Index
247 (Container : Vector;
248 Item : Element_Type;
249 Index : Index_Type := Index_Type'First) return Extended_Index;
251 function Find
252 (Container : Vector;
253 Item : Element_Type;
254 Position : Cursor := No_Element) return Cursor;
256 function Reverse_Find_Index
257 (Container : Vector;
258 Item : Element_Type;
259 Index : Index_Type := Index_Type'Last) return Extended_Index;
261 function Reverse_Find
262 (Container : Vector;
263 Item : Element_Type;
264 Position : Cursor := No_Element) return Cursor;
266 function Contains
267 (Container : Vector;
268 Item : Element_Type) return Boolean;
270 function Has_Element (Position : Cursor) return Boolean;
272 procedure Iterate
273 (Container : Vector;
274 Process : not null access procedure (Position : Cursor));
276 procedure Reverse_Iterate
277 (Container : Vector;
278 Process : not null access procedure (Position : Cursor));
280 generic
281 with function "<" (Left, Right : Element_Type) return Boolean is <>;
282 package Generic_Sorting is
284 function Is_Sorted (Container : Vector) return Boolean;
286 procedure Sort (Container : in out Vector);
288 procedure Merge (Target : in out Vector; Source : in out Vector);
290 end Generic_Sorting;
292 private
294 pragma Inline (First_Index);
295 pragma Inline (Last_Index);
296 pragma Inline (Element);
297 pragma Inline (First_Element);
298 pragma Inline (Last_Element);
299 pragma Inline (Query_Element);
300 pragma Inline (Update_Element);
301 pragma Inline (Replace_Element);
302 pragma Inline (Contains);
303 pragma Inline (Next);
304 pragma Inline (Previous);
306 type Element_Access is access Element_Type;
308 type Elements_Array is array (Index_Type range <>) of Element_Access;
309 function "=" (L, R : Elements_Array) return Boolean is abstract;
311 type Elements_Type (Last : Index_Type) is limited record
312 EA : Elements_Array (Index_Type'First .. Last);
313 end record;
315 type Elements_Access is access Elements_Type;
317 use Ada.Finalization;
319 type Vector is new Controlled with record
320 Elements : Elements_Access;
321 Last : Extended_Index := No_Index;
322 Busy : Natural := 0;
323 Lock : Natural := 0;
324 end record;
326 overriding
327 procedure Adjust (Container : in out Vector);
329 overriding
330 procedure Finalize (Container : in out Vector);
332 use Ada.Streams;
334 procedure Write
335 (Stream : not null access Root_Stream_Type'Class;
336 Container : Vector);
338 for Vector'Write use Write;
340 procedure Read
341 (Stream : not null access Root_Stream_Type'Class;
342 Container : out Vector);
344 for Vector'Read use Read;
346 type Vector_Access is access constant Vector;
347 for Vector_Access'Storage_Size use 0;
349 type Cursor is record
350 Container : Vector_Access;
351 Index : Index_Type := Index_Type'First;
352 end record;
354 procedure Write
355 (Stream : not null access Root_Stream_Type'Class;
356 Position : Cursor);
358 for Cursor'Write use Write;
360 procedure Read
361 (Stream : not null access Root_Stream_Type'Class;
362 Position : out Cursor);
364 for Cursor'Read use Read;
366 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
368 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
370 end Ada.Containers.Indefinite_Vectors;