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, 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 ------------------------------------------------------------------------------
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
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
49 Index_Type'Min (Index_Type'Base'Last - 1, Index_Type'Last) + 1;
51 No_Index : constant Extended_Index := Extended_Index'First;
53 subtype Index_Subtype is Index_Type;
55 type Vector is tagged private;
57 type Cursor is private;
59 Empty_Vector : constant Vector;
61 No_Element : constant Cursor;
63 function To_Vector (Length : Count_Type) return Vector;
66 (New_Item : Element_Type;
67 Length : Count_Type) return Vector;
69 function "&" (Left, Right : Vector) return Vector;
71 function "&" (Left : Vector; Right : Element_Type) return Vector;
73 function "&" (Left : Element_Type; Right : Vector) return Vector;
75 function "&" (Left, Right : Element_Type) return Vector;
77 function "=" (Left, Right : Vector) return Boolean;
79 function Capacity (Container : Vector) return Count_Type;
81 procedure Reserve_Capacity
82 (Container : in out Vector;
83 Capacity : Count_Type);
85 function Length (Container : Vector) return Count_Type;
87 function Is_Empty (Container : Vector) return Boolean;
89 procedure Clear (Container : in out Vector);
93 Index : Extended_Index) return Cursor;
95 function To_Index (Position : Cursor) return Extended_Index;
99 Index : Index_Type) return Element_Type;
101 function Element (Position : Cursor) return Element_Type;
103 procedure Query_Element
106 Process : not null access procedure (Element : Element_Type));
108 procedure Query_Element
110 Process : not null access procedure (Element : Element_Type));
112 procedure Update_Element
115 Process : not null access procedure (Element : in out Element_Type));
117 procedure Update_Element
119 Process : not null access procedure (Element : in out Element_Type));
121 procedure Replace_Element
126 procedure Replace_Element (Position : Cursor; By : Element_Type);
128 procedure Assign (Target : in out Vector; Source : Vector);
130 procedure Move (Target : in out Vector; Source : in out Vector);
133 (Container : in out Vector;
134 Before : Extended_Index;
138 (Container : in out Vector;
143 (Container : in out Vector;
146 Position : out Cursor);
149 (Container : in out Vector;
150 Before : Extended_Index;
151 New_Item : Element_Type;
152 Count : Count_Type := 1);
155 (Container : in out Vector;
157 New_Item : Element_Type;
158 Count : Count_Type := 1);
161 (Container : in out Vector;
163 New_Item : Element_Type;
164 Position : out Cursor;
165 Count : Count_Type := 1);
168 (Container : in out Vector;
172 (Container : in out Vector;
173 New_Item : Element_Type;
174 Count : Count_Type := 1);
177 (Container : in out Vector;
181 (Container : in out Vector;
182 New_Item : Element_Type;
183 Count : Count_Type := 1);
185 procedure Insert_Space
186 (Container : in out Vector;
187 Before : Extended_Index;
188 Count : Count_Type := 1);
190 procedure Insert_Space
191 (Container : in out Vector;
193 Position : out Cursor;
194 Count : Count_Type := 1);
197 (Container : in out Vector;
198 Length : Count_Type);
201 (Container : in out Vector;
202 Index : Extended_Index;
203 Count : Count_Type := 1);
206 (Container : in out Vector;
207 Position : in out Cursor;
208 Count : Count_Type := 1);
210 procedure Delete_First
211 (Container : in out Vector;
212 Count : Count_Type := 1);
214 procedure Delete_Last
215 (Container : in out Vector;
216 Count : Count_Type := 1);
218 function First_Index (Container : Vector) return Index_Type;
220 function First (Container : Vector) return Cursor;
222 function First_Element (Container : Vector) return Element_Type;
224 function Last_Index (Container : Vector) return Extended_Index;
226 function Last (Container : Vector) return Cursor;
228 function Last_Element (Container : Vector) return Element_Type;
230 procedure Swap (Container : Vector; I, J : Index_Type);
232 procedure Swap (I, J : Cursor);
235 with function "<" (Left, Right : Element_Type) return Boolean is <>;
236 package Generic_Sorting is
238 function Is_Sorted (Container : Vector) return Boolean;
240 procedure Sort (Container : in out Vector);
242 procedure Merge (Target, Source : in out Vector);
249 Index : Index_Type := Index_Type'First) return Extended_Index;
254 Position : Cursor := No_Element) return Cursor;
256 function Reverse_Find_Index
259 Index : Index_Type := Index_Type'Last) return Extended_Index;
261 function Reverse_Find
264 Position : Cursor := No_Element) return Cursor;
268 Item : Element_Type) return Boolean;
270 function Next (Position : Cursor) return Cursor;
272 function Previous (Position : Cursor) return Cursor;
274 procedure Next (Position : in out Cursor);
276 procedure Previous (Position : in out Cursor);
278 function Has_Element (Position : Cursor) return Boolean;
282 Process : not null access procedure (Position : Cursor));
284 procedure Reverse_Iterate
286 Process : not null access procedure (Position : Cursor));
290 pragma Inline (First_Index);
291 pragma Inline (Last_Index);
292 pragma Inline (Element);
293 pragma Inline (First_Element);
294 pragma Inline (Last_Element);
295 pragma Inline (Query_Element);
296 pragma Inline (Update_Element);
297 pragma Inline (Replace_Element);
298 pragma Inline (Contains);
300 type Elements_Type is array (Index_Type range <>) of Element_Type;
302 function "=" (L, R : Elements_Type) return Boolean is abstract;
304 type Elements_Access is access Elements_Type;
306 use Ada.Finalization;
308 type Vector is new Controlled with record
309 Elements : Elements_Access;
310 Last : Extended_Index := No_Index;
315 procedure Adjust (Container : in out Vector);
317 procedure Finalize (Container : in out Vector);
322 (Stream : access Root_Stream_Type'Class;
325 for Vector'Write use Write;
328 (Stream : access Root_Stream_Type'Class;
329 Container : out Vector);
331 for Vector'Read use Read;
333 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
335 type Vector_Access is access constant Vector;
336 for Vector_Access'Storage_Size use 0;
338 type Cursor is record
339 Container : Vector_Access;
340 Index : Index_Type := Index_Type'First;
343 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
345 end Ada.Containers.Vectors;