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-2006, 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 2, 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. See the GNU General Public License --
21 -- for more details. You should have received a copy of the GNU General --
22 -- Public License distributed with GNAT; see file COPYING. If not, write --
23 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
24 -- Boston, MA 02110-1301, USA. --
26 -- As a special exception, if other files instantiate generics from this --
27 -- unit, or you link this unit with other files to produce an executable, --
28 -- this unit does not by itself cause the resulting executable to be --
29 -- covered by the GNU General Public License. This exception does not --
30 -- however invalidate any other reasons why the executable file might be --
31 -- covered by the GNU Public License. --
33 -- This unit was originally developed by Matthew J Heaney. --
34 ------------------------------------------------------------------------------
36 with Ada.Finalization;
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
48 subtype Extended_Index is Index_Type'Base
49 range Index_Type'First - 1 ..
50 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
52 No_Index : constant Extended_Index := Extended_Index'First;
54 type Vector is tagged private;
55 pragma Preelaborable_Initialization (Vector);
57 type Cursor is private;
58 pragma Preelaborable_Initialization (Cursor);
60 Empty_Vector : constant Vector;
62 No_Element : constant Cursor;
64 function "=" (Left, Right : Vector) return Boolean;
66 function To_Vector (Length : Count_Type) return Vector;
69 (New_Item : Element_Type;
70 Length : Count_Type) return Vector;
72 function "&" (Left, Right : Vector) return Vector;
74 function "&" (Left : Vector; Right : Element_Type) return Vector;
76 function "&" (Left : Element_Type; Right : Vector) return Vector;
78 function "&" (Left, Right : Element_Type) return Vector;
80 function Capacity (Container : Vector) return Count_Type;
82 procedure Reserve_Capacity
83 (Container : in out Vector;
84 Capacity : Count_Type);
86 function Length (Container : Vector) return Count_Type;
89 (Container : in out Vector;
92 function Is_Empty (Container : Vector) return Boolean;
94 procedure Clear (Container : in out Vector);
98 Index : Extended_Index) return Cursor;
100 function To_Index (Position : Cursor) return Extended_Index;
104 Index : Index_Type) return Element_Type;
106 function Element (Position : Cursor) return Element_Type;
108 procedure Replace_Element
109 (Container : in out Vector;
111 New_Item : Element_Type);
113 procedure Replace_Element
114 (Container : in out Vector;
116 New_Item : Element_Type);
118 procedure Query_Element
121 Process : not null access procedure (Element : Element_Type));
123 procedure Query_Element
125 Process : not null access procedure (Element : Element_Type));
127 procedure Update_Element
128 (Container : in out Vector;
130 Process : not null access procedure (Element : in out Element_Type));
132 procedure Update_Element
133 (Container : in out Vector;
135 Process : not null access procedure (Element : in out Element_Type));
137 procedure Move (Target : in out Vector; Source : in out Vector);
140 (Container : in out Vector;
141 Before : Extended_Index;
145 (Container : in out Vector;
150 (Container : in out Vector;
153 Position : out Cursor);
156 (Container : in out Vector;
157 Before : Extended_Index;
158 New_Item : Element_Type;
159 Count : Count_Type := 1);
162 (Container : in out Vector;
164 New_Item : Element_Type;
165 Count : Count_Type := 1);
168 (Container : in out Vector;
170 New_Item : Element_Type;
171 Position : out Cursor;
172 Count : Count_Type := 1);
175 (Container : in out Vector;
179 (Container : in out Vector;
180 New_Item : Element_Type;
181 Count : Count_Type := 1);
184 (Container : in out Vector;
188 (Container : in out Vector;
189 New_Item : Element_Type;
190 Count : Count_Type := 1);
192 procedure Insert_Space
193 (Container : in out Vector;
194 Before : Extended_Index;
195 Count : Count_Type := 1);
197 procedure Insert_Space
198 (Container : in out Vector;
200 Position : out Cursor;
201 Count : Count_Type := 1);
204 (Container : in out Vector;
205 Index : Extended_Index;
206 Count : Count_Type := 1);
209 (Container : in out Vector;
210 Position : in out Cursor;
211 Count : Count_Type := 1);
213 procedure Delete_First
214 (Container : in out Vector;
215 Count : Count_Type := 1);
217 procedure Delete_Last
218 (Container : in out Vector;
219 Count : Count_Type := 1);
221 procedure Reverse_Elements (Container : in out Vector);
223 procedure Swap (Container : in out Vector; I, J : Index_Type);
225 procedure Swap (Container : in out Vector; I, J : Cursor);
227 function First_Index (Container : Vector) return Index_Type;
229 function First (Container : Vector) return Cursor;
231 function First_Element (Container : Vector) return Element_Type;
233 function Last_Index (Container : Vector) return Extended_Index;
235 function Last (Container : Vector) return Cursor;
237 function Last_Element (Container : Vector) return Element_Type;
239 function Next (Position : Cursor) return Cursor;
241 procedure Next (Position : in out Cursor);
243 function Previous (Position : Cursor) return Cursor;
245 procedure Previous (Position : in out Cursor);
250 Index : Index_Type := Index_Type'First) return Extended_Index;
255 Position : Cursor := No_Element) return Cursor;
257 function Reverse_Find_Index
260 Index : Index_Type := Index_Type'Last) return Extended_Index;
262 function Reverse_Find
265 Position : Cursor := No_Element) return Cursor;
269 Item : Element_Type) return Boolean;
271 function Has_Element (Position : Cursor) return Boolean;
275 Process : not null access procedure (Position : Cursor));
277 procedure Reverse_Iterate
279 Process : not null access procedure (Position : Cursor));
282 with function "<" (Left, Right : Element_Type) return Boolean is <>;
283 package Generic_Sorting is
285 function Is_Sorted (Container : Vector) return Boolean;
287 procedure Sort (Container : in out Vector);
289 procedure Merge (Target : in out Vector; Source : in out Vector);
295 pragma Inline (First_Index);
296 pragma Inline (Last_Index);
297 pragma Inline (Element);
298 pragma Inline (First_Element);
299 pragma Inline (Last_Element);
300 pragma Inline (Query_Element);
301 pragma Inline (Update_Element);
302 pragma Inline (Replace_Element);
303 pragma Inline (Contains);
305 type Element_Access is access Element_Type;
307 type Elements_Type is array (Index_Type range <>) of Element_Access;
309 function "=" (L, R : Elements_Type) return Boolean is abstract;
311 type Elements_Access is access Elements_Type;
313 use Ada.Finalization;
315 type Vector is new Controlled with record
316 Elements : Elements_Access;
317 Last : Extended_Index := No_Index;
322 procedure Adjust (Container : in out Vector);
324 procedure Finalize (Container : in out Vector);
329 (Stream : not null access Root_Stream_Type'Class;
332 for Vector'Write use Write;
335 (Stream : not null access Root_Stream_Type'Class;
336 Container : out Vector);
338 for Vector'Read use Read;
340 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
342 type Vector_Access is access constant Vector;
343 for Vector_Access'Storage_Size use 0;
345 type Cursor is record
346 Container : Vector_Access;
347 Index : Index_Type := Index_Type'First;
351 (Stream : not null access Root_Stream_Type'Class;
354 for Cursor'Write use Write;
357 (Stream : not null access Root_Stream_Type'Class;
358 Position : out Cursor);
360 for Cursor'Read use Read;
362 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
364 end Ada.Containers.Indefinite_Vectors;