1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
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 --
9 -- Copyright (C) 2004-2012, Free Software Foundation, Inc. --
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. --
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. --
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. --
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/>. --
31 -- This unit was originally developed by Matthew J Heaney. --
32 ------------------------------------------------------------------------------
34 with Ada
.Iterator_Interfaces
;
36 private with Ada
.Finalization
;
37 private with Ada
.Streams
;
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
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
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;
71 function Has_Element (Position : Cursor) return Boolean;
73 package Vector_Iterator_Interfaces is new
74 Ada.Iterator_Interfaces (Cursor, Has_Element);
76 overriding function "=" (Left, Right : Vector) return Boolean;
78 function To_Vector (Length : Count_Type) return Vector;
81 (New_Item : Element_Type;
82 Length : Count_Type) return Vector;
84 function "&" (Left, Right : Vector) return Vector;
86 function "&" (Left : Vector; Right : Element_Type) return Vector;
88 function "&" (Left : Element_Type; Right : Vector) return Vector;
90 function "&" (Left, Right : Element_Type) return Vector;
92 function Capacity (Container : Vector) return Count_Type;
94 procedure Reserve_Capacity
95 (Container : in out Vector;
96 Capacity : Count_Type);
98 function Length (Container : Vector) return Count_Type;
101 (Container : in out Vector;
102 Length : Count_Type);
104 function Is_Empty (Container : Vector) return Boolean;
106 procedure Clear (Container : in out Vector);
108 type Constant_Reference_Type
109 (Element : not null access constant Element_Type) is private
111 Implicit_Dereference => Element;
113 type Reference_Type (Element : not null access Element_Type) is private
115 Implicit_Dereference => Element;
117 function Constant_Reference
118 (Container : aliased Vector;
119 Position : Cursor) return Constant_Reference_Type;
120 pragma Inline (Constant_Reference);
123 (Container : aliased in out Vector;
124 Position : Cursor) return Reference_Type;
125 pragma Inline (Reference);
127 function Constant_Reference
128 (Container : aliased Vector;
129 Index : Index_Type) return Constant_Reference_Type;
130 pragma Inline (Constant_Reference);
133 (Container : aliased in out Vector;
134 Index : Index_Type) return Reference_Type;
135 pragma Inline (Reference);
139 Index : Extended_Index) return Cursor;
141 function To_Index (Position : Cursor) return Extended_Index;
145 Index : Index_Type) return Element_Type;
147 function Element (Position : Cursor) return Element_Type;
149 procedure Replace_Element
150 (Container : in out Vector;
152 New_Item : Element_Type);
154 procedure Replace_Element
155 (Container : in out Vector;
157 New_Item : Element_Type);
159 procedure Query_Element
162 Process : not null access procedure (Element : Element_Type));
164 procedure Query_Element
166 Process : not null access procedure (Element : Element_Type));
168 procedure Update_Element
169 (Container : in out Vector;
171 Process : not null access procedure (Element : in out Element_Type));
173 procedure Update_Element
174 (Container : in out Vector;
176 Process : not null access procedure (Element : in out Element_Type));
178 procedure Assign (Target : in out Vector; Source : Vector);
180 function Copy (Source : Vector; Capacity : Count_Type := 0) return Vector;
182 procedure Move (Target : in out Vector; Source : in out Vector);
185 (Container : in out Vector;
186 Before : Extended_Index;
190 (Container : in out Vector;
195 (Container : in out Vector;
198 Position : out Cursor);
201 (Container : in out Vector;
202 Before : Extended_Index;
203 New_Item : Element_Type;
204 Count : Count_Type := 1);
207 (Container : in out Vector;
209 New_Item : Element_Type;
210 Count : Count_Type := 1);
213 (Container : in out Vector;
215 New_Item : Element_Type;
216 Position : out Cursor;
217 Count : Count_Type := 1);
220 (Container : in out Vector;
224 (Container : in out Vector;
225 New_Item : Element_Type;
226 Count : Count_Type := 1);
229 (Container : in out Vector;
233 (Container : in out Vector;
234 New_Item : Element_Type;
235 Count : Count_Type := 1);
237 procedure Insert_Space
238 (Container : in out Vector;
239 Before : Extended_Index;
240 Count : Count_Type := 1);
242 procedure Insert_Space
243 (Container : in out Vector;
245 Position : out Cursor;
246 Count : Count_Type := 1);
249 (Container : in out Vector;
250 Index : Extended_Index;
251 Count : Count_Type := 1);
254 (Container : in out Vector;
255 Position : in out Cursor;
256 Count : Count_Type := 1);
258 procedure Delete_First
259 (Container : in out Vector;
260 Count : Count_Type := 1);
262 procedure Delete_Last
263 (Container : in out Vector;
264 Count : Count_Type := 1);
266 procedure Reverse_Elements (Container : in out Vector);
268 procedure Swap (Container : in out Vector; I, J : Index_Type);
270 procedure Swap (Container : in out Vector; I, J : Cursor);
272 function First_Index (Container : Vector) return Index_Type;
274 function First (Container : Vector) return Cursor;
276 function First_Element (Container : Vector) return Element_Type;
278 function Last_Index (Container : Vector) return Extended_Index;
280 function Last (Container : Vector) return Cursor;
282 function Last_Element (Container : Vector) return Element_Type;
284 function Next (Position : Cursor) return Cursor;
286 procedure Next (Position : in out Cursor);
288 function Previous (Position : Cursor) return Cursor;
290 procedure Previous (Position : in out Cursor);
295 Index : Index_Type := Index_Type'First) return Extended_Index;
300 Position : Cursor := No_Element) return Cursor;
302 function Reverse_Find_Index
305 Index : Index_Type := Index_Type'Last) return Extended_Index;
307 function Reverse_Find
310 Position : Cursor := No_Element) return Cursor;
314 Item : Element_Type) return Boolean;
318 Process : not null access procedure (Position : Cursor));
320 function Iterate (Container : Vector)
321 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
326 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
328 procedure Reverse_Iterate
330 Process : not null access procedure (Position : Cursor));
333 with function "<" (Left, Right : Element_Type) return Boolean is <>;
334 package Generic_Sorting is
336 function Is_Sorted (Container : Vector) return Boolean;
338 procedure Sort (Container : in out Vector);
340 procedure Merge (Target : in out Vector; Source : in out Vector);
346 pragma Inline (First_Index);
347 pragma Inline (Last_Index);
348 pragma Inline (Element);
349 pragma Inline (First_Element);
350 pragma Inline (Last_Element);
351 pragma Inline (Query_Element);
352 pragma Inline (Update_Element);
353 pragma Inline (Replace_Element);
354 pragma Inline (Contains);
355 pragma Inline (Next);
356 pragma Inline (Previous);
358 type Element_Access is access Element_Type;
360 type Elements_Array is array (Index_Type range <>) of Element_Access;
361 function "=" (L, R : Elements_Array) return Boolean is abstract;
363 type Elements_Type (Last : Index_Type) is limited record
364 EA : Elements_Array (Index_Type'First .. Last);
367 type Elements_Access is access Elements_Type;
369 type Vector is new Ada.Finalization.Controlled with record
370 Elements : Elements_Access;
371 Last : Extended_Index := No_Index;
376 overriding procedure Adjust (Container : in out Vector);
378 overriding procedure Finalize (Container : in out Vector);
380 use Ada.Finalization;
384 (Stream : not null access Root_Stream_Type'Class;
387 for Vector'Write use Write;
390 (Stream : not null access Root_Stream_Type'Class;
391 Container : out Vector);
393 for Vector'Read use Read;
395 type Vector_Access is access all Vector;
396 for Vector_Access'Storage_Size use 0;
398 type Cursor is record
399 Container : Vector_Access;
400 Index : Index_Type := Index_Type'First;
404 (Stream : not null access Root_Stream_Type'Class;
405 Position : out Cursor);
407 for Cursor'Read use Read;
410 (Stream : not null access Root_Stream_Type'Class;
413 for Cursor'Write use Write;
415 type Reference_Control_Type is
416 new Controlled with record
417 Container : Vector_Access;
420 overriding procedure Adjust (Control : in out Reference_Control_Type);
421 pragma Inline (Adjust);
423 overriding procedure Finalize (Control : in out Reference_Control_Type);
424 pragma Inline (Finalize);
426 type Constant_Reference_Type
427 (Element : not null access constant Element_Type) is
429 Control : Reference_Control_Type;
433 (Stream : not null access Root_Stream_Type'Class;
434 Item : Constant_Reference_Type);
436 for Constant_Reference_Type'Write use Write;
439 (Stream : not null access Root_Stream_Type'Class;
440 Item : out Constant_Reference_Type);
442 for Constant_Reference_Type'Read use Read;
445 (Element : not null access Element_Type) is
447 Control : Reference_Control_Type;
451 (Stream : not null access Root_Stream_Type'Class;
452 Item : Reference_Type);
454 for Reference_Type'Write use Write;
457 (Stream : not null access Root_Stream_Type'Class;
458 Item : out Reference_Type);
460 for Reference_Type'Read use Read;
462 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
464 No_Element : constant Cursor := Cursor'(null, Index_Type
'First);
466 end Ada
.Containers
.Indefinite_Vectors
;