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-2005 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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, 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 ------------------------------------------------------------------------------
35 with Ada.Finalization;
39 type Index_Type is range <>;
40 type Element_Type is private;
42 with function "=" (Left, Right : Element_Type) return Boolean is <>;
44 package Ada.Containers.Vectors is
45 pragma Preelaborate (Vectors);
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
50 Boolean'Pos (Index_Type'Base'Last > Index_Type'Last);
52 No_Index : constant Extended_Index := Extended_Index'First;
54 subtype Index_Subtype is Index_Type;
56 type Vector is tagged private;
58 type Cursor is private;
60 Empty_Vector : constant Vector;
62 No_Element : constant Cursor;
64 function To_Vector (Length : Count_Type) return Vector;
67 (New_Item : Element_Type;
68 Length : Count_Type) return Vector;
70 function "&" (Left, Right : Vector) return Vector;
72 function "&" (Left : Vector; Right : Element_Type) return Vector;
74 function "&" (Left : Element_Type; Right : Vector) return Vector;
76 function "&" (Left, Right : Element_Type) return Vector;
78 function "=" (Left, Right : Vector) return Boolean;
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;
88 function Is_Empty (Container : Vector) return Boolean;
90 procedure Clear (Container : in out Vector);
94 Index : Extended_Index) return Cursor;
96 function To_Index (Position : Cursor) return Extended_Index;
100 Index : Index_Type) return Element_Type;
102 function Element (Position : Cursor) return Element_Type;
104 procedure Query_Element
107 Process : not null access procedure (Element : Element_Type));
109 procedure Query_Element
111 Process : not null access procedure (Element : Element_Type));
113 procedure Update_Element
116 Process : not null access procedure (Element : in out Element_Type));
118 procedure Update_Element
120 Process : not null access procedure (Element : in out Element_Type));
122 procedure Replace_Element
127 procedure Replace_Element (Position : Cursor; By : Element_Type);
129 procedure Assign (Target : in out Vector; Source : Vector);
131 procedure Move (Target : in out Vector; Source : in out Vector);
134 (Container : in out Vector;
135 Before : Extended_Index;
139 (Container : in out Vector;
144 (Container : in out Vector;
147 Position : out Cursor);
150 (Container : in out Vector;
151 Before : Extended_Index;
152 New_Item : Element_Type;
153 Count : Count_Type := 1);
156 (Container : in out Vector;
158 New_Item : Element_Type;
159 Count : Count_Type := 1);
162 (Container : in out Vector;
164 New_Item : Element_Type;
165 Position : out Cursor;
166 Count : Count_Type := 1);
169 (Container : in out Vector;
173 (Container : in out Vector;
174 New_Item : Element_Type;
175 Count : Count_Type := 1);
178 (Container : in out Vector;
182 (Container : in out Vector;
183 New_Item : Element_Type;
184 Count : Count_Type := 1);
186 procedure Insert_Space
187 (Container : in out Vector;
188 Before : Extended_Index;
189 Count : Count_Type := 1);
191 procedure Insert_Space
192 (Container : in out Vector;
194 Position : out Cursor;
195 Count : Count_Type := 1);
198 (Container : in out Vector;
199 Length : Count_Type);
202 (Container : in out Vector;
203 Index : Extended_Index;
204 Count : Count_Type := 1);
207 (Container : in out Vector;
208 Position : in out Cursor;
209 Count : Count_Type := 1);
211 procedure Delete_First
212 (Container : in out Vector;
213 Count : Count_Type := 1);
215 procedure Delete_Last
216 (Container : in out Vector;
217 Count : Count_Type := 1);
219 function First_Index (Container : Vector) return Index_Type;
221 function First (Container : Vector) return Cursor;
223 function First_Element (Container : Vector) return Element_Type;
225 function Last_Index (Container : Vector) return Extended_Index;
227 function Last (Container : Vector) return Cursor;
229 function Last_Element (Container : Vector) return Element_Type;
231 procedure Swap (Container : Vector; I, J : Index_Type);
233 procedure Swap (I, J : Cursor);
236 with function "<" (Left, Right : Element_Type) return Boolean is <>;
237 package Generic_Sorting is
239 function Is_Sorted (Container : Vector) return Boolean;
241 procedure Sort (Container : in out Vector);
243 procedure Merge (Target, Source : in out Vector);
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 Next (Position : Cursor) return Cursor;
273 function Previous (Position : Cursor) return Cursor;
275 procedure Next (Position : in out Cursor);
277 procedure Previous (Position : in out Cursor);
279 function Has_Element (Position : Cursor) return Boolean;
283 Process : not null access procedure (Position : Cursor));
285 procedure Reverse_Iterate
287 Process : not null access procedure (Position : Cursor));
291 pragma Inline (First_Index);
292 pragma Inline (Last_Index);
293 pragma Inline (Element);
294 pragma Inline (First_Element);
295 pragma Inline (Last_Element);
296 pragma Inline (Query_Element);
297 pragma Inline (Update_Element);
298 pragma Inline (Replace_Element);
299 pragma Inline (Contains);
301 type Elements_Type is array (Index_Type range <>) of Element_Type;
303 function "=" (L, R : Elements_Type) return Boolean is abstract;
305 type Elements_Access is access Elements_Type;
307 use Ada.Finalization;
309 type Vector is new Controlled with record
310 Elements : Elements_Access;
311 Last : Extended_Index := No_Index;
316 procedure Adjust (Container : in out Vector);
318 procedure Finalize (Container : in out Vector);
323 (Stream : access Root_Stream_Type'Class;
326 for Vector'Write use Write;
329 (Stream : access Root_Stream_Type'Class;
330 Container : out Vector);
332 for Vector'Read use Read;
334 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
336 type Vector_Access is access constant Vector;
337 for Vector_Access'Storage_Size use 0;
339 type Cursor is record
340 Container : Vector_Access;
341 Index : Index_Type := Index_Type'First;
344 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
346 end Ada.Containers.Vectors;