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 type Vector is tagged private;
55 type Cursor is private;
57 Empty_Vector : constant Vector;
59 No_Element : constant Cursor;
61 function "=" (Left, Right : Vector) return Boolean;
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 Capacity (Container : Vector) return Count_Type;
79 procedure Reserve_Capacity
80 (Container : in out Vector;
81 Capacity : Count_Type);
83 function Length (Container : Vector) return Count_Type;
86 (Container : in out Vector;
89 function Is_Empty (Container : Vector) return Boolean;
91 procedure Clear (Container : in out Vector);
95 Index : Extended_Index) return Cursor;
97 function To_Index (Position : Cursor) return Extended_Index;
101 Index : Index_Type) return Element_Type;
103 function Element (Position : Cursor) return Element_Type;
105 procedure Replace_Element
106 (Container : in out Vector;
108 New_Item : Element_Type);
110 procedure Replace_Element
111 (Container : in out Vector;
113 New_Item : Element_Type);
115 procedure Query_Element
118 Process : not null access procedure (Element : Element_Type));
120 procedure Query_Element
122 Process : not null access procedure (Element : Element_Type));
124 procedure Update_Element
125 (Container : in out Vector;
127 Process : not null access procedure (Element : in out Element_Type));
129 procedure Update_Element
130 (Container : in out Vector;
132 Process : not null access procedure (Element : in out Element_Type));
134 procedure Move (Target : in out Vector; Source : in out Vector);
137 (Container : in out Vector;
138 Before : Extended_Index;
142 (Container : in out Vector;
147 (Container : in out Vector;
150 Position : out Cursor);
153 (Container : in out Vector;
154 Before : Extended_Index;
155 New_Item : Element_Type;
156 Count : Count_Type := 1);
159 (Container : in out Vector;
161 New_Item : Element_Type;
162 Count : Count_Type := 1);
165 (Container : in out Vector;
167 New_Item : Element_Type;
168 Position : out Cursor;
169 Count : Count_Type := 1);
172 (Container : in out Vector;
173 Before : Extended_Index;
174 Count : Count_Type := 1);
177 (Container : in out Vector;
179 Position : out Cursor;
180 Count : Count_Type := 1);
183 (Container : in out Vector;
187 (Container : in out Vector;
188 New_Item : Element_Type;
189 Count : Count_Type := 1);
192 (Container : in out Vector;
196 (Container : in out Vector;
197 New_Item : Element_Type;
198 Count : Count_Type := 1);
200 procedure Insert_Space
201 (Container : in out Vector;
202 Before : Extended_Index;
203 Count : Count_Type := 1);
205 procedure Insert_Space
206 (Container : in out Vector;
208 Position : out Cursor;
209 Count : Count_Type := 1);
212 (Container : in out Vector;
213 Index : Extended_Index;
214 Count : Count_Type := 1);
217 (Container : in out Vector;
218 Position : in out Cursor;
219 Count : Count_Type := 1);
221 procedure Delete_First
222 (Container : in out Vector;
223 Count : Count_Type := 1);
225 procedure Delete_Last
226 (Container : in out Vector;
227 Count : Count_Type := 1);
229 procedure Reverse_Elements (Container : in out Vector);
231 procedure Swap (Container : in out Vector; I, J : Index_Type);
233 procedure Swap (Container : in out Vector; I, J : Cursor);
235 function First_Index (Container : Vector) return Index_Type;
237 function First (Container : Vector) return Cursor;
239 function First_Element (Container : Vector) return Element_Type;
241 function Last_Index (Container : Vector) return Extended_Index;
243 function Last (Container : Vector) return Cursor;
245 function Last_Element (Container : Vector) return Element_Type;
247 function Next (Position : Cursor) return Cursor;
249 procedure Next (Position : in out Cursor);
251 function Previous (Position : Cursor) return Cursor;
253 procedure Previous (Position : in out Cursor);
258 Index : Index_Type := Index_Type'First) return Extended_Index;
263 Position : Cursor := No_Element) return Cursor;
265 function Reverse_Find_Index
268 Index : Index_Type := Index_Type'Last) return Extended_Index;
270 function Reverse_Find
273 Position : Cursor := No_Element) return Cursor;
277 Item : Element_Type) return Boolean;
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));
290 with function "<" (Left, Right : Element_Type) return Boolean is <>;
291 package Generic_Sorting is
293 function Is_Sorted (Container : Vector) return Boolean;
295 procedure Sort (Container : in out Vector);
297 procedure Merge (Target : in out Vector; Source : in out Vector);
303 pragma Inline (First_Index);
304 pragma Inline (Last_Index);
305 pragma Inline (Element);
306 pragma Inline (First_Element);
307 pragma Inline (Last_Element);
308 pragma Inline (Query_Element);
309 pragma Inline (Update_Element);
310 pragma Inline (Replace_Element);
311 pragma Inline (Contains);
313 type Elements_Type is array (Index_Type range <>) of Element_Type;
315 function "=" (L, R : Elements_Type) return Boolean is abstract;
317 type Elements_Access is access Elements_Type;
319 use Ada.Finalization;
321 type Vector is new Controlled with record
322 Elements : Elements_Access;
323 Last : Extended_Index := No_Index;
328 procedure Adjust (Container : in out Vector);
330 procedure Finalize (Container : in out Vector);
335 (Stream : access Root_Stream_Type'Class;
338 for Vector'Write use Write;
341 (Stream : access Root_Stream_Type'Class;
342 Container : out Vector);
344 for Vector'Read use Read;
346 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
348 type Vector_Access is access constant Vector;
349 for Vector_Access'Storage_Size use 0;
351 type Cursor is record
352 Container : Vector_Access;
353 Index : Index_Type := Index_Type'First;
357 (Stream : access Root_Stream_Type'Class;
360 for Cursor'Write use Write;
363 (Stream : access Root_Stream_Type'Class;
364 Position : out Cursor);
366 for Cursor'Read use Read;
368 No_Element : constant Cursor := Cursor'(null, Index_Type
'First);
370 end Ada
.Containers
.Vectors
;