Daily bump.
[official-gcc.git] / gcc / ada / a-convec.ads
blob9dc5c547162cb11dc7fa358f1dfae1d64a5b32ec
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- A D A . C O N T A I N E R S . V E C T O R S --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004-2007, Free Software Foundation, Inc. --
10 -- --
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. --
14 -- --
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. --
25 -- --
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. --
32 -- --
33 -- This unit was originally developed by Matthew J Heaney. --
34 ------------------------------------------------------------------------------
36 private with Ada.Finalization;
37 private with Ada.Streams;
39 generic
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
46 pragma Preelaborate;
47 pragma Remote_Types;
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;
69 function To_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;
89 procedure Set_Length
90 (Container : in out Vector;
91 Length : Count_Type);
93 function Is_Empty (Container : Vector) return Boolean;
95 procedure Clear (Container : in out Vector);
97 function To_Cursor
98 (Container : Vector;
99 Index : Extended_Index) return Cursor;
101 function To_Index (Position : Cursor) return Extended_Index;
103 function Element
104 (Container : Vector;
105 Index : Index_Type) return Element_Type;
107 function Element (Position : Cursor) return Element_Type;
109 procedure Replace_Element
110 (Container : in out Vector;
111 Index : Index_Type;
112 New_Item : Element_Type);
114 procedure Replace_Element
115 (Container : in out Vector;
116 Position : Cursor;
117 New_Item : Element_Type);
119 procedure Query_Element
120 (Container : Vector;
121 Index : Index_Type;
122 Process : not null access procedure (Element : Element_Type));
124 procedure Query_Element
125 (Position : Cursor;
126 Process : not null access procedure (Element : Element_Type));
128 procedure Update_Element
129 (Container : in out Vector;
130 Index : Index_Type;
131 Process : not null access procedure (Element : in out Element_Type));
133 procedure Update_Element
134 (Container : in out Vector;
135 Position : Cursor;
136 Process : not null access procedure (Element : in out Element_Type));
138 procedure Move (Target : in out Vector; Source : in out Vector);
140 procedure Insert
141 (Container : in out Vector;
142 Before : Extended_Index;
143 New_Item : Vector);
145 procedure Insert
146 (Container : in out Vector;
147 Before : Cursor;
148 New_Item : Vector);
150 procedure Insert
151 (Container : in out Vector;
152 Before : Cursor;
153 New_Item : Vector;
154 Position : out Cursor);
156 procedure Insert
157 (Container : in out Vector;
158 Before : Extended_Index;
159 New_Item : Element_Type;
160 Count : Count_Type := 1);
162 procedure Insert
163 (Container : in out Vector;
164 Before : Cursor;
165 New_Item : Element_Type;
166 Count : Count_Type := 1);
168 procedure Insert
169 (Container : in out Vector;
170 Before : Cursor;
171 New_Item : Element_Type;
172 Position : out Cursor;
173 Count : Count_Type := 1);
175 procedure Insert
176 (Container : in out Vector;
177 Before : Extended_Index;
178 Count : Count_Type := 1);
180 procedure Insert
181 (Container : in out Vector;
182 Before : Cursor;
183 Position : out Cursor;
184 Count : Count_Type := 1);
186 procedure Prepend
187 (Container : in out Vector;
188 New_Item : Vector);
190 procedure Prepend
191 (Container : in out Vector;
192 New_Item : Element_Type;
193 Count : Count_Type := 1);
195 procedure Append
196 (Container : in out Vector;
197 New_Item : Vector);
199 procedure Append
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;
211 Before : Cursor;
212 Position : out Cursor;
213 Count : Count_Type := 1);
215 procedure Delete
216 (Container : in out Vector;
217 Index : Extended_Index;
218 Count : Count_Type := 1);
220 procedure Delete
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);
259 function Find_Index
260 (Container : Vector;
261 Item : Element_Type;
262 Index : Index_Type := Index_Type'First) return Extended_Index;
264 function Find
265 (Container : Vector;
266 Item : Element_Type;
267 Position : Cursor := No_Element) return Cursor;
269 function Reverse_Find_Index
270 (Container : Vector;
271 Item : Element_Type;
272 Index : Index_Type := Index_Type'Last) return Extended_Index;
274 function Reverse_Find
275 (Container : Vector;
276 Item : Element_Type;
277 Position : Cursor := No_Element) return Cursor;
279 function Contains
280 (Container : Vector;
281 Item : Element_Type) return Boolean;
283 function Has_Element (Position : Cursor) return Boolean;
285 procedure Iterate
286 (Container : Vector;
287 Process : not null access procedure (Position : Cursor));
289 procedure Reverse_Iterate
290 (Container : Vector;
291 Process : not null access procedure (Position : Cursor));
293 generic
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);
303 end Generic_Sorting;
305 private
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);
324 end record;
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;
333 Busy : Natural := 0;
334 Lock : Natural := 0;
335 end record;
337 overriding
338 procedure Adjust (Container : in out Vector);
340 overriding
341 procedure Finalize (Container : in out Vector);
343 use Ada.Streams;
345 procedure Write
346 (Stream : not null access Root_Stream_Type'Class;
347 Container : Vector);
349 for Vector'Write use Write;
351 procedure Read
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;
363 end record;
365 procedure Write
366 (Stream : not null access Root_Stream_Type'Class;
367 Position : Cursor);
369 for Cursor'Write use Write;
371 procedure Read
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;