Disable tests for strdup/strndup on __hpux__
[official-gcc.git] / gcc / ada / libgnat / a-cobove.ads
blobd5bfe4b21291fdf88196b26b6c64f9d5d63b5d89
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-2023, 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 with Ada.Iterator_Interfaces;
36 with Ada.Containers.Helpers;
37 private with Ada.Streams;
38 private with Ada.Finalization;
39 private with Ada.Strings.Text_Buffers;
41 generic
42 type Index_Type is range <>;
43 type Element_Type is private;
45 with function "=" (Left, Right : Element_Type) return Boolean is <>;
47 package Ada.Containers.Bounded_Vectors is
48 pragma Annotate (CodePeer, Skip_Analysis);
49 pragma Pure;
50 pragma Remote_Types;
52 subtype Extended_Index is Index_Type'Base
53 range Index_Type'First - 1 ..
54 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
56 No_Index : constant Extended_Index := Extended_Index'First;
58 type Vector (Capacity : Count_Type) is tagged private with
59 Constant_Indexing => Constant_Reference,
60 Variable_Indexing => Reference,
61 Default_Iterator => Iterate,
62 Iterator_Element => Element_Type,
63 Aggregate => (Empty => Empty,
64 Add_Unnamed => Append,
65 New_Indexed => New_Vector,
66 Assign_Indexed => Replace_Element),
67 Preelaborable_Initialization
68 => Element_Type'Preelaborable_Initialization;
70 type Cursor is private with Preelaborable_Initialization;
72 Empty_Vector : constant Vector;
74 No_Element : constant Cursor;
76 function Has_Element (Position : Cursor) return Boolean;
78 package Vector_Iterator_Interfaces is new
79 Ada.Iterator_Interfaces (Cursor, Has_Element);
81 function Empty (Capacity : Count_Type := 10) return Vector;
82 pragma Ada_2022 (Empty);
84 overriding function "=" (Left, Right : Vector) return Boolean;
86 function New_Vector (First, Last : Index_Type) return Vector
87 with Pre => First = Index_Type'First;
88 -- Ada 2022 aggregate operation.
89 pragma Ada_2022 (New_Vector);
91 function To_Vector (Length : Count_Type) return Vector;
93 function To_Vector
94 (New_Item : Element_Type;
95 Length : Count_Type) return Vector;
97 function "&" (Left, Right : Vector) return Vector;
99 function "&" (Left : Vector; Right : Element_Type) return Vector;
101 function "&" (Left : Element_Type; Right : Vector) return Vector;
103 function "&" (Left, Right : Element_Type) return Vector;
105 function Capacity (Container : Vector) return Count_Type;
107 procedure Reserve_Capacity
108 (Container : in out Vector;
109 Capacity : Count_Type);
111 function Length (Container : Vector) return Count_Type;
113 procedure Set_Length
114 (Container : in out Vector;
115 Length : Count_Type);
117 function Is_Empty (Container : Vector) return Boolean;
119 procedure Clear (Container : in out Vector);
121 function To_Cursor
122 (Container : Vector;
123 Index : Extended_Index) return Cursor;
125 function To_Index (Position : Cursor) return Extended_Index;
127 function Element
128 (Container : Vector;
129 Index : Index_Type) return Element_Type;
131 function Element (Position : Cursor) return Element_Type;
133 procedure Replace_Element
134 (Container : in out Vector;
135 Index : Index_Type;
136 New_Item : Element_Type);
138 procedure Replace_Element
139 (Container : in out Vector;
140 Position : Cursor;
141 New_Item : Element_Type);
143 procedure Query_Element
144 (Container : Vector;
145 Index : Index_Type;
146 Process : not null access procedure (Element : Element_Type));
148 procedure Query_Element
149 (Position : Cursor;
150 Process : not null access procedure (Element : Element_Type));
152 procedure Update_Element
153 (Container : in out Vector;
154 Index : Index_Type;
155 Process : not null access procedure (Element : in out Element_Type));
157 procedure Update_Element
158 (Container : in out Vector;
159 Position : Cursor;
160 Process : not null access procedure (Element : in out Element_Type));
162 type Constant_Reference_Type
163 (Element : not null access constant Element_Type) is
164 private
165 with
166 Implicit_Dereference => Element;
168 type Reference_Type (Element : not null access Element_Type) is private
169 with
170 Implicit_Dereference => Element;
172 function Constant_Reference
173 (Container : aliased Vector;
174 Position : Cursor) return Constant_Reference_Type;
176 function Reference
177 (Container : aliased in out Vector;
178 Position : Cursor) return Reference_Type;
180 function Constant_Reference
181 (Container : aliased Vector;
182 Index : Index_Type) return Constant_Reference_Type;
184 function Reference
185 (Container : aliased in out Vector;
186 Index : Index_Type) return Reference_Type;
188 procedure Assign (Target : in out Vector; Source : Vector);
190 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
192 procedure Move (Target : in out Vector; Source : in out Vector);
194 procedure Insert_Vector
195 (Container : in out Vector;
196 Before : Extended_Index;
197 New_Item : Vector);
198 pragma Ada_2022 (Insert_Vector);
200 procedure Insert
201 (Container : in out Vector;
202 Before : Extended_Index;
203 New_Item : Vector) renames Insert_Vector;
204 -- Retained for now for compatibility; AI12-0400 will remove this.
206 procedure Insert_Vector
207 (Container : in out Vector;
208 Before : Cursor;
209 New_Item : Vector);
210 pragma Ada_2022 (Insert_Vector);
212 procedure Insert
213 (Container : in out Vector;
214 Before : Cursor;
215 New_Item : Vector) renames Insert_Vector;
216 -- Retained for now for compatibility; AI12-0400 will remove this.
218 procedure Insert_Vector
219 (Container : in out Vector;
220 Before : Cursor;
221 New_Item : Vector;
222 Position : out Cursor);
223 pragma Ada_2022 (Insert_Vector);
225 procedure Insert
226 (Container : in out Vector;
227 Before : Cursor;
228 New_Item : Vector;
229 Position : out Cursor) renames Insert_Vector;
230 -- Retained for now for compatibility; AI12-0400 will remove this.
232 procedure Insert
233 (Container : in out Vector;
234 Before : Extended_Index;
235 New_Item : Element_Type;
236 Count : Count_Type := 1);
238 procedure Insert
239 (Container : in out Vector;
240 Before : Cursor;
241 New_Item : Element_Type;
242 Count : Count_Type := 1);
244 procedure Insert
245 (Container : in out Vector;
246 Before : Cursor;
247 New_Item : Element_Type;
248 Position : out Cursor;
249 Count : Count_Type := 1);
251 procedure Insert
252 (Container : in out Vector;
253 Before : Extended_Index;
254 Count : Count_Type := 1);
256 procedure Insert
257 (Container : in out Vector;
258 Before : Cursor;
259 Position : out Cursor;
260 Count : Count_Type := 1);
262 procedure Prepend_Vector
263 (Container : in out Vector;
264 New_Item : Vector);
265 pragma Ada_2022 (Prepend_Vector);
267 procedure Prepend
268 (Container : in out Vector;
269 New_Item : Vector) renames Prepend_Vector;
270 -- Retained for now for compatibility; AI12-0400 will remove this.
272 procedure Prepend
273 (Container : in out Vector;
274 New_Item : Element_Type;
275 Count : Count_Type := 1);
277 procedure Append_Vector
278 (Container : in out Vector;
279 New_Item : Vector);
280 pragma Ada_2022 (Append_Vector);
282 procedure Append
283 (Container : in out Vector;
284 New_Item : Vector) renames Append_Vector;
285 -- Retained for now for compatibility; AI12-0400 will remove this.
287 procedure Append
288 (Container : in out Vector;
289 New_Item : Element_Type;
290 Count : Count_Type);
292 procedure Append (Container : in out Vector;
293 New_Item : Element_Type);
295 procedure Insert_Space
296 (Container : in out Vector;
297 Before : Extended_Index;
298 Count : Count_Type := 1);
300 procedure Insert_Space
301 (Container : in out Vector;
302 Before : Cursor;
303 Position : out Cursor;
304 Count : Count_Type := 1);
306 procedure Delete
307 (Container : in out Vector;
308 Index : Extended_Index;
309 Count : Count_Type := 1);
311 procedure Delete
312 (Container : in out Vector;
313 Position : in out Cursor;
314 Count : Count_Type := 1);
316 procedure Delete_First
317 (Container : in out Vector;
318 Count : Count_Type := 1);
320 procedure Delete_Last
321 (Container : in out Vector;
322 Count : Count_Type := 1);
324 procedure Reverse_Elements (Container : in out Vector);
326 procedure Swap (Container : in out Vector; I, J : Index_Type);
328 procedure Swap (Container : in out Vector; I, J : Cursor);
330 function First_Index (Container : Vector) return Index_Type;
332 function First (Container : Vector) return Cursor;
334 function First_Element (Container : Vector) return Element_Type;
336 function Last_Index (Container : Vector) return Extended_Index;
338 function Last (Container : Vector) return Cursor;
340 function Last_Element (Container : Vector) return Element_Type;
342 function Next (Position : Cursor) return Cursor;
344 procedure Next (Position : in out Cursor);
346 function Previous (Position : Cursor) return Cursor;
348 procedure Previous (Position : in out Cursor);
350 function Find_Index
351 (Container : Vector;
352 Item : Element_Type;
353 Index : Index_Type := Index_Type'First) return Extended_Index;
355 function Find
356 (Container : Vector;
357 Item : Element_Type;
358 Position : Cursor := No_Element) return Cursor;
360 function Reverse_Find_Index
361 (Container : Vector;
362 Item : Element_Type;
363 Index : Index_Type := Index_Type'Last) return Extended_Index;
365 function Reverse_Find
366 (Container : Vector;
367 Item : Element_Type;
368 Position : Cursor := No_Element) return Cursor;
370 function Contains
371 (Container : Vector;
372 Item : Element_Type) return Boolean;
374 procedure Iterate
375 (Container : Vector;
376 Process : not null access procedure (Position : Cursor));
378 procedure Reverse_Iterate
379 (Container : Vector;
380 Process : not null access procedure (Position : Cursor));
382 function Iterate
383 (Container : Vector)
384 return Vector_Iterator_Interfaces.Reversible_Iterator'Class;
386 function Iterate
387 (Container : Vector;
388 Start : Cursor)
389 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
391 generic
392 with function "<" (Left, Right : Element_Type) return Boolean is <>;
393 package Generic_Sorting is
395 function Is_Sorted (Container : Vector) return Boolean;
397 procedure Sort (Container : in out Vector);
399 procedure Merge (Target : in out Vector; Source : in out Vector);
401 end Generic_Sorting;
403 private
405 pragma Inline (First_Index);
406 pragma Inline (Last_Index);
407 pragma Inline (Element);
408 pragma Inline (First_Element);
409 pragma Inline (Last_Element);
410 pragma Inline (Query_Element);
411 pragma Inline (Update_Element);
412 pragma Inline (Replace_Element);
413 pragma Inline (Is_Empty);
414 pragma Inline (Contains);
415 pragma Inline (Next);
416 pragma Inline (Previous);
418 use Ada.Containers.Helpers;
419 package Implementation is new Generic_Implementation;
420 use Implementation;
422 use Ada.Streams;
423 use Ada.Finalization;
425 type Elements_Array is array (Count_Type range <>) of aliased Element_Type;
426 function "=" (L, R : Elements_Array) return Boolean is abstract;
428 type Vector (Capacity : Count_Type) is tagged record
429 Elements : Elements_Array (1 .. Capacity);
430 Last : Extended_Index := No_Index;
431 TC : aliased Tamper_Counts;
432 end record with Put_Image => Put_Image;
434 procedure Put_Image
435 (S : in out Ada.Strings.Text_Buffers.Root_Buffer_Type'Class; V : Vector);
437 procedure Write
438 (Stream : not null access Root_Stream_Type'Class;
439 Container : Vector);
441 for Vector'Write use Write;
443 procedure Read
444 (Stream : not null access Root_Stream_Type'Class;
445 Container : out Vector);
447 for Vector'Read use Read;
449 type Vector_Access is access all Vector;
450 for Vector_Access'Storage_Size use 0;
452 type Cursor is record
453 Container : Vector_Access;
454 Index : Index_Type := Index_Type'First;
455 end record;
457 procedure Write
458 (Stream : not null access Root_Stream_Type'Class;
459 Position : Cursor);
461 for Cursor'Write use Write;
463 procedure Read
464 (Stream : not null access Root_Stream_Type'Class;
465 Position : out Cursor);
467 for Cursor'Read use Read;
469 subtype Reference_Control_Type is Implementation.Reference_Control_Type;
470 -- It is necessary to rename this here, so that the compiler can find it
472 type Constant_Reference_Type
473 (Element : not null access constant Element_Type) is
474 record
475 Control : Reference_Control_Type :=
476 raise Program_Error with "uninitialized reference";
477 -- The RM says, "The default initialization of an object of
478 -- type Constant_Reference_Type or Reference_Type propagates
479 -- Program_Error."
480 end record;
482 procedure Read
483 (Stream : not null access Root_Stream_Type'Class;
484 Item : out Constant_Reference_Type);
486 for Constant_Reference_Type'Read use Read;
488 procedure Write
489 (Stream : not null access Root_Stream_Type'Class;
490 Item : Constant_Reference_Type);
492 for Constant_Reference_Type'Write use Write;
494 type Reference_Type (Element : not null access Element_Type) is record
495 Control : Reference_Control_Type :=
496 raise Program_Error with "uninitialized reference";
497 -- The RM says, "The default initialization of an object of
498 -- type Constant_Reference_Type or Reference_Type propagates
499 -- Program_Error."
500 end record;
502 procedure Read
503 (Stream : not null access Root_Stream_Type'Class;
504 Item : out Reference_Type);
506 for Reference_Type'Read use Read;
508 procedure Write
509 (Stream : not null access Root_Stream_Type'Class;
510 Item : Reference_Type);
512 for Reference_Type'Write use Write;
514 -- See Ada.Containers.Vectors for documentation on the following
516 procedure _Next (Position : in out Cursor) renames Next;
517 procedure _Previous (Position : in out Cursor) renames Previous;
519 function Pseudo_Reference
520 (Container : aliased Vector'Class) return Reference_Control_Type;
521 pragma Inline (Pseudo_Reference);
522 -- Creates an object of type Reference_Control_Type pointing to the
523 -- container, and increments the Lock. Finalization of this object will
524 -- decrement the Lock.
526 type Element_Access is access all Element_Type with
527 Storage_Size => 0;
529 function Get_Element_Access
530 (Position : Cursor) return not null Element_Access;
531 -- Returns a pointer to the element designated by Position.
533 Empty_Vector : constant Vector := (Capacity => 0, others => <>);
535 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
537 type Iterator is new Limited_Controlled and
538 Vector_Iterator_Interfaces.Reversible_Iterator with
539 record
540 Container : Vector_Access;
541 Index : Index_Type'Base;
542 end record
543 with Disable_Controlled => not T_Check;
545 overriding procedure Finalize (Object : in out Iterator);
547 overriding function First (Object : Iterator) return Cursor;
548 overriding function Last (Object : Iterator) return Cursor;
550 overriding function Next
551 (Object : Iterator;
552 Position : Cursor) return Cursor;
554 overriding function Previous
555 (Object : Iterator;
556 Position : Cursor) return Cursor;
558 end Ada.Containers.Bounded_Vectors;