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 Move (Target : in out Vector; Source : in out Vector);
210 (Container : in out Vector;
211 Before : Extended_Index;
215 (Container : in out Vector;
220 (Container : in out Vector;
223 Position : out Cursor);
226 (Container : in out Vector;
227 Before : Extended_Index;
228 New_Item : Element_Type;
229 Count : Count_Type := 1);
232 (Container : in out Vector;
234 New_Item : Element_Type;
235 Count : Count_Type := 1);
238 (Container : in out Vector;
240 New_Item : Element_Type;
241 Position : out Cursor;
242 Count : Count_Type := 1);
245 (Container : in out Vector;
249 (Container : in out Vector;
250 New_Item : Element_Type;
251 Count : Count_Type := 1);
254 (Container : in out Vector;
258 (Container : in out Vector;
259 New_Item : Element_Type;
260 Count : Count_Type := 1);
262 procedure Insert_Space
263 (Container : in out Vector;
264 Before : Extended_Index;
265 Count : Count_Type := 1);
267 procedure Insert_Space
268 (Container : in out Vector;
270 Position : out Cursor;
271 Count : Count_Type := 1);
274 (Container : in out Vector;
275 Index : Extended_Index;
276 Count : Count_Type := 1);
279 (Container : in out Vector;
280 Position : in out Cursor;
281 Count : Count_Type := 1);
283 procedure Delete_First
284 (Container : in out Vector;
285 Count : Count_Type := 1);
287 procedure Delete_Last
288 (Container : in out Vector;
289 Count : Count_Type := 1);
291 procedure Reverse_Elements (Container : in out Vector);
293 procedure Swap (Container : in out Vector; I, J : Index_Type);
295 procedure Swap (Container : in out Vector; I, J : Cursor);
297 function First_Index (Container : Vector) return Index_Type;
299 function First (Container : Vector) return Cursor;
301 function First_Element (Container : Vector) return Element_Type;
303 function Last_Index (Container : Vector) return Extended_Index;
305 function Last (Container : Vector) return Cursor;
307 function Last_Element (Container : Vector) return Element_Type;
309 function Next (Position : Cursor) return Cursor;
311 procedure Next (Position : in out Cursor);
313 function Previous (Position : Cursor) return Cursor;
315 procedure Previous (Position : in out Cursor);
320 Index : Index_Type := Index_Type'First) return Extended_Index;
325 Position : Cursor := No_Element) return Cursor;
327 function Reverse_Find_Index
330 Index : Index_Type := Index_Type'Last) return Extended_Index;
332 function Reverse_Find
335 Position : Cursor := No_Element) return Cursor;
339 Item : Element_Type) return Boolean;
343 Process : not null access procedure (Position : Cursor));
345 function Iterate (Container : Vector)
346 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
351 return Vector_Iterator_Interfaces.Reversible_Iterator'class;
353 procedure Reverse_Iterate
355 Process : not null access procedure (Position : Cursor));
358 with function "<" (Left, Right : Element_Type) return Boolean is <>;
359 package Generic_Sorting is
361 function Is_Sorted (Container : Vector) return Boolean;
363 procedure Sort (Container : in out Vector);
365 procedure Merge (Target : in out Vector; Source : in out Vector);
371 pragma Inline (First_Index);
372 pragma Inline (Last_Index);
373 pragma Inline (Element);
374 pragma Inline (First_Element);
375 pragma Inline (Last_Element);
376 pragma Inline (Query_Element);
377 pragma Inline (Update_Element);
378 pragma Inline (Replace_Element);
379 pragma Inline (Contains);
380 pragma Inline (Next);
381 pragma Inline (Previous);
383 type Element_Access is access Element_Type;
385 type Elements_Array is array (Index_Type range <>) of Element_Access;
386 function "=" (L, R : Elements_Array) return Boolean is abstract;
388 type Elements_Type (Last : Index_Type) is limited record
389 EA : Elements_Array (Index_Type'First .. Last);
392 type Elements_Access is access Elements_Type;
394 use Ada.Finalization;
396 type Vector is new Controlled with record
397 Elements : Elements_Access;
398 Last : Extended_Index := No_Index;
403 type Constant_Reference_Type
404 (Element : not null access constant Element_Type) is null record;
407 (Element : not null access Element_Type) is null record;
409 overriding procedure Adjust (Container : in out Vector);
411 overriding procedure Finalize (Container : in out Vector);
414 (Stream : not null access Root_Stream_Type'Class;
417 for Vector'Write use Write;
420 (Stream : not null access Root_Stream_Type'Class;
421 Container : out Vector);
423 for Vector'Read use Read;
425 type Vector_Access is access constant Vector;
426 for Vector_Access'Storage_Size use 0;
428 type Cursor is record
429 Container : Vector_Access;
430 Index : Index_Type := Index_Type'First;
433 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
435 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
437 end Ada.Containers.Indefinite_Vectors;