PR middle-end/20263
[official-gcc.git] / gcc / ada / a-convec.ads
blobef877c0f7979bf3d3e662cf23a740adb72c767ca
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT LIBRARY COMPONENTS --
4 -- --
5 -- ADA.CONTAINERS.VECTORS --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2004 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, 59 Temple Place - Suite 330, Boston, --
24 -- MA 02111-1307, 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 (Vectors);
47 subtype Extended_Index is Index_Type'Base
48 range Index_Type'First - 1 ..
49 Index_Type'Last +
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;
66 function To_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);
92 function To_Cursor
93 (Container : Vector;
94 Index : Extended_Index) return Cursor;
96 function To_Index (Position : Cursor) return Extended_Index;
98 function Element
99 (Container : Vector;
100 Index : Index_Type) return Element_Type;
102 function Element (Position : Cursor) return Element_Type;
104 procedure Query_Element
105 (Container : Vector;
106 Index : Index_Type;
107 Process : not null access procedure (Element : Element_Type));
109 procedure Query_Element
110 (Position : Cursor;
111 Process : not null access procedure (Element : Element_Type));
113 procedure Update_Element
114 (Container : Vector;
115 Index : Index_Type;
116 Process : not null access procedure (Element : in out Element_Type));
118 procedure Update_Element
119 (Position : Cursor;
120 Process : not null access procedure (Element : in out Element_Type));
122 procedure Replace_Element
123 (Container : Vector;
124 Index : Index_Type;
125 By : Element_Type);
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);
133 procedure Insert
134 (Container : in out Vector;
135 Before : Extended_Index;
136 New_Item : Vector);
138 procedure Insert
139 (Container : in out Vector;
140 Before : Cursor;
141 New_Item : Vector);
143 procedure Insert
144 (Container : in out Vector;
145 Before : Cursor;
146 New_Item : Vector;
147 Position : out Cursor);
149 procedure Insert
150 (Container : in out Vector;
151 Before : Extended_Index;
152 New_Item : Element_Type;
153 Count : Count_Type := 1);
155 procedure Insert
156 (Container : in out Vector;
157 Before : Cursor;
158 New_Item : Element_Type;
159 Count : Count_Type := 1);
161 procedure Insert
162 (Container : in out Vector;
163 Before : Cursor;
164 New_Item : Element_Type;
165 Position : out Cursor;
166 Count : Count_Type := 1);
168 procedure Prepend
169 (Container : in out Vector;
170 New_Item : Vector);
172 procedure Prepend
173 (Container : in out Vector;
174 New_Item : Element_Type;
175 Count : Count_Type := 1);
177 procedure Append
178 (Container : in out Vector;
179 New_Item : Vector);
181 procedure Append
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;
193 Before : Cursor;
194 Position : out Cursor;
195 Count : Count_Type := 1);
197 procedure Set_Length
198 (Container : in out Vector;
199 Length : Count_Type);
201 procedure Delete
202 (Container : in out Vector;
203 Index : Extended_Index; -- TODO: verify
204 Count : Count_Type := 1);
206 procedure Delete
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);
235 generic
236 with function "<" (Left, Right : Element_Type) return Boolean is <>;
237 procedure Generic_Sort (Container : Vector);
239 function Find_Index
240 (Container : Vector;
241 Item : Element_Type;
242 Index : Index_Type := Index_Type'First) return Extended_Index;
244 function Find
245 (Container : Vector;
246 Item : Element_Type;
247 Position : Cursor := No_Element) return Cursor;
249 function Reverse_Find_Index
250 (Container : Vector;
251 Item : Element_Type;
252 Index : Index_Type := Index_Type'Last) return Extended_Index;
254 function Reverse_Find
255 (Container : Vector;
256 Item : Element_Type;
257 Position : Cursor := No_Element) return Cursor;
259 function Contains
260 (Container : Vector;
261 Item : Element_Type) return Boolean;
263 function Next (Position : Cursor) return Cursor;
265 function Previous (Position : Cursor) return Cursor;
267 procedure Next (Position : in out Cursor);
269 procedure Previous (Position : in out Cursor);
271 function Has_Element (Position : Cursor) return Boolean;
273 procedure Iterate
274 (Container : Vector;
275 Process : not null access procedure (Position : Cursor));
277 procedure Reverse_Iterate
278 (Container : Vector;
279 Process : not null access procedure (Position : Cursor));
281 private
283 pragma Inline (First_Index);
284 pragma Inline (Last_Index);
285 pragma Inline (Element);
286 pragma Inline (First_Element);
287 pragma Inline (Last_Element);
288 pragma Inline (Query_Element);
289 pragma Inline (Update_Element);
290 pragma Inline (Replace_Element);
291 pragma Inline (Contains);
293 type Elements_Type is array (Index_Type range <>) of Element_Type;
295 function "=" (L, R : Elements_Type) return Boolean is abstract;
297 type Elements_Access is access Elements_Type;
299 use Ada.Finalization;
301 type Vector is new Controlled with record
302 Elements : Elements_Access;
303 Last : Extended_Index := No_Index;
304 end record;
306 procedure Adjust (Container : in out Vector);
308 procedure Finalize (Container : in out Vector);
310 use Ada.Streams;
312 procedure Write
313 (Stream : access Root_Stream_Type'Class;
314 Container : Vector);
316 for Vector'Write use Write;
318 procedure Read
319 (Stream : access Root_Stream_Type'Class;
320 Container : out Vector);
322 for Vector'Read use Read;
324 Empty_Vector : constant Vector := (Controlled with null, No_Index);
326 type Vector_Access is access constant Vector;
327 for Vector_Access'Storage_Size use 0;
329 type Cursor is record
330 Container : Vector_Access;
331 Index : Index_Type := Index_Type'First;
332 end record;
334 No_Element : constant Cursor := Cursor'(null, Index_Type'First);
336 end Ada.Containers.Vectors;