PR ada/18819
[official-gcc.git] / gcc / ada / a-convec.ads
blobbceea179995fda90ffc78c7907bcd8dcca2d7bad
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-2006, 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 ------------------------------------------------------------------------------
35 with Ada.Finalization;
36 with Ada.Streams;
38 generic
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;
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;
54 pragma Preelaborable_Initialization (Vector);
56 type Cursor is private;
57 pragma Preelaborable_Initialization (Cursor);
59 Empty_Vector : constant Vector;
61 No_Element : constant Cursor;
63 function "=" (Left, Right : Vector) return Boolean;
65 function To_Vector (Length : Count_Type) return Vector;
67 function To_Vector
68 (New_Item : Element_Type;
69 Length : Count_Type) return Vector;
71 function "&" (Left, Right : Vector) return Vector;
73 function "&" (Left : Vector; Right : Element_Type) return Vector;
75 function "&" (Left : Element_Type; Right : Vector) return Vector;
77 function "&" (Left, Right : Element_Type) return Vector;
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 procedure Set_Length
88 (Container : in out Vector;
89 Length : Count_Type);
91 function Is_Empty (Container : Vector) return Boolean;
93 procedure Clear (Container : in out Vector);
95 function To_Cursor
96 (Container : Vector;
97 Index : Extended_Index) return Cursor;
99 function To_Index (Position : Cursor) return Extended_Index;
101 function Element
102 (Container : Vector;
103 Index : Index_Type) return Element_Type;
105 function Element (Position : Cursor) return Element_Type;
107 procedure Replace_Element
108 (Container : in out Vector;
109 Index : Index_Type;
110 New_Item : Element_Type);
112 procedure Replace_Element
113 (Container : in out Vector;
114 Position : Cursor;
115 New_Item : Element_Type);
117 procedure Query_Element
118 (Container : Vector;
119 Index : Index_Type;
120 Process : not null access procedure (Element : Element_Type));
122 procedure Query_Element
123 (Position : Cursor;
124 Process : not null access procedure (Element : Element_Type));
126 procedure Update_Element
127 (Container : in out Vector;
128 Index : Index_Type;
129 Process : not null access procedure (Element : in out Element_Type));
131 procedure Update_Element
132 (Container : in out Vector;
133 Position : Cursor;
134 Process : not null access procedure (Element : in out Element_Type));
136 procedure Move (Target : in out Vector; Source : in out Vector);
138 procedure Insert
139 (Container : in out Vector;
140 Before : Extended_Index;
141 New_Item : Vector);
143 procedure Insert
144 (Container : in out Vector;
145 Before : Cursor;
146 New_Item : Vector);
148 procedure Insert
149 (Container : in out Vector;
150 Before : Cursor;
151 New_Item : Vector;
152 Position : out Cursor);
154 procedure Insert
155 (Container : in out Vector;
156 Before : Extended_Index;
157 New_Item : Element_Type;
158 Count : Count_Type := 1);
160 procedure Insert
161 (Container : in out Vector;
162 Before : Cursor;
163 New_Item : Element_Type;
164 Count : Count_Type := 1);
166 procedure Insert
167 (Container : in out Vector;
168 Before : Cursor;
169 New_Item : Element_Type;
170 Position : out Cursor;
171 Count : Count_Type := 1);
173 procedure Insert
174 (Container : in out Vector;
175 Before : Extended_Index;
176 Count : Count_Type := 1);
178 procedure Insert
179 (Container : in out Vector;
180 Before : Cursor;
181 Position : out Cursor;
182 Count : Count_Type := 1);
184 procedure Prepend
185 (Container : in out Vector;
186 New_Item : Vector);
188 procedure Prepend
189 (Container : in out Vector;
190 New_Item : Element_Type;
191 Count : Count_Type := 1);
193 procedure Append
194 (Container : in out Vector;
195 New_Item : Vector);
197 procedure Append
198 (Container : in out Vector;
199 New_Item : Element_Type;
200 Count : Count_Type := 1);
202 procedure Insert_Space
203 (Container : in out Vector;
204 Before : Extended_Index;
205 Count : Count_Type := 1);
207 procedure Insert_Space
208 (Container : in out Vector;
209 Before : Cursor;
210 Position : out Cursor;
211 Count : Count_Type := 1);
213 procedure Delete
214 (Container : in out Vector;
215 Index : Extended_Index;
216 Count : Count_Type := 1);
218 procedure Delete
219 (Container : in out Vector;
220 Position : in out Cursor;
221 Count : Count_Type := 1);
223 procedure Delete_First
224 (Container : in out Vector;
225 Count : Count_Type := 1);
227 procedure Delete_Last
228 (Container : in out Vector;
229 Count : Count_Type := 1);
231 procedure Reverse_Elements (Container : in out Vector);
233 procedure Swap (Container : in out Vector; I, J : Index_Type);
235 procedure Swap (Container : in out Vector; I, J : Cursor);
237 function First_Index (Container : Vector) return Index_Type;
239 function First (Container : Vector) return Cursor;
241 function First_Element (Container : Vector) return Element_Type;
243 function Last_Index (Container : Vector) return Extended_Index;
245 function Last (Container : Vector) return Cursor;
247 function Last_Element (Container : Vector) return Element_Type;
249 function Next (Position : Cursor) return Cursor;
251 procedure Next (Position : in out Cursor);
253 function Previous (Position : Cursor) return Cursor;
255 procedure Previous (Position : in out Cursor);
257 function Find_Index
258 (Container : Vector;
259 Item : Element_Type;
260 Index : Index_Type := Index_Type'First) return Extended_Index;
262 function Find
263 (Container : Vector;
264 Item : Element_Type;
265 Position : Cursor := No_Element) return Cursor;
267 function Reverse_Find_Index
268 (Container : Vector;
269 Item : Element_Type;
270 Index : Index_Type := Index_Type'Last) return Extended_Index;
272 function Reverse_Find
273 (Container : Vector;
274 Item : Element_Type;
275 Position : Cursor := No_Element) return Cursor;
277 function Contains
278 (Container : Vector;
279 Item : Element_Type) return Boolean;
281 function Has_Element (Position : Cursor) return Boolean;
283 procedure Iterate
284 (Container : Vector;
285 Process : not null access procedure (Position : Cursor));
287 procedure Reverse_Iterate
288 (Container : Vector;
289 Process : not null access procedure (Position : Cursor));
291 generic
292 with function "<" (Left, Right : Element_Type) return Boolean is <>;
293 package Generic_Sorting is
295 function Is_Sorted (Container : Vector) return Boolean;
297 procedure Sort (Container : in out Vector);
299 procedure Merge (Target : in out Vector; Source : in out Vector);
301 end Generic_Sorting;
303 private
305 pragma Inline (First_Index);
306 pragma Inline (Last_Index);
307 pragma Inline (Element);
308 pragma Inline (First_Element);
309 pragma Inline (Last_Element);
310 pragma Inline (Query_Element);
311 pragma Inline (Update_Element);
312 pragma Inline (Replace_Element);
313 pragma Inline (Contains);
315 type Elements_Type is array (Index_Type range <>) of Element_Type;
317 function "=" (L, R : Elements_Type) return Boolean is abstract;
319 type Elements_Access is access Elements_Type;
321 use Ada.Finalization;
323 type Vector is new Controlled with record
324 Elements : Elements_Access;
325 Last : Extended_Index := No_Index;
326 Busy : Natural := 0;
327 Lock : Natural := 0;
328 end record;
330 procedure Adjust (Container : in out Vector);
332 procedure Finalize (Container : in out Vector);
334 use Ada.Streams;
336 procedure Write
337 (Stream : not null access Root_Stream_Type'Class;
338 Container : Vector);
340 for Vector'Write use Write;
342 procedure Read
343 (Stream : not null access Root_Stream_Type'Class;
344 Container : out Vector);
346 for Vector'Read use Read;
348 Empty_Vector : constant Vector := (Controlled with null, No_Index, 0, 0);
350 type Vector_Access is access constant Vector;
351 for Vector_Access'Storage_Size use 0;
353 type Cursor is record
354 Container : Vector_Access;
355 Index : Index_Type := Index_Type'First;
356 end record;
358 procedure Write
359 (Stream : not null access Root_Stream_Type'Class;
360 Position : Cursor);
362 for Cursor'Write use Write;
364 procedure Read
365 (Stream : not null access Root_Stream_Type'Class;
366 Position : out Cursor);
368 for Cursor'Read use Read;
370 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
372 end Ada.Containers.Vectors;