2011-11-06 François Dumont <fdumont@gcc.gnu.org>
[official-gcc.git] / gcc / ada / a-coinve.ads
blob06568278997d3d769b489054f81baed66148369e
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-2011, 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;
36 with Ada.Streams; use Ada.Streams;
37 with Ada.Iterator_Interfaces;
39 generic
40 type Index_Type is range <>;
41 type Element_Type (<>) is private;
43 with function "=" (Left, Right : Element_Type) return Boolean is <>;
45 package Ada.Containers.Indefinite_Vectors is
46 pragma Preelaborate;
47 pragma Remote_Types;
49 subtype Extended_Index is Index_Type'Base
50 range Index_Type'First - 1 ..
51 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
53 No_Index : constant Extended_Index := Extended_Index'First;
55 type Vector is tagged private
56 with
57 Constant_Indexing => Constant_Reference,
58 Variable_Indexing => Reference,
59 Default_Iterator => Iterate,
60 Iterator_Element => Element_Type;
62 pragma Preelaborable_Initialization (Vector);
64 type Cursor is private;
65 pragma Preelaborable_Initialization (Cursor);
67 Empty_Vector : constant Vector;
69 No_Element : constant Cursor;
70 function Has_Element (Position : Cursor) return Boolean;
72 procedure Read
73 (Stream : not null access Root_Stream_Type'Class;
74 Position : out Cursor);
76 for Cursor'Read use Read;
78 procedure Write
79 (Stream : not null access Root_Stream_Type'Class;
80 Position : Cursor);
82 for Cursor'Write use Write;
84 package Vector_Iterator_Interfaces is new
85 Ada.Iterator_Interfaces (Cursor, Has_Element);
87 overriding function "=" (Left, Right : Vector) return Boolean;
89 function To_Vector (Length : Count_Type) return Vector;
91 function To_Vector
92 (New_Item : Element_Type;
93 Length : Count_Type) return Vector;
95 function "&" (Left, Right : Vector) return Vector;
97 function "&" (Left : Vector; Right : Element_Type) return Vector;
99 function "&" (Left : Element_Type; Right : Vector) return Vector;
101 function "&" (Left, Right : Element_Type) return Vector;
103 function Capacity (Container : Vector) return Count_Type;
105 procedure Reserve_Capacity
106 (Container : in out Vector;
107 Capacity : Count_Type);
109 function Length (Container : Vector) return Count_Type;
111 procedure Set_Length
112 (Container : in out Vector;
113 Length : Count_Type);
115 function Is_Empty (Container : Vector) return Boolean;
117 procedure Clear (Container : in out Vector);
119 type Constant_Reference_Type
120 (Element : not null access constant Element_Type) is private
121 with
122 Implicit_Dereference => Element;
124 procedure Write
125 (Stream : not null access Root_Stream_Type'Class;
126 Item : Constant_Reference_Type);
128 for Constant_Reference_Type'Write use Write;
130 procedure Read
131 (Stream : not null access Root_Stream_Type'Class;
132 Item : out Constant_Reference_Type);
134 for Constant_Reference_Type'Read use Read;
136 type Reference_Type (Element : not null access Element_Type) is private
137 with
138 Implicit_Dereference => Element;
140 procedure Write
141 (Stream : not null access Root_Stream_Type'Class;
142 Item : Reference_Type);
144 for Reference_Type'Write use Write;
146 procedure Read
147 (Stream : not null access Root_Stream_Type'Class;
148 Item : out Reference_Type);
150 for Reference_Type'Read use Read;
152 function Constant_Reference
153 (Container : Vector; Position : Cursor) -- SHOULD BE ALIASED
154 return Constant_Reference_Type;
156 function Constant_Reference
157 (Container : Vector; Position : Index_Type)
158 return Constant_Reference_Type;
160 function Reference (Container : Vector; Position : Cursor)
161 return Reference_Type;
163 function Reference (Container : Vector; Position : Index_Type)
164 return Reference_Type;
166 function To_Cursor
167 (Container : Vector;
168 Index : Extended_Index) return Cursor;
170 function To_Index (Position : Cursor) return Extended_Index;
172 function Element
173 (Container : Vector;
174 Index : Index_Type) return Element_Type;
176 function Element (Position : Cursor) return Element_Type;
178 procedure Replace_Element
179 (Container : in out Vector;
180 Index : Index_Type;
181 New_Item : Element_Type);
183 procedure Replace_Element
184 (Container : in out Vector;
185 Position : Cursor;
186 New_Item : Element_Type);
188 procedure Query_Element
189 (Container : Vector;
190 Index : Index_Type;
191 Process : not null access procedure (Element : Element_Type));
193 procedure Query_Element
194 (Position : Cursor;
195 Process : not null access procedure (Element : Element_Type));
197 procedure Update_Element
198 (Container : in out Vector;
199 Index : Index_Type;
200 Process : not null access procedure (Element : in out Element_Type));
202 procedure Update_Element
203 (Container : in out Vector;
204 Position : Cursor;
205 Process : not null access procedure (Element : in out Element_Type));
207 procedure Assign (Target : in out Vector; Source : Vector);
209 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
211 procedure Move (Target : in out Vector; Source : in out Vector);
213 procedure Insert
214 (Container : in out Vector;
215 Before : Extended_Index;
216 New_Item : Vector);
218 procedure Insert
219 (Container : in out Vector;
220 Before : Cursor;
221 New_Item : Vector);
223 procedure Insert
224 (Container : in out Vector;
225 Before : Cursor;
226 New_Item : Vector;
227 Position : out Cursor);
229 procedure Insert
230 (Container : in out Vector;
231 Before : Extended_Index;
232 New_Item : Element_Type;
233 Count : Count_Type := 1);
235 procedure Insert
236 (Container : in out Vector;
237 Before : Cursor;
238 New_Item : Element_Type;
239 Count : Count_Type := 1);
241 procedure Insert
242 (Container : in out Vector;
243 Before : Cursor;
244 New_Item : Element_Type;
245 Position : out Cursor;
246 Count : Count_Type := 1);
248 procedure Prepend
249 (Container : in out Vector;
250 New_Item : Vector);
252 procedure Prepend
253 (Container : in out Vector;
254 New_Item : Element_Type;
255 Count : Count_Type := 1);
257 procedure Append
258 (Container : in out Vector;
259 New_Item : Vector);
261 procedure Append
262 (Container : in out Vector;
263 New_Item : Element_Type;
264 Count : Count_Type := 1);
266 procedure Insert_Space
267 (Container : in out Vector;
268 Before : Extended_Index;
269 Count : Count_Type := 1);
271 procedure Insert_Space
272 (Container : in out Vector;
273 Before : Cursor;
274 Position : out Cursor;
275 Count : Count_Type := 1);
277 procedure Delete
278 (Container : in out Vector;
279 Index : Extended_Index;
280 Count : Count_Type := 1);
282 procedure Delete
283 (Container : in out Vector;
284 Position : in out Cursor;
285 Count : Count_Type := 1);
287 procedure Delete_First
288 (Container : in out Vector;
289 Count : Count_Type := 1);
291 procedure Delete_Last
292 (Container : in out Vector;
293 Count : Count_Type := 1);
295 procedure Reverse_Elements (Container : in out Vector);
297 procedure Swap (Container : in out Vector; I, J : Index_Type);
299 procedure Swap (Container : in out Vector; I, J : Cursor);
301 function First_Index (Container : Vector) return Index_Type;
303 function First (Container : Vector) return Cursor;
305 function First_Element (Container : Vector) return Element_Type;
307 function Last_Index (Container : Vector) return Extended_Index;
309 function Last (Container : Vector) return Cursor;
311 function Last_Element (Container : Vector) return Element_Type;
313 function Next (Position : Cursor) return Cursor;
315 procedure Next (Position : in out Cursor);
317 function Previous (Position : Cursor) return Cursor;
319 procedure Previous (Position : in out Cursor);
321 function Find_Index
322 (Container : Vector;
323 Item : Element_Type;
324 Index : Index_Type := Index_Type'First) return Extended_Index;
326 function Find
327 (Container : Vector;
328 Item : Element_Type;
329 Position : Cursor := No_Element) return Cursor;
331 function Reverse_Find_Index
332 (Container : Vector;
333 Item : Element_Type;
334 Index : Index_Type := Index_Type'Last) return Extended_Index;
336 function Reverse_Find
337 (Container : Vector;
338 Item : Element_Type;
339 Position : Cursor := No_Element) return Cursor;
341 function Contains
342 (Container : Vector;
343 Item : Element_Type) return Boolean;
345 procedure Iterate
346 (Container : Vector;
347 Process : not null access procedure (Position : Cursor));
349 function Iterate (Container : Vector)
350 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
352 function Iterate
353 (Container : Vector;
354 Start : Cursor)
355 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
357 procedure Reverse_Iterate
358 (Container : Vector;
359 Process : not null access procedure (Position : Cursor));
361 generic
362 with function "<" (Left, Right : Element_Type) return Boolean is <>;
363 package Generic_Sorting is
365 function Is_Sorted (Container : Vector) return Boolean;
367 procedure Sort (Container : in out Vector);
369 procedure Merge (Target : in out Vector; Source : in out Vector);
371 end Generic_Sorting;
373 private
375 pragma Inline (First_Index);
376 pragma Inline (Last_Index);
377 pragma Inline (Element);
378 pragma Inline (First_Element);
379 pragma Inline (Last_Element);
380 pragma Inline (Query_Element);
381 pragma Inline (Update_Element);
382 pragma Inline (Replace_Element);
383 pragma Inline (Contains);
384 pragma Inline (Next);
385 pragma Inline (Previous);
387 type Element_Access is access Element_Type;
389 type Elements_Array is array (Index_Type range <>) of Element_Access;
390 function "=" (L, R : Elements_Array) return Boolean is abstract;
392 type Elements_Type (Last : Index_Type) is limited record
393 EA : Elements_Array (Index_Type'First .. Last);
394 end record;
396 type Elements_Access is access Elements_Type;
398 use Ada.Finalization;
400 type Vector is new Controlled with record
401 Elements : Elements_Access;
402 Last : Extended_Index := No_Index;
403 Busy : Natural := 0;
404 Lock : Natural := 0;
405 end record;
407 type Constant_Reference_Type
408 (Element : not null access constant Element_Type) is null record;
410 type Reference_Type
411 (Element : not null access Element_Type) is null record;
413 overriding procedure Adjust (Container : in out Vector);
415 overriding procedure Finalize (Container : in out Vector);
417 procedure Write
418 (Stream : not null access Root_Stream_Type'Class;
419 Container : Vector);
421 for Vector'Write use Write;
423 procedure Read
424 (Stream : not null access Root_Stream_Type'Class;
425 Container : out Vector);
427 for Vector'Read use Read;
429 type Vector_Access is access constant Vector;
430 for Vector_Access'Storage_Size use 0;
432 type Cursor is record
433 Container : Vector_Access;
434 Index : Index_Type := Index_Type'First;
435 end record;
437 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
439 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
441 end Ada.Containers.Indefinite_Vectors;