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-2011, 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 private with Ada
.Finalization
;
36 with Ada
.Streams
; use Ada
.Streams
;
37 with Ada
.Iterator_Interfaces
;
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;
70 function Has_Element (Position : Cursor) return Boolean;
73 (Stream : not null access Root_Stream_Type'Class;
74 Position : out Cursor);
76 for Cursor'Read use Read;
79 (Stream : not null access Root_Stream_Type'Class;
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;
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;
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
122 Implicit_Dereference => Element;
125 (Stream : not null access Root_Stream_Type'Class;
126 Item : Constant_Reference_Type);
128 for Constant_Reference_Type'Write use Write;
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
138 Implicit_Dereference => Element;
141 (Stream : not null access Root_Stream_Type'Class;
142 Item : Reference_Type);
144 for Reference_Type'Write use Write;
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;
168 Index : Extended_Index) return Cursor;
170 function To_Index (Position : Cursor) return Extended_Index;
174 Index : Index_Type) return Element_Type;
176 function Element (Position : Cursor) return Element_Type;
178 procedure Replace_Element
179 (Container : in out Vector;
181 New_Item : Element_Type);
183 procedure Replace_Element
184 (Container : in out Vector;
186 New_Item : Element_Type);
188 procedure Query_Element
191 Process : not null access procedure (Element : Element_Type));
193 procedure Query_Element
195 Process : not null access procedure (Element : Element_Type));
197 procedure Update_Element
198 (Container : in out Vector;
200 Process : not null access procedure (Element : in out Element_Type));
202 procedure Update_Element
203 (Container : in out Vector;
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);
214 (Container : in out Vector;
215 Before : Extended_Index;
219 (Container : in out Vector;
224 (Container : in out Vector;
227 Position : out Cursor);
230 (Container : in out Vector;
231 Before : Extended_Index;
232 New_Item : Element_Type;
233 Count : Count_Type := 1);
236 (Container : in out Vector;
238 New_Item : Element_Type;
239 Count : Count_Type := 1);
242 (Container : in out Vector;
244 New_Item : Element_Type;
245 Position : out Cursor;
246 Count : Count_Type := 1);
249 (Container : in out Vector;
253 (Container : in out Vector;
254 New_Item : Element_Type;
255 Count : Count_Type := 1);
258 (Container : in out Vector;
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;
274 Position : out Cursor;
275 Count : Count_Type := 1);
278 (Container : in out Vector;
279 Index : Extended_Index;
280 Count : Count_Type := 1);
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);
324 Index : Index_Type := Index_Type'First) return Extended_Index;
329 Position : Cursor := No_Element) return Cursor;
331 function Reverse_Find_Index
334 Index : Index_Type := Index_Type'Last) return Extended_Index;
336 function Reverse_Find
339 Position : Cursor := No_Element) return Cursor;
343 Item : Element_Type) return Boolean;
347 Process : not null access procedure (Position : Cursor));
349 function Iterate (Container : Vector)
350 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
355 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
357 procedure Reverse_Iterate
359 Process : not null access procedure (Position : Cursor));
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);
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);
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;
407 type Constant_Reference_Type
408 (Element : not null access constant Element_Type) is null record;
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);
418 (Stream : not null access Root_Stream_Type'Class;
421 for Vector'Write use Write;
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;
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
;