[multiple changes]
[gcc.git] / gcc / ada / a-cobove.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . B O U N D E D _ 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 ------------------------------------------------------------------------------
33
34 with Ada.Streams; use Ada.Streams;
35 with Ada.Iterator_Interfaces;
36
37 generic
38 type Index_Type is range <>;
39 type Element_Type is private;
40
41 with function "=" (Left, Right : Element_Type) return Boolean is <>;
42
43 package Ada.Containers.Bounded_Vectors is
44 pragma Pure;
45 pragma Remote_Types;
46
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;
50
51 No_Index : constant Extended_Index := Extended_Index'First;
52
53 type Vector (Capacity : Count_Type) is tagged private with
54 Constant_Indexing => Constant_Reference,
55 Variable_Indexing => Reference,
56 Default_Iterator => Iterate,
57 Iterator_Element => Element_Type;
58
59 pragma Preelaborable_Initialization (Vector);
60
61 type Cursor is private;
62 pragma Preelaborable_Initialization (Cursor);
63
64 Empty_Vector : constant Vector;
65
66 No_Element : constant Cursor;
67 function Has_Element (Position : Cursor) return Boolean;
68
69 package Vector_Iterator_Interfaces is new
70 Ada.Iterator_Interfaces (Cursor, Has_Element);
71
72 overriding function "=" (Left, Right : Vector) return Boolean;
73
74 function To_Vector (Length : Count_Type) return Vector;
75
76 function To_Vector
77 (New_Item : Element_Type;
78 Length : Count_Type) return Vector;
79
80 function "&" (Left, Right : Vector) return Vector;
81
82 function "&" (Left : Vector; Right : Element_Type) return Vector;
83
84 function "&" (Left : Element_Type; Right : Vector) return Vector;
85
86 function "&" (Left, Right : Element_Type) return Vector;
87
88 function Capacity (Container : Vector) return Count_Type;
89
90 procedure Reserve_Capacity
91 (Container : in out Vector;
92 Capacity : Count_Type);
93
94 function Length (Container : Vector) return Count_Type;
95
96 procedure Set_Length
97 (Container : in out Vector;
98 Length : Count_Type);
99
100 function Is_Empty (Container : Vector) return Boolean;
101
102 procedure Clear (Container : in out Vector);
103
104 function To_Cursor
105 (Container : Vector;
106 Index : Extended_Index) return Cursor;
107
108 function To_Index (Position : Cursor) return Extended_Index;
109
110 function Element
111 (Container : Vector;
112 Index : Index_Type) return Element_Type;
113
114 function Element (Position : Cursor) return Element_Type;
115
116 procedure Replace_Element
117 (Container : in out Vector;
118 Index : Index_Type;
119 New_Item : Element_Type);
120
121 procedure Replace_Element
122 (Container : in out Vector;
123 Position : Cursor;
124 New_Item : Element_Type);
125
126 procedure Query_Element
127 (Container : Vector;
128 Index : Index_Type;
129 Process : not null access procedure (Element : Element_Type));
130
131 procedure Query_Element
132 (Position : Cursor;
133 Process : not null access procedure (Element : Element_Type));
134
135 procedure Update_Element
136 (Container : in out Vector;
137 Index : Index_Type;
138 Process : not null access procedure (Element : in out Element_Type));
139
140 procedure Update_Element
141 (Container : in out Vector;
142 Position : Cursor;
143 Process : not null access procedure (Element : in out Element_Type));
144
145 procedure Assign (Target : in out Vector; Source : Vector);
146
147 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
148
149 procedure Move (Target : in out Vector; Source : in out Vector);
150
151 procedure Insert
152 (Container : in out Vector;
153 Before : Extended_Index;
154 New_Item : Vector);
155
156 procedure Insert
157 (Container : in out Vector;
158 Before : Cursor;
159 New_Item : Vector);
160
161 procedure Insert
162 (Container : in out Vector;
163 Before : Cursor;
164 New_Item : Vector;
165 Position : out Cursor);
166
167 procedure Insert
168 (Container : in out Vector;
169 Before : Extended_Index;
170 New_Item : Element_Type;
171 Count : Count_Type := 1);
172
173 procedure Insert
174 (Container : in out Vector;
175 Before : Cursor;
176 New_Item : Element_Type;
177 Count : Count_Type := 1);
178
179 procedure Insert
180 (Container : in out Vector;
181 Before : Cursor;
182 New_Item : Element_Type;
183 Position : out Cursor;
184 Count : Count_Type := 1);
185
186 procedure Insert
187 (Container : in out Vector;
188 Before : Extended_Index;
189 Count : Count_Type := 1);
190
191 procedure Insert
192 (Container : in out Vector;
193 Before : Cursor;
194 Position : out Cursor;
195 Count : Count_Type := 1);
196
197 procedure Prepend
198 (Container : in out Vector;
199 New_Item : Vector);
200
201 procedure Prepend
202 (Container : in out Vector;
203 New_Item : Element_Type;
204 Count : Count_Type := 1);
205
206 procedure Append
207 (Container : in out Vector;
208 New_Item : Vector);
209
210 procedure Append
211 (Container : in out Vector;
212 New_Item : Element_Type;
213 Count : Count_Type := 1);
214
215 procedure Insert_Space
216 (Container : in out Vector;
217 Before : Extended_Index;
218 Count : Count_Type := 1);
219
220 procedure Insert_Space
221 (Container : in out Vector;
222 Before : Cursor;
223 Position : out Cursor;
224 Count : Count_Type := 1);
225
226 procedure Delete
227 (Container : in out Vector;
228 Index : Extended_Index;
229 Count : Count_Type := 1);
230
231 procedure Delete
232 (Container : in out Vector;
233 Position : in out Cursor;
234 Count : Count_Type := 1);
235
236 procedure Delete_First
237 (Container : in out Vector;
238 Count : Count_Type := 1);
239
240 procedure Delete_Last
241 (Container : in out Vector;
242 Count : Count_Type := 1);
243
244 procedure Reverse_Elements (Container : in out Vector);
245
246 procedure Swap (Container : in out Vector; I, J : Index_Type);
247
248 procedure Swap (Container : in out Vector; I, J : Cursor);
249
250 function First_Index (Container : Vector) return Index_Type;
251
252 function First (Container : Vector) return Cursor;
253
254 function First_Element (Container : Vector) return Element_Type;
255
256 function Last_Index (Container : Vector) return Extended_Index;
257
258 function Last (Container : Vector) return Cursor;
259
260 function Last_Element (Container : Vector) return Element_Type;
261
262 function Next (Position : Cursor) return Cursor;
263
264 procedure Next (Position : in out Cursor);
265
266 function Previous (Position : Cursor) return Cursor;
267
268 procedure Previous (Position : in out Cursor);
269
270 function Find_Index
271 (Container : Vector;
272 Item : Element_Type;
273 Index : Index_Type := Index_Type'First) return Extended_Index;
274
275 function Find
276 (Container : Vector;
277 Item : Element_Type;
278 Position : Cursor := No_Element) return Cursor;
279
280 function Reverse_Find_Index
281 (Container : Vector;
282 Item : Element_Type;
283 Index : Index_Type := Index_Type'Last) return Extended_Index;
284
285 function Reverse_Find
286 (Container : Vector;
287 Item : Element_Type;
288 Position : Cursor := No_Element) return Cursor;
289
290 function Contains
291 (Container : Vector;
292 Item : Element_Type) return Boolean;
293
294 procedure Iterate
295 (Container : Vector;
296 Process : not null access procedure (Position : Cursor));
297
298 procedure Reverse_Iterate
299 (Container : Vector;
300 Process : not null access procedure (Position : Cursor));
301
302 function Iterate
303 (Container : Vector)
304 return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
305
306 function Iterate
307 (Container : Vector;
308 Start : Cursor)
309 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
310
311 type Constant_Reference_Type
312 (Element : not null access constant Element_Type) is
313 private
314 with
315 Implicit_Dereference => Element;
316
317 procedure Read
318 (Stream : not null access Root_Stream_Type'Class;
319 Item : out Constant_Reference_Type);
320
321 for Constant_Reference_Type'Read use Read;
322
323 procedure Write
324 (Stream : not null access Root_Stream_Type'Class;
325 Item : Constant_Reference_Type);
326
327 for Constant_Reference_Type'Write use Write;
328
329 type Reference_Type (Element : not null access Element_Type) is private
330 with
331 Implicit_Dereference => Element;
332
333 procedure Read
334 (Stream : not null access Root_Stream_Type'Class;
335 Item : out Reference_Type);
336
337 for Reference_Type'Read use Read;
338
339 procedure Write
340 (Stream : not null access Root_Stream_Type'Class;
341 Item : Reference_Type);
342
343 for Reference_Type'Write use Write;
344
345 function Constant_Reference
346 (Container : Vector; Position : Cursor) -- SHOULD BE ALIASED
347 return Constant_Reference_Type;
348
349 function Constant_Reference
350 (Container : Vector; Position : Index_Type)
351 return Constant_Reference_Type;
352
353 function Reference (Container : Vector; Position : Cursor)
354 return Reference_Type;
355
356 function Reference (Container : Vector; Position : Index_Type)
357 return Reference_Type;
358
359 generic
360 with function "<" (Left, Right : Element_Type) return Boolean is <>;
361 package Generic_Sorting is
362
363 function Is_Sorted (Container : Vector) return Boolean;
364
365 procedure Sort (Container : in out Vector);
366
367 procedure Merge (Target : in out Vector; Source : in out Vector);
368
369 end Generic_Sorting;
370
371 private
372
373 pragma Inline (First_Index);
374 pragma Inline (Last_Index);
375 pragma Inline (Element);
376 pragma Inline (First_Element);
377 pragma Inline (Last_Element);
378 pragma Inline (Query_Element);
379 pragma Inline (Update_Element);
380 pragma Inline (Replace_Element);
381 pragma Inline (Is_Empty);
382 pragma Inline (Contains);
383 pragma Inline (Next);
384 pragma Inline (Previous);
385
386 type Elements_Array is array (Count_Type range <>) of aliased Element_Type;
387 function "=" (L, R : Elements_Array) return Boolean is abstract;
388
389 type Vector (Capacity : Count_Type) is tagged record
390 Elements : Elements_Array (1 .. Capacity) := (others => <>);
391 Last : Extended_Index := No_Index;
392 Busy : Natural := 0;
393 Lock : Natural := 0;
394 end record;
395
396 procedure Write
397 (Stream : not null access Root_Stream_Type'Class;
398 Container : Vector);
399
400 for Vector'Write use Write;
401
402 procedure Read
403 (Stream : not null access Root_Stream_Type'Class;
404 Container : out Vector);
405
406 for Vector'Read use Read;
407
408 type Vector_Access is access all Vector;
409 for Vector_Access'Storage_Size use 0;
410
411 type Cursor is record
412 Container : Vector_Access;
413 Index : Index_Type := Index_Type'First;
414 end record;
415
416 procedure Write
417 (Stream : not null access Root_Stream_Type'Class;
418 Position : Cursor);
419
420 for Cursor'Write use Write;
421
422 procedure Read
423 (Stream : not null access Root_Stream_Type'Class;
424 Position : out Cursor);
425
426 for Cursor'Read use Read;
427
428 type Constant_Reference_Type
429 (Element : not null access constant Element_Type) is null record;
430
431 type Reference_Type
432 (Element : not null access Element_Type) is null record;
433
434 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
435
436 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
437
438 end Ada.Containers.Bounded_Vectors;