1 ------------------------------------------------------------------------------
3 -- GNAT LIBRARY COMPONENTS --
5 -- A D A . C O N T A I N E R S . V E C T O R S --
9 -- Copyright (C) 2004-2007, 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 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
.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;
56 pragma Preelaborable_Initialization (Vector);
58 type Cursor is private;
59 pragma Preelaborable_Initialization (Cursor);
61 Empty_Vector : constant Vector;
63 No_Element : constant Cursor;
65 function "=" (Left, Right : Vector) return Boolean;
67 function To_Vector (Length : Count_Type) return Vector;
70 (New_Item : Element_Type;
71 Length : Count_Type) return Vector;
73 function "&" (Left, Right : Vector) return Vector;
75 function "&" (Left : Vector; Right : Element_Type) return Vector;
77 function "&" (Left : Element_Type; Right : Vector) return Vector;
79 function "&" (Left, Right : Element_Type) return Vector;
81 function Capacity (Container : Vector) return Count_Type;
83 procedure Reserve_Capacity
84 (Container : in out Vector;
85 Capacity : Count_Type);
87 function Length (Container : Vector) return Count_Type;
90 (Container : in out Vector;
93 function Is_Empty (Container : Vector) return Boolean;
95 procedure Clear (Container : in out Vector);
99 Index : Extended_Index) return Cursor;
101 function To_Index (Position : Cursor) return Extended_Index;
105 Index : Index_Type) return Element_Type;
107 function Element (Position : Cursor) return Element_Type;
109 procedure Replace_Element
110 (Container : in out Vector;
112 New_Item : Element_Type);
114 procedure Replace_Element
115 (Container : in out Vector;
117 New_Item : Element_Type);
119 procedure Query_Element
122 Process : not null access procedure (Element : Element_Type));
124 procedure Query_Element
126 Process : not null access procedure (Element : Element_Type));
128 procedure Update_Element
129 (Container : in out Vector;
131 Process : not null access procedure (Element : in out Element_Type));
133 procedure Update_Element
134 (Container : in out Vector;
136 Process : not null access procedure (Element : in out Element_Type));
138 procedure Move (Target : in out Vector; Source : in out Vector);
141 (Container : in out Vector;
142 Before : Extended_Index;
146 (Container : in out Vector;
151 (Container : in out Vector;
154 Position : out Cursor);
157 (Container : in out Vector;
158 Before : Extended_Index;
159 New_Item : Element_Type;
160 Count : Count_Type := 1);
163 (Container : in out Vector;
165 New_Item : Element_Type;
166 Count : Count_Type := 1);
169 (Container : in out Vector;
171 New_Item : Element_Type;
172 Position : out Cursor;
173 Count : Count_Type := 1);
176 (Container : in out Vector;
177 Before : Extended_Index;
178 Count : Count_Type := 1);
181 (Container : in out Vector;
183 Position : out Cursor;
184 Count : Count_Type := 1);
187 (Container : in out Vector;
191 (Container : in out Vector;
192 New_Item : Element_Type;
193 Count : Count_Type := 1);
196 (Container : in out Vector;
200 (Container : in out Vector;
201 New_Item : Element_Type;
202 Count : Count_Type := 1);
204 procedure Insert_Space
205 (Container : in out Vector;
206 Before : Extended_Index;
207 Count : Count_Type := 1);
209 procedure Insert_Space
210 (Container : in out Vector;
212 Position : out Cursor;
213 Count : Count_Type := 1);
216 (Container : in out Vector;
217 Index : Extended_Index;
218 Count : Count_Type := 1);
221 (Container : in out Vector;
222 Position : in out Cursor;
223 Count : Count_Type := 1);
225 procedure Delete_First
226 (Container : in out Vector;
227 Count : Count_Type := 1);
229 procedure Delete_Last
230 (Container : in out Vector;
231 Count : Count_Type := 1);
233 procedure Reverse_Elements (Container : in out Vector);
235 procedure Swap (Container : in out Vector; I, J : Index_Type);
237 procedure Swap (Container : in out Vector; I, J : Cursor);
239 function First_Index (Container : Vector) return Index_Type;
241 function First (Container : Vector) return Cursor;
243 function First_Element (Container : Vector) return Element_Type;
245 function Last_Index (Container : Vector) return Extended_Index;
247 function Last (Container : Vector) return Cursor;
249 function Last_Element (Container : Vector) return Element_Type;
251 function Next (Position : Cursor) return Cursor;
253 procedure Next (Position : in out Cursor);
255 function Previous (Position : Cursor) return Cursor;
257 procedure Previous (Position : in out Cursor);
262 Index : Index_Type := Index_Type'First) return Extended_Index;
267 Position : Cursor := No_Element) return Cursor;
269 function Reverse_Find_Index
272 Index : Index_Type := Index_Type'Last) return Extended_Index;
274 function Reverse_Find
277 Position : Cursor := No_Element) return Cursor;
281 Item : Element_Type) return Boolean;
283 function Has_Element (Position : Cursor) return Boolean;
287 Process : not null access procedure (Position : Cursor));
289 procedure Reverse_Iterate
291 Process : not null access procedure (Position : Cursor));
294 with function "<" (Left, Right : Element_Type) return Boolean is <>;
295 package Generic_Sorting is
297 function Is_Sorted (Container : Vector) return Boolean;
299 procedure Sort (Container : in out Vector);
301 procedure Merge (Target : in out Vector; Source : in out Vector);
307 pragma Inline (First_Index);
308 pragma Inline (Last_Index);
309 pragma Inline (Element);
310 pragma Inline (First_Element);
311 pragma Inline (Last_Element);
312 pragma Inline (Query_Element);
313 pragma Inline (Update_Element);
314 pragma Inline (Replace_Element);
315 pragma Inline (Contains);
316 pragma Inline (Next);
317 pragma Inline (Previous);
319 type Elements_Array is array (Index_Type range <>) of Element_Type;
320 function "=" (L, R : Elements_Array) return Boolean is abstract;
322 type Elements_Type (Last : Index_Type) is limited record
323 EA : Elements_Array (Index_Type'First .. Last);
326 type Elements_Access is access Elements_Type;
328 use Ada.Finalization;
330 type Vector is new Controlled with record
331 Elements : Elements_Access;
332 Last : Extended_Index := No_Index;
338 procedure Adjust (Container : in out Vector);
341 procedure Finalize (Container : in out Vector);
346 (Stream : not null access Root_Stream_Type'Class;
349 for Vector'Write use Write;
352 (Stream : not null access Root_Stream_Type'Class;
353 Container : out Vector);
355 for Vector'Read use Read;
357 type Vector_Access is access constant Vector;
358 for Vector_Access'Storage_Size use 0;
360 type Cursor is record
361 Container : Vector_Access;
362 Index : Index_Type := Index_Type'First;
366 (Stream : not null access Root_Stream_Type'Class;
369 for Cursor'Write use Write;
372 (Stream : not null access Root_Stream_Type'Class;
373 Position : out Cursor);
375 for Cursor'Read use Read;
377 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
379 No_Element : constant Cursor := Cursor'(null, Index_Type
'First);
381 end Ada
.Containers
.Vectors
;